added helper

This commit is contained in:
dscarpac 2024-07-31 14:48:06 -05:00
parent cd694e04ea
commit c35d0cd7c0

View File

@ -1,4 +1,9 @@
require("playercards/CardsWithHelper") require("playercards/CardsWithHelper")
-- intentionally global
hasXML = false
isHelperEnabled = false
local chaosBagApi = require("chaosbag/ChaosBagApi") local chaosBagApi = require("chaosbag/ChaosBagApi")
-- XML background color for each token -- XML background color for each token
@ -14,17 +19,22 @@ local tokenColor = {
[""] = "#77674DE6" [""] = "#77674DE6"
} }
function onSave() function updateSave()
return JSON.encode(sigil) self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
sigil = sigil
})
end end
function onLoad(savedData) function onLoad(savedData)
self.addContextMenuItem("Enable Helper", chooseSigil) syncDisplayWithOptionPanel()
sigil = JSON.decode(savedData) if savedData and savedData ~= "" then
if sigil and sigil ~= nil then local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
sigil = loadedData.sigil
makeXMLButton() makeXMLButton()
self.clearContextMenu() self.clearContextMenu()
self.addContextMenuItem("Clear Helper", deleteButtons) self.addContextMenuItem("Clear Helper", toggleHelper)
end end
end end
@ -59,11 +69,35 @@ function makeXMLButton()
) )
end end
-- Create XML button to prompt choosing a sigil; acts as this card's helper
function initialize()
self.UI.setXmlTable({
{
tag = "Button",
attributes = {
height = 450,
width = 1400,
rotation = "0 0 180",
scale = "0.1 0.1 1",
position = "0 -55 -22",
padding = "50 50 50 50",
font = "font_teutonic-arkham",
fontSize = 300,
onClick = "chooseSigil",
color = "#77674DE6",
textColor = "White"
},
value = "Choose Sigil"
}
}
)
end
-- Create dialog window to choose sigil and create sigil-drawing button -- Create dialog window to choose sigil and create sigil-drawing button
function chooseSigil(playerColor) function chooseSigil(player)
Player[playerColor].clearSelectedObjects() player.clearSelectedObjects()
self.clearContextMenu() self.clearContextMenu()
self.addContextMenuItem("Clear Helper", deleteButtons) self.addContextMenuItem("Clear Helper", toggleHelper)
-- get list of readable names -- get list of readable names
local readableNames = {} local readableNames = {}
@ -72,7 +106,7 @@ function chooseSigil(playerColor)
end end
-- prompt player to choose sigil -- prompt player to choose sigil
Player[playerColor].showOptionsDialog("Choose Sigil", readableNames, 1, player.showOptionsDialog("Choose Sigil", readableNames, 1,
function(chosenToken) function(chosenToken)
sigil = Global.call("getChaosTokenName", chosenToken) sigil = Global.call("getChaosTokenName", chosenToken)
makeXMLButton() makeXMLButton()
@ -80,11 +114,7 @@ function chooseSigil(playerColor)
) )
end end
-- Delete button and remove sigil function shutOff()
function deleteButtons(playerColor)
Player[playerColor].clearSelectedObjects()
self.clearContextMenu()
self.addContextMenuItem("Enable Helper", chooseSigil)
self.UI.setXml("") self.UI.setXml("")
sigil = nil sigil = nil
end end