From c35d0cd7c0de567594d334484def27ca8037a5cb Mon Sep 17 00:00:00 2001 From: dscarpac Date: Wed, 31 Jul 2024 14:48:06 -0500 Subject: [PATCH 1/2] added helper --- src/playercards/cards/NkosiMabati3.ttslua | 60 +++++++++++++++++------ 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/playercards/cards/NkosiMabati3.ttslua b/src/playercards/cards/NkosiMabati3.ttslua index 83d2e6b9..91208972 100644 --- a/src/playercards/cards/NkosiMabati3.ttslua +++ b/src/playercards/cards/NkosiMabati3.ttslua @@ -1,4 +1,9 @@ require("playercards/CardsWithHelper") + +-- intentionally global +hasXML = false +isHelperEnabled = false + local chaosBagApi = require("chaosbag/ChaosBagApi") -- XML background color for each token @@ -14,17 +19,22 @@ local tokenColor = { [""] = "#77674DE6" } -function onSave() - return JSON.encode(sigil) +function updateSave() + self.script_state = JSON.encode({ + isHelperEnabled = isHelperEnabled, + sigil = sigil + }) end function onLoad(savedData) - self.addContextMenuItem("Enable Helper", chooseSigil) - sigil = JSON.decode(savedData) - if sigil and sigil ~= nil then + syncDisplayWithOptionPanel() + if savedData and savedData ~= "" then + local loadedData = JSON.decode(savedData) + isHelperEnabled = loadedData.isHelperEnabled + sigil = loadedData.sigil makeXMLButton() self.clearContextMenu() - self.addContextMenuItem("Clear Helper", deleteButtons) + self.addContextMenuItem("Clear Helper", toggleHelper) end end @@ -59,11 +69,35 @@ function makeXMLButton() ) 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 -function chooseSigil(playerColor) - Player[playerColor].clearSelectedObjects() +function chooseSigil(player) + player.clearSelectedObjects() self.clearContextMenu() - self.addContextMenuItem("Clear Helper", deleteButtons) + self.addContextMenuItem("Clear Helper", toggleHelper) -- get list of readable names local readableNames = {} @@ -72,7 +106,7 @@ function chooseSigil(playerColor) end -- prompt player to choose sigil - Player[playerColor].showOptionsDialog("Choose Sigil", readableNames, 1, + player.showOptionsDialog("Choose Sigil", readableNames, 1, function(chosenToken) sigil = Global.call("getChaosTokenName", chosenToken) makeXMLButton() @@ -80,11 +114,7 @@ function chooseSigil(playerColor) ) end --- Delete button and remove sigil -function deleteButtons(playerColor) - Player[playerColor].clearSelectedObjects() - self.clearContextMenu() - self.addContextMenuItem("Enable Helper", chooseSigil) +function shutOff() self.UI.setXml("") sigil = nil end From f957ea25118c5e25baeef53515615210a0165a98 Mon Sep 17 00:00:00 2001 From: dscarpac Date: Wed, 31 Jul 2024 15:36:43 -0500 Subject: [PATCH 2/2] more changes --- src/playercards/cards/NkosiMabati3.ttslua | 51 +++++++++++++---------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/playercards/cards/NkosiMabati3.ttslua b/src/playercards/cards/NkosiMabati3.ttslua index 91208972..e5cf8643 100644 --- a/src/playercards/cards/NkosiMabati3.ttslua +++ b/src/playercards/cards/NkosiMabati3.ttslua @@ -27,15 +27,17 @@ function updateSave() end function onLoad(savedData) - syncDisplayWithOptionPanel() if savedData and savedData ~= "" then local loadedData = JSON.decode(savedData) isHelperEnabled = loadedData.isHelperEnabled sigil = loadedData.sigil - makeXMLButton() + if sigil and sigil ~= nil then + makeXMLButton() + end self.clearContextMenu() self.addContextMenuItem("Clear Helper", toggleHelper) end + syncDisplayWithOptionPanel() end function makeXMLButton() @@ -67,30 +69,35 @@ function makeXMLButton() } } ) + updateSave() 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" + if sigil and sigil ~= nil then + makeXMLButton() + else + 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 end -- Create dialog window to choose sigil and create sigil-drawing button @@ -112,11 +119,13 @@ function chooseSigil(player) makeXMLButton() end ) + updateSave() end function shutOff() self.UI.setXml("") sigil = nil + updateSave() end function resolveSigil()