updated onLoad functions

This commit is contained in:
Chr1Z93 2024-03-25 17:36:03 +01:00
parent f41f4f9107
commit 7cb3545cab
16 changed files with 62 additions and 51 deletions

View File

@ -11,6 +11,8 @@ local phaseImages = {
"http://cloud-3.steamusercontent.com/ugc/982233321870237261/C287CAED2423970F33E72D6C7415CBEC6794C533/"
}
local phaseId, broadcastChange
function onSave()
return JSON.encode({
phaseId = phaseId,

View File

@ -55,9 +55,9 @@ function onSave()
end
-- loading data, button creation and initial layouting
function onLoad(saveState)
if saveState ~= nil and saveState ~= "" then
local loadedData = JSON.decode(saveState)
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
tokenPrecedence = loadedData.tokenPrecedence
percentage = loadedData.percentage
includeDrawnTokens = loadedData.includeDrawnTokens

View File

@ -15,7 +15,7 @@ val = 0
function onSave() return JSON.encode({ val, options }) end
function onLoad(savedData)
if savedData ~= "" then
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
val = loadedData[1]
options = loadedData[2]

View File

@ -5,21 +5,20 @@ val = 0
function onSave() return JSON.encode(val) end
function onLoad(savedData)
if savedData ~= nil then
if savedData and savedData ~= "" then
val = JSON.decode(savedData)
end
local name = self.getName()
local position = {}
local position = { 0, 0.06, 0 }
-- set position of label depending on object
if name == "Damage" or name == "Resources" or name == "Resource Counter" then
position = { 0, 0.06, 0.1 }
elseif name == "Horror" then
position = { -0.025, 0.06, -0.025 }
elseif name == "Elder Sign Counter" or name == "Auto-fail Counter" then
position = { 0, 0.1, 0 }
else
position = { 0, 0.06, 0 }
end
self.createButton({
@ -35,6 +34,7 @@ function onLoad(savedData)
color = { 0, 0, 0, 0 }
})
-- add context menu entries
self.addContextMenuItem("Add 5", function() updateVal(val + 5) end)
self.addContextMenuItem("Subtract 5", function() updateVal(val - 5) end)
self.addContextMenuItem("Add 10", function() updateVal(val + 10) end)

View File

@ -127,19 +127,18 @@ function onSave()
end
function onLoad(savedData)
if savedData then
loadedData = JSON.decode(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
optionPanel = loadedData.optionPanel
acknowledgedUpgradeVersions = loadedData.acknowledgedUpgradeVersions
updateOptionPanelState()
chaosTokensLastMatGUID = loadedData.chaosTokensLastMatGUID
-- restore saved state for drawn chaos tokens
for _, guid in ipairs(loadedData.chaosTokensGUID or {}) do
table.insert(chaosTokens, getObjectFromGUID(guid))
end
chaosTokensLastMatGUID = loadedData.chaosTokensLastMatGUID
else
print("Saved state could not be found!")
updateOptionPanelState()
end
for _, guid in ipairs(NOT_INTERACTABLE) do

View File

@ -7,9 +7,10 @@ useClickableCounters = false
function onSave() return JSON.encode(useClickableCounters) end
function onLoad(savedData)
if savedData ~= nil then
if savedData and savedData ~= "" then
useClickableCounters = JSON.decode(savedData)
end
self.createButton({
label = "0",
click_function = "removeAllPlayerClues",
@ -23,6 +24,7 @@ function onLoad(savedData)
font_color = { 1, 1, 1, 100 },
color = { 0, 0, 0, 0 }
})
Wait.time(sumClues, 2, -1)
end

View File

@ -23,9 +23,9 @@ local collisionEnabled = false
local currentScenario, useFrontData, tokenData
local TRASH, DATA_HELPER
function onLoad(saveState)
if saveState ~= nil then
local loadedState = JSON.decode(saveState) or {}
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedState = JSON.decode(savedData) or {}
currentScenario = loadedState.currentScenario or ""
useFrontData = loadedState.useFrontData or true
tokenData = loadedState.tokenData or {}

View File

@ -82,7 +82,7 @@ function onSave()
end
function onLoad(savedData)
if savedData ~= "" then
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
visibility = loadedData.visibility
claims = loadedData.claims

View File

@ -60,12 +60,16 @@ function onSave()
end
function onLoad(savedData)
self.interactable = false -- this needs to be here since the playarea will be reloaded when the image changes
local loadedData = JSON.decode(savedData) or {}
locations = loadedData.trackedLocations or {}
currentScenario = loadedData.currentScenario
connectionColor = loadedData.connectionColor or { 0.4, 0.4, 0.4, 1 }
connectionsEnabled = loadedData.connectionsEnabled or true
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) or {}
locations = loadedData.trackedLocations or {}
currentScenario = loadedData.currentScenario
connectionColor = loadedData.connectionColor or { 0.4, 0.4, 0.4, 1 }
connectionsEnabled = loadedData.connectionsEnabled or true
end
-- this needs to be here since the playarea will be reloaded when the image changes
self.interactable = false
Wait.time(function() collisionEnabled = true end, 0.1)
end

View File

@ -6,6 +6,12 @@ local typeIndex, selectionIndex, plainNameCache
function onSave() return JSON.encode({ typeIndex = typeIndex, selectionIndex = selectionIndex }) end
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) or {}
typeIndex = loadedData.typeIndex or 1
selectionIndex = loadedData.selectionIndex or 1
end
self.createButton({
function_owner = self,
click_function = "onClick_toggleGallery",
@ -16,9 +22,6 @@ function onLoad(savedData)
color = { 1, 1, 1, 0 }
})
local loadedData = JSON.decode(savedData) or {}
typeIndex = loadedData.typeIndex or 1
selectionIndex = loadedData.selectionIndex or 1
Wait.time(updatePlayAreaGallery, 0.5)
math.randomseed(os.time())
end

View File

@ -2,15 +2,13 @@ local spawnedCardGuids = {}
function onSave() return JSON.encode({ cards = spawnedCardGuids }) end
function onLoad(saveState)
if saveState ~= nil then
local saveTable = JSON.decode(saveState) or {}
spawnedCardGuids = saveTable.cards or {}
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) or {}
spawnedCardGuids = loadedData.cards or {}
end
createResetMenuItems()
end
function createResetMenuItems()
-- context menu entries
self.addContextMenuItem("Reset All", resetAll)
self.addContextMenuItem("Reset Locations", resetAllLocations)
self.addContextMenuItem("Reset Player Cards", resetAllAssetAndEvents)

