From 000a47338c9ac2ee6e317b9adbf4357c57973426 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Wed, 5 Nov 2014 08:26:04 +0100 Subject: [PATCH] Ignore hidden and uncollected mounts when saving and restoring favorites. --- Squire3.lua | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/Squire3.lua b/Squire3.lua index 294f6a0..4c67d74 100644 --- a/Squire3.lua +++ b/Squire3.lua @@ -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