Skip to content

Commit

Permalink
Update the loading process to be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
Justw8 committed Aug 27, 2024
1 parent 1c0816c commit 07c6640
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions TeleportMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -715,31 +715,59 @@ SlashCmdList["TPMENU"] = function(msg)
end
end

--------------------------------------
-- Loading
--------------------------------------

local function checkItemsLoaded(self)
if self.continuableContainer then
self.continuableContainer:Cancel()
end

self.continuableContainer = ContinuableContainer:Create()
local function LoadItems(itemTable)
for _, itemId in ipairs(itemTable) do
self.continuableContainer:AddContinuable(Item:CreateFromItemID(itemId))
end
end

LoadItems(hearthstoneToys)
LoadItems(wormholes)
LoadItems(bonusHearthstones)

local allLoaded = true
local function OnItemsLoaded()
if allLoaded then
tpm:Setup()
else
StartUpdate(self)
end
end

allLoaded = self.continuableContainer:ContinueOnLoad(OnItemsLoaded)
end

function tpm:Setup()
tpm:updateAvailableHearthstones()
tpm:updateAvailableBonusHeartstones()
tpm:updateAvailableWormholes()

if db.hearthstone and db.hearthstone ~= "rng" and db.hearthstone ~= "none" and not PlayerHasToy(db.hearthstone) then
print(APPEND..L["Hearthone Reset Error"]:format(db.hearthstone))
db.hearthstone = "none"
tpm:updateHearthstone()
end

createAnchors()
hooksecurefunc("ToggleGameMenu", createAnchors)
end

-- Loading
local function OnEvent(self, event, addOnName)
if addOnName == "TeleportMenu" then
db = TeleportMenuDB or {}
db.debug = false
C_Timer.After(5, function()
if db.hearthstone and db.hearthstone ~= "rng" and db.hearthstone ~= "none" and not PlayerHasToy(db.hearthstone) then
print(APPEND..L["Hearthone Reset Error"]:format(db.hearthstone))
db.hearthstone = "none"
tpm:updateHearthstone()
end
end)
checkItemsLoaded(self)
tpm:LoadOptions()
elseif event == "PLAYER_LOGIN" then
C_Timer.After(3, function() -- Delay so things can load?
tpm:Setup()
end)
end
end

Expand Down

0 comments on commit 07c6640

Please sign in to comment.