diff --git a/config.json b/config.json index 46ab6ea5..c2e3a329 100644 --- a/config.json +++ b/config.json @@ -22,7 +22,7 @@ }, "Lighting_path": "Lighting.json", "LuaScript": "require(\"core/Global\")", - "LuaScriptState": "[]", + "LuaScriptState": "{\"optionPanel\":[false,false,false,false,false,false,false,false]}", "MusicPlayer_path": "MusicPlayer.json", "Note": "", "ObjectStates_order": [ diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 283a4660..21363e7d 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -28,8 +28,8 @@ local NOT_INTERACTABLE = { local chaosTokens = {} local chaosTokensLastMat = nil local IS_RESHUFFLING = false - -local bagSearchers = { } +local bagSearchers = {} +local playmatAPI = require("playermat/PlaymatApi") --------------------------------------------------------- -- data for tokens @@ -131,18 +131,15 @@ local overallStats = { --------------------------------------------------------- -- saving state of optionPanel to restore later -function onSave() return JSON.encode(optionPanel) end +function onSave() return JSON.encode({ optionPanel = optionPanel }) end function onLoad(savedData) if savedData then - optionPanel = JSON.decode(savedData) - for id, enabled in pairs(optionPanel) do - if enabled then self.UI.setAttribute("toggle" .. id, "isOn", true) end - end + loadedData = JSON.decode(savedData) + optionPanel = loadedData.optionPanel + updateOptionPanelState() else - for i = 1, 8 do - optionPanel[i] = false - end + print("Saved state could not be found!") end for _, guid in ipairs(NOT_INTERACTABLE) do @@ -652,27 +649,31 @@ function onClick_toggleOption(_, id) end self.UI.setAttribute("toggle" .. id, "isOn", state) - optionPanel[id] = state - applyChange(id, state) + id = tonumber(id) + optionPanel[id] = state + applyOptionPanelChange(id, state) end -local PlayerMatAPI = require("playermat/PlaymatApi") -function applyChange(id, state) +-- sets the option panel to the correct state (corresponding to 'optionPanel') +function updateOptionPanelState() + for id, enabled in pairs(optionPanel) do + if enabled then self.UI.setAttribute("toggle" .. id, "isOn", true) end + end +end + +function applyOptionPanelChange(id, state) -- option 1: Snap tags - if id == "1" then - printToAll("Playermat snap tags " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.setLimitSnapsByType(state, "All") + if id == 1 then + playmatAPI.setLimitSnapsByType(state, "All") -- option 2: Draw 1 button - elseif id=="2" then - printToAll("'Draw 1' button " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.showDrawButton(state, "All") + elseif id == 2 then + playmatAPI.showDrawButton(state, "All") -- option 3: Clickable clue counters - elseif id=="3" then - printToAll("Clickable clue counters " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.clickableClues(state, "All") + elseif id == 3 then + playmatAPI.clickableClues(state, "All") end end diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 67e3a073..7294d6b5 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -47,7 +47,14 @@ local RESOURCE_COUNTER activeInvestigatorId = "00000" local drawButton = false -function onSave() return JSON.encode({zoneID = zoneID, playerColor = PLAYER_COLOR, activeInvestigatorId = activeInvestigatorId, drawButton = drawButton}) end +function onSave() + return JSON.encode({ + zoneID = zoneID, + playerColor = PLAYER_COLOR, + activeInvestigatorId = activeInvestigatorId, + drawButton = drawButton + }) +end function onLoad(save_state) self.interactable = DEBUG @@ -653,9 +660,11 @@ function spawnToken(position, tokenType) end -- Sets this playermat's draw 1 button to visible ----@param visibleButton Boolean. Whether the draw 1 button should be visible -function showDrawButton(visibleButton) - drawButton = visibleButton +---@param visible Boolean. Whether the draw 1 button should be visible +function showDrawButton(visible) + drawButton = visible + + -- create the "Draw 1" button if drawButton then self.createButton({ label = "Draw 1", @@ -667,17 +676,21 @@ function showDrawButton(visibleButton) height = 280, font_size = 180 }) + + -- remove the "Draw 1" button else - -- remove button with index 9 if 10 buttons are present (because index starts at 0) - if #self.getButtons() == 10 then - self.removeButton(9) + local buttons = self.getButtons() + for i = 1, #buttons do + if buttons[i].label == "Draw 1" then + self.removeButton(buttons[i].index) + end end end end --- Spawns / destroys a clickable clue counter for this playmat ----@param clickableCounter Boolean. Whether the clickable clue counter should be present -function clickableClues(clickableCounter) +-- Shows or hides the clickable clue counter for this playmat +---@param showCounters Boolean. Whether the clickable clue counter should be present +function clickableClues(showCounters) print("dummy function for clue counters") end diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 6a4064e6..a8b0e952 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -33,13 +33,13 @@ do end end - -- Spawns a clickable clue counter for the requested playermat + -- Shows or hides the clickable clue counter for the requested playermat ---@param visibleButton Boolean. Whether the clickable counter should be present or not ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also -- accepts "All" as a special value which will apply the setting to all four mats. - PlaymatApi.clickableClues = function(clickableCounter, matColor) + PlaymatApi.clickableClues = function(showCounter, matColor) for _, mat in ipairs(internal.getMatForColor(matColor)) do - mat.call("clickableClues", clickableCounter) + mat.call("clickableClues", showCounter) end end