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",
"LuaScript": "require(\"core/Global\")",
"LuaScriptState": "[]",
"LuaScriptState": "{\"optionPanel\":[false,false,false,false,false,false,false,false]}",
"MusicPlayer_path": "MusicPlayer.json",
"Note": "",
"ObjectStates_order": [

View File

@ -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

View File

@ -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

View File

@ -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