Skip to content

Commit

Permalink
Ignore hidden and uncollected mounts when saving and restoring favori…
Browse files Browse the repository at this point in the history
…tes.
  • Loading branch information
Adirelle committed Nov 5, 2014
1 parent c32ecf7 commit 000a473
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions Squire3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,28 +177,37 @@ function addon:GetFavoriteDB()
return self.db[self.db.profile.favoriteSection].favorites
end

function addon:SaveFavorites()
local favorites = self:GetFavoriteDB()
for index = 1, C_MountJournal.GetNumMounts() do
local function favoriteIterator(num, index)
while index < num do
index = index + 1
local isFavorite, canFavorite = C_MountJournal.GetIsFavorite(index)
if canFavorite then
local _, spellId = C_MountJournal.GetMountInfo(index)
favorites[spellId] = isFavorite
local _, spellId, _, _, _, _, _, _, _, hideOnChar, isCollected = C_MountJournal.GetMountInfo(index) C_MountJournal.GetMountInfo(index)
if isCollected and not hideOnChar then
return index, spellId, isFavorite
end
end
end
end

local function iterateFavorites()
return favoriteIterator, C_MountJournal.GetNumMounts(), 0
end

function addon:SaveFavorites()
local favorites = self:GetFavoriteDB()
for index, spellId, isFavorite in iterateFavorites() do
favorites[spellId] = isFavorite
end
end

function addon:RestoreFavorites()
local favorites = self:GetFavoriteDB()
for index = 1, C_MountJournal.GetNumMounts() do
local isFavorite, canFavorite = C_MountJournal.GetIsFavorite(index)
if canFavorite then
local _, spellId = C_MountJournal.GetMountInfo(index)
local saved = favorites[spellId] or false
if saved ~= isFavorite then
C_MountJournal.SetIsFavorite(index, saved)
self:Debug("Restored favorite status of", GetSpellInfo(spellId), "to", saved and "favorite" or "not favorite")
end
for index, spellId, isFavorite in iterateFavorites() do
local saved = favorites[spellId] or false
if saved ~= isFavorite then
self:Debug("Restoring favorite status of", index, spellId, GetSpellInfo(spellId), ":", saved, "actual:", isFavorite)
C_MountJournal.SetIsFavorite(index, saved)
end
end
end
Expand Down

0 comments on commit 000a473

Please sign in to comment.