resolving review comments

This commit is contained in:
Chr1Z93 2022-12-12 12:18:45 +01:00
parent 2f83df87d8
commit 24e8f3d8a6
4 changed files with 51 additions and 37 deletions

View File

@ -22,7 +22,7 @@
}, },
"Lighting_path": "Lighting.json", "Lighting_path": "Lighting.json",
"LuaScript": "require(\"core/Global\")", "LuaScript": "require(\"core/Global\")",
"LuaScriptState": "[]", "LuaScriptState": "{\"optionPanel\":[false,false,false,false,false,false,false,false]}",
"MusicPlayer_path": "MusicPlayer.json", "MusicPlayer_path": "MusicPlayer.json",
"Note": "", "Note": "",
"ObjectStates_order": [ "ObjectStates_order": [

View File

@ -28,8 +28,8 @@ local NOT_INTERACTABLE = {
local chaosTokens = {} local chaosTokens = {}
local chaosTokensLastMat = nil local chaosTokensLastMat = nil
local IS_RESHUFFLING = false local IS_RESHUFFLING = false
local bagSearchers = {}
local bagSearchers = { } local playmatAPI = require("playermat/PlaymatApi")
--------------------------------------------------------- ---------------------------------------------------------
-- data for tokens -- data for tokens
@ -131,18 +131,15 @@ local overallStats = {
--------------------------------------------------------- ---------------------------------------------------------
-- saving state of optionPanel to restore later -- 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) function onLoad(savedData)
if savedData then if savedData then
optionPanel = JSON.decode(savedData) loadedData = JSON.decode(savedData)
for id, enabled in pairs(optionPanel) do optionPanel = loadedData.optionPanel
if enabled then self.UI.setAttribute("toggle" .. id, "isOn", true) end updateOptionPanelState()
end
else else
for i = 1, 8 do print("Saved state could not be found!")
optionPanel[i] = false
end
end end
for _, guid in ipairs(NOT_INTERACTABLE) do for _, guid in ipairs(NOT_INTERACTABLE) do
@ -652,27 +649,31 @@ function onClick_toggleOption(_, id)
end end
self.UI.setAttribute("toggle" .. id, "isOn", state) self.UI.setAttribute("toggle" .. id, "isOn", state)
optionPanel[id] = state
applyChange(id, state) id = tonumber(id)
optionPanel[id] = state
applyOptionPanelChange(id, state)
end end
local PlayerMatAPI = require("playermat/PlaymatApi") -- sets the option panel to the correct state (corresponding to 'optionPanel')
function applyChange(id, state) 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 -- option 1: Snap tags
if id == "1" then if id == 1 then
printToAll("Playermat snap tags " .. (state and "en" or "dis") .."abled.", "White") playmatAPI.setLimitSnapsByType(state, "All")
PlayerMatAPI.setLimitSnapsByType(state, "All")
-- option 2: Draw 1 button -- option 2: Draw 1 button
elseif id=="2" then elseif id == 2 then
printToAll("'Draw 1' button " .. (state and "en" or "dis") .."abled.", "White") playmatAPI.showDrawButton(state, "All")
PlayerMatAPI.showDrawButton(state, "All")
-- option 3: Clickable clue counters -- option 3: Clickable clue counters
elseif id=="3" then elseif id == 3 then
printToAll("Clickable clue counters " .. (state and "en" or "dis") .."abled.", "White") playmatAPI.clickableClues(state, "All")
PlayerMatAPI.clickableClues(state, "All")
end end
end end

View File

@ -47,7 +47,14 @@ local RESOURCE_COUNTER
activeInvestigatorId = "00000" activeInvestigatorId = "00000"
local drawButton = false 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) function onLoad(save_state)
self.interactable = DEBUG self.interactable = DEBUG
@ -653,9 +660,11 @@ function spawnToken(position, tokenType)
end end
-- Sets this playermat's draw 1 button to visible -- Sets this playermat's draw 1 button to visible
---@param visibleButton Boolean. Whether the draw 1 button should be visible ---@param visible Boolean. Whether the draw 1 button should be visible
function showDrawButton(visibleButton) function showDrawButton(visible)
drawButton = visibleButton drawButton = visible
-- create the "Draw 1" button
if drawButton then if drawButton then
self.createButton({ self.createButton({
label = "Draw 1", label = "Draw 1",
@ -667,17 +676,21 @@ function showDrawButton(visibleButton)
height = 280, height = 280,
font_size = 180 font_size = 180
}) })
-- remove the "Draw 1" button
else else
-- remove button with index 9 if 10 buttons are present (because index starts at 0) local buttons = self.getButtons()
if #self.getButtons() == 10 then for i = 1, #buttons do
self.removeButton(9) if buttons[i].label == "Draw 1" then
self.removeButton(buttons[i].index)
end
end end
end end
end end
-- Spawns / destroys a clickable clue counter for this playmat -- Shows or hides the clickable clue counter for this playmat
---@param clickableCounter Boolean. Whether the clickable clue counter should be present ---@param showCounters Boolean. Whether the clickable clue counter should be present
function clickableClues(clickableCounter) function clickableClues(showCounters)
print("dummy function for clue counters") print("dummy function for clue counters")
end end

View File

@ -33,13 +33,13 @@ do
end end
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 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 ---@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. -- 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 for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("clickableClues", clickableCounter) mat.call("clickableClues", showCounter)
end end
end end