View File

@ -103,13 +103,13 @@ function onSave()
end
function onLoad(savedData)
arkhamDb.initialize()
if (savedData ~= nil) then
if savedData and savedData ~= "" then
local saveState = JSON.decode(savedData) or { }
if (saveState.spawnBagState ~= nil) then
if saveState.spawnBagState ~= nil then
spawnBag.loadFromSave(saveState.spawnBagState)
end
end
arkhamDb.initialize()
buildExcludedWeaknessList()
createButtons()
end

View File

@ -11,7 +11,9 @@ function onSave() return JSON.encode(stats) end
-- load stats and make buttons (left to right)
function onLoad(savedData)
stats = JSON.decode(savedData) or { 1, 1, 1, 1 }
if savedData and savedData ~= "" then
stats = JSON.decode(savedData) or { 1, 1, 1, 1 }
end
for index = 1, 4 do
local fnName = "buttonClick" .. index

View File

@ -95,7 +95,14 @@ function onSave()
})
end
function onLoad(saveState)
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
playerColor = loadedData.playerColor
activeInvestigatorId = loadedData.activeInvestigatorId
isDrawButtonVisible = loadedData.isDrawButtonVisible
end
self.interactable = false
-- get object references to owned objects
@ -135,14 +142,6 @@ function onLoad(saveState)
font_size = 180
})
-- save state loading
local state = JSON.decode(saveState)
if state ~= nil then
playerColor = state.playerColor
activeInvestigatorId = state.activeInvestigatorId
isDrawButtonVisible = state.isDrawButtonVisible
end
showDrawButton(isDrawButtonVisible)
math.randomseed(os.time())
Wait.time(function() collisionEnabled = true end, 0.1)

View File

@ -6,7 +6,9 @@ function onSave()
end
function onLoad(savedData)
lines = JSON.decode(savedData) or {}
if savedData and savedData ~= "" then
lines = JSON.decode(savedData) or {}
end
end
-- create timer when numpad 0 is pressed

View File

@ -1,8 +1,8 @@
local zone = nil
local zone
-- general code
function onSave()
return JSON.encode(zone and zone.getGUID() or nil)
return JSON.encode(zone and zone.getGUID())
end
function onLoad(savedData)