Skip to content

Commit

Permalink
Makes loading characters more robust - still with an error message th…
Browse files Browse the repository at this point in the history
…ough :-(
  • Loading branch information
Sebaestschjin committed Mar 7, 2021
1 parent 78d2f62 commit b01ecca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gloomhaven-campaign-manager/CampaignManager.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local Unlocked = require('gloomhaven-campaign-manager.Unlocked')
local CampaignManager = {}

---@type number[]
CampaignManager.VERSION = { 2, 0, 1 }
CampaignManager.VERSION = { 2, 0, 2 }

function CampaignManager.loadAll()
local content = Savefile.load()
Expand Down
19 changes: 17 additions & 2 deletions gloomhaven-campaign-manager/Character.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ function Character.load(index, character)
Component.loadPlayer(index, function() Character.unpackCharacterBox(index, character) end)
end

---@param obj tts__Object
---@return boolean
local function isReady(obj)
if not obj.getObjects then
return false
end

local status, content = pcall(function() return obj.getObjects() end)
if not status then
return false
end

return content ~= nil
end

---@param player number
---@param character gh_Save_Character
function Character.unpackCharacterBox(player, character)
Expand All @@ -41,9 +56,9 @@ function Character.unpackCharacterBox(player, character)
-- TODO I'd like to get rid of the wait here, but don't know how. Somehow the taken object is not ready yet and
-- will fail in the called function
callback_function = function(obj)
Wait.time(
Wait.condition(
function() Character.unpackCharacterAbilities(player, character, --[[---@type tts__Bag]] obj) end
, 4)
, function() return isReady(obj) end)
end
})
end
Expand Down
2 changes: 1 addition & 1 deletion sebaestschjin-tts

0 comments on commit b01ecca

Please sign in to comment.