Merge pull request #724 from argonui/helpers

Bugfixes for CardsWithHelpers
This commit is contained in:
dscarpac 2024-06-26 17:35:25 -05:00 committed by GitHub
commit ed4ac42ee7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 53 deletions

View File

@ -189,15 +189,26 @@ function tryObjectEnterContainer(container, object)
end end
-- TTS event for objects that enter zones -- TTS event for objects that enter zones
-- used to detect the "token discard zones" beneath the hand zones function onObjectEnterZone(zone, object)
function onObjectEnterZone(zone, enteringObj) -- detect the "token discard zones" beneath the hand zones
if zone.getName() ~= "TokenDiscardZone" then return end if zone.getName() == "TokenDiscardZone" and
if tokenChecker.isChaosToken(enteringObj) then return end not tokenChecker.isChaosToken(object) and
object.type == "Tile" and
if enteringObj.type == "Tile" and enteringObj.getMemo() and enteringObj.getLock() == false then object.getMemo() and
local matcolor = playmatApi.getMatColorByPosition(enteringObj.getPosition()) not object.getLock() then
local matcolor = playmatApi.getMatColorByPosition(object.getPosition())
local trash = guidReferenceApi.getObjectByOwnerAndType(matcolor, "Trash") local trash = guidReferenceApi.getObjectByOwnerAndType(matcolor, "Trash")
trash.putObject(enteringObj) trash.putObject(object)
elseif zone.type == "Hand" and object.hasTag("CardWithHelper") then
object.clearContextMenu()
object.call("shutOff")
end
end
-- TTS event for objects that leave zones
function onObjectLeaveZone(zone, object)
if zone.type == "Hand" and object.hasTag("CardWithHelper") then
object.call("updateDisplay")
end end
end end
@ -1335,7 +1346,8 @@ function contentDownloadCallback(request, params)
if pos then if pos then
spawnTable.position = pos spawnTable.position = pos
else else
broadcastToAll("Please make space in the area below the tentacle stand in the upper middle of the table and try again.", "Red") broadcastToAll(
"Please make space in the area below the tentacle stand in the upper middle of the table and try again.", "Red")
return return
end end
end end
@ -1558,7 +1570,6 @@ function applyOptionPanelChange(id, state)
-- update master clue counter -- update master clue counter
local counter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "MasterClueCounter") local counter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "MasterClueCounter")
counter.setVar("useClickableCounters", state) counter.setVar("useClickableCounters", state)
elseif id == "enableCardHelpers" then elseif id == "enableCardHelpers" then
toggleCardHelpers(state) toggleCardHelpers(state)

View File

@ -4,13 +4,9 @@ local guidReferenceApi = require("core/GUIDReferenceApi")
local playmatApi = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
local isHelperEnabled = false local isHelperEnabled = false
local loopId
function updateSave() function updateSave()
self.script_state = JSON.encode({ self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end end
function onLoad(savedData) function onLoad(savedData)
@ -18,7 +14,6 @@ function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end end
checkOptionPanel() checkOptionPanel()
updateDisplay() updateDisplay()
@ -27,15 +22,15 @@ end
-- hide buttons and stop monitoring -- hide buttons and stop monitoring
function shutOff() function shutOff()
self.UI.hide("Helper") self.UI.hide("Helper")
if loopId then Wait.stop(loopId) end Wait.stopAll()
loopId = nil
updateSave() updateSave()
end end
-- show buttons and begin monitoring chaos bag for curse and bless tokens -- show buttons and begin monitoring chaos bag for curse and bless tokens
function initialize() function initialize()
self.UI.show("Helper") self.UI.show("Helper")
loopId = Wait.time(maybeUpdateButtonState, 1, -1) maybeUpdateButtonState()
Wait.time(maybeUpdateButtonState, 1, -1)
updateSave() updateSave()
end end
@ -72,10 +67,8 @@ function getBlessCurseInBag()
local chaosBag = chaosBagApi.findChaosBag() local chaosBag = chaosBagApi.findChaosBag()
for _, v in ipairs(chaosBag.getObjects()) do for _, v in ipairs(chaosBag.getObjects()) do
if v.name == "Bless" then if v.name == "Bless" or v.name == "Curse" then
numInBag.Bless = numInBag.Bless + 1 numInBag[v.name] = numInBag[v.name] + 1
elseif v.name == "Curse" then
numInBag.Curse = numInBag.Curse + 1
end end
end end
@ -83,22 +76,14 @@ function getBlessCurseInBag()
end end
function setUiState(params) function setUiState(params)
-- set bless state for _, tokenName in ipairs({ "Bless", "Curse" }) do
if params.Bless then if params[tokenName] then
self.UI.show("Bless") self.UI.show(tokenName)
self.UI.hide("inactiveBless") self.UI.hide("inactive" .. tokenName)
else else
self.UI.show("inactiveBless") self.UI.show("inactive" .. tokenName)
self.UI.hide("Bless") self.UI.hide(tokenName)
end end
-- set curse state
if params.Curse then
self.UI.show("Curse")
self.UI.hide("inactiveCurse")
else
self.UI.show("inactiveCurse")
self.UI.hide("Curse")
end end
end end

View File

@ -59,9 +59,6 @@ end
function shutOff() function shutOff()
self.clearButtons() self.clearButtons()
-- reset the z position
buttonParameters.position.z = initialButtonPosition
end end
-- marks a button as active -- marks a button as active
@ -80,6 +77,8 @@ end
-- Create buttons based on the button parameters -- Create buttons based on the button parameters
function createButtons() function createButtons()
self.clearButtons()
-- reset the list in case of addition of checkboxes or Refine -- reset the list in case of addition of checkboxes or Refine
hypothesisList = { 'Succeed by 3 or more', 'Fail by 2 or more' } hypothesisList = { 'Succeed by 3 or more', 'Fail by 2 or more' }
@ -96,6 +95,10 @@ function createButtons()
end end
end end
-- reset the z position
buttonParameters.position.z = initialButtonPosition
-- actual button creation
for i, label in ipairs(hypothesisList) do for i, label in ipairs(hypothesisList) do
buttonParameters.label = label buttonParameters.label = label
buttonParameters.click_function = "selectButton" .. i buttonParameters.click_function = "selectButton" .. i

View File

@ -10,13 +10,10 @@ local buttonParameters = {
height = 175 height = 175
} }
local modValue, loopId local modValue
function updateSave() function updateSave()
self.script_state = JSON.encode({ self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end end
function onLoad(savedData) function onLoad(savedData)
@ -31,24 +28,21 @@ function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end end
checkOptionPanel() checkOptionPanel()
updateDisplay() updateDisplay()
end end
function initialize() function initialize()
self.clearButtons()
self.createButton(buttonParameters) self.createButton(buttonParameters)
updateButton() updateButton()
loopId = Wait.time(updateButton, 2, -1) Wait.time(updateButton, 2, -1)
end end
function shutOff() function shutOff()
if loopId then
Wait.stop(loopId)
loopId = nil
end
self.clearButtons() self.clearButtons()
Wait.stopAll()
end end
function updateButton() function updateButton()