Merge pull request #754 from argonui/cards-with-helper

Update for cards with helper
This commit is contained in:
dscarpac 2024-07-07 16:13:43 -05:00 committed by GitHub
commit 6801208a85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 100 additions and 83 deletions

View File

@ -51,20 +51,21 @@ As a nice reminder the XML button takes on the Frost color and icon with the tex
> require...
----------------------------------------------------------]]
local isHelperEnabled = false
-- intentionally global
hasXML = true
isHelperEnabled = false
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
createHelperXML()
checkOptionPanel()
syncDisplayWithOptionPanel()
end
function createHelperXML()
@ -95,14 +96,6 @@ function createHelperXML()
self.UI.setXmlTable(xmlTable)
end
function shutOff()
self.UI.hide("Helper")
end
function initialize()
self.UI.show("Helper")
end
function triggerXMLTokenLabelCreation()
Global.call("activeRedrawEffect", {
VALID_TOKENS = VALID_TOKENS,

View File

@ -1,7 +1,23 @@
--[[ Library for cards that have helpers
This file is used to share code between cards with helpers.
It syncs the visibility of the helper with the option panel and
makes sure the card has the respective tag.
Additionally, it will call 'initiliaze()' and 'shutOff()'
in the parent file if they are present.
Instructions:
1) Define the global variables before requiring this file:
hasXML = true (whether the card has an XML display)
isHelperEnabled = false (default state of the helper, should be 'false')
2) In 'onLoad()'', call 'syncDisplayWithOptionPanel()'
----------------------------------------------------------]]
local optionPanelApi = require("core/OptionPanelApi")
-- if the respective option is enabled in onLoad(), enable the helper
function checkOptionPanel()
function syncDisplayWithOptionPanel()
self.addTag("CardWithHelper")
local options = optionPanelApi.getOptions()
if options.enableCardHelpers then
setHelperState(true)
@ -33,10 +49,12 @@ function actualDisplayUpdate()
if isHelperEnabled then
self.clearContextMenu()
self.addContextMenuItem("Disable Helper", toggleHelper)
if hasXML then self.UI.show("Helper") end
if initialize then initialize() end
else
self.clearContextMenu()
self.addContextMenuItem("Enable Helper", toggleHelper)
if hasXML then self.UI.hide("Helper") end
if shutOff then shutOff() end
end
end

View File

@ -4,35 +4,37 @@ local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local isHelperEnabled = false
local updated
-- intentionally global
hasXML = true
isHelperEnabled = false
local updated, loopId
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
checkOptionPanel()
syncDisplayWithOptionPanel()
end
-- hide buttons and stop monitoring
function shutOff()
self.UI.hide("Helper")
Wait.stopAll()
updateSave()
if loopId then
Wait.stop(loopId)
loopId = nil
end
end
-- show buttons and begin monitoring chaos bag for curse and bless tokens
function initialize()
self.UI.show("Helper")
maybeUpdateButtonState()
Wait.time(maybeUpdateButtonState, 1, -1)
updateSave()
loopId = Wait.time(maybeUpdateButtonState, 1, -1)
end
function resolveToken(player, _, tokenType)

View File

@ -1,6 +1,10 @@
require("playercards/CardsWithHelper")
local playermatApi = require("playermat/PlayermatApi")
-- intentionally global
hasXML = false
isHelperEnabled = false
-- common button parameters
local buttonParameters = {}
buttonParameters.function_owner = self
@ -28,7 +32,6 @@ local customizableList = {
-- index of the currently selected button (0-indexed from the top)
local activeButtonIndex = -1
local isHelperEnabled = false
local hypothesisList = {}
function updateSave()
@ -39,17 +42,17 @@ function updateSave()
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
activeButtonIndex = loadedData.activeButtonIndex
end
checkOptionPanel()
if activeButtonIndex > 0 then
selectButton(activeButtonIndex)
end
syncDisplayWithOptionPanel()
end
function initialize()
@ -74,7 +77,7 @@ function selectButton(index)
end
end
-- Create buttons based on the button parameters
-- create buttons based on the button parameters
function createButtons()
self.clearButtons()

View File

@ -3,7 +3,9 @@ local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager")
local isHelperEnabled = false
-- intentionally global
hasXML = true
isHelperEnabled = false
local clickableResourceCounter = nil
local foundTokens = 0
@ -11,13 +13,12 @@ function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
end
function onLoad()
self.addTag("CardWithHelper")
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
checkOptionPanel()
syncDisplayWithOptionPanel()
end
function searchSelf()
@ -66,15 +67,3 @@ function loseAll(player)
end
printToColor("Discarded " .. foundTokens .. " resource(s).", player.color)
end
-- hide buttons
function shutOff()
self.UI.hide("Helper")
updateSave()
end
-- show buttons
function initialize()
self.UI.show("Helper")
updateSave()
end

View File

@ -5,8 +5,10 @@ local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager")
local isHelperEnabled = false
local updated
-- intentionally global
hasXML = true
isHelperEnabled = false
local updated, loopId
local xmlData = {
Action = { color = "#6D202CE6", onClick = "removeAndExtraAction" },
@ -16,31 +18,31 @@ local xmlData = {
}
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
checkOptionPanel()
syncDisplayWithOptionPanel()
end
-- hide buttons and stop monitoring
function shutOff()
self.UI.hide("Helper")
Wait.stopAll()
updateSave()
end
-- show buttons and begin monitoring chaos bag for curse and bless tokens
function initialize()
self.UI.show("Helper")
maybeUpdateButtonState()
Wait.time(maybeUpdateButtonState, 1, -1)
updateSave()
loopId = Wait.time(maybeUpdateButtonState, 1, -1)
end
function shutOff()
if loopId then
Wait.stop(loopId)
loopId = nil
end
end
function addTokenToBag(_, _, tokenType)

View File

@ -1,6 +1,12 @@
require("playercards/CardsWithHelper")
local playermatApi = require("playermat/PlayermatApi")
-- intentionally global
hasXML = false
isHelperEnabled = false
local modValue, loopId
local buttonParameters = {
click_function = "shutOff",
function_owner = self,
@ -10,13 +16,20 @@ local buttonParameters = {
height = 175
}
local modValue
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
-- use metadata to detect level and adjust modValue accordingly
if JSON.decode(self.getGMNotes()).level == 0 then
modValue = 5
@ -24,25 +37,22 @@ function onLoad(savedData)
modValue = 4
end
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
checkOptionPanel()
updateDisplay()
syncDisplayWithOptionPanel()
end
function initialize()
self.clearButtons()
self.createButton(buttonParameters)
updateButton()
Wait.time(updateButton, 2, -1)
loopId = Wait.time(updateButton, 2, -1)
end
function shutOff()
self.clearButtons()
Wait.stopAll()
if loopId then
Wait.stop(loopId)
loopId = nil
end
end
function updateButton()