update for cards with helper
This commit is contained in:
parent
6a9d0cae76
commit
8e9829931b
@ -51,20 +51,21 @@ As a nice reminder the XML button takes on the Frost color and icon with the tex
|
|||||||
> require...
|
> require...
|
||||||
----------------------------------------------------------]]
|
----------------------------------------------------------]]
|
||||||
|
|
||||||
local isHelperEnabled = false
|
-- intentionally global
|
||||||
|
hasXML = true
|
||||||
|
isHelperEnabled = false
|
||||||
|
|
||||||
function updateSave()
|
function updateSave()
|
||||||
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
||||||
end
|
end
|
||||||
|
|
||||||
function onLoad(savedData)
|
function onLoad(savedData)
|
||||||
self.addTag("CardWithHelper")
|
|
||||||
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
|
||||||
end
|
end
|
||||||
createHelperXML()
|
createHelperXML()
|
||||||
checkOptionPanel()
|
syncDisplayWithOptionPanel()
|
||||||
end
|
end
|
||||||
|
|
||||||
function createHelperXML()
|
function createHelperXML()
|
||||||
@ -95,14 +96,6 @@ function createHelperXML()
|
|||||||
self.UI.setXmlTable(xmlTable)
|
self.UI.setXmlTable(xmlTable)
|
||||||
end
|
end
|
||||||
|
|
||||||
function shutOff()
|
|
||||||
self.UI.hide("Helper")
|
|
||||||
end
|
|
||||||
|
|
||||||
function initialize()
|
|
||||||
self.UI.show("Helper")
|
|
||||||
end
|
|
||||||
|
|
||||||
function triggerXMLTokenLabelCreation()
|
function triggerXMLTokenLabelCreation()
|
||||||
Global.call("activeRedrawEffect", {
|
Global.call("activeRedrawEffect", {
|
||||||
VALID_TOKENS = VALID_TOKENS,
|
VALID_TOKENS = VALID_TOKENS,
|
||||||
|
@ -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")
|
local optionPanelApi = require("core/OptionPanelApi")
|
||||||
|
|
||||||
-- if the respective option is enabled in onLoad(), enable the helper
|
-- if the respective option is enabled in onLoad(), enable the helper
|
||||||
function checkOptionPanel()
|
function syncDisplayWithOptionPanel()
|
||||||
|
self.addTag("CardWithHelper")
|
||||||
local options = optionPanelApi.getOptions()
|
local options = optionPanelApi.getOptions()
|
||||||
if options.enableCardHelpers then
|
if options.enableCardHelpers then
|
||||||
setHelperState(true)
|
setHelperState(true)
|
||||||
@ -33,10 +49,12 @@ function actualDisplayUpdate()
|
|||||||
if isHelperEnabled then
|
if isHelperEnabled then
|
||||||
self.clearContextMenu()
|
self.clearContextMenu()
|
||||||
self.addContextMenuItem("Disable Helper", toggleHelper)
|
self.addContextMenuItem("Disable Helper", toggleHelper)
|
||||||
|
if hasXML then self.UI.show("Helper") end
|
||||||
if initialize then initialize() end
|
if initialize then initialize() end
|
||||||
else
|
else
|
||||||
self.clearContextMenu()
|
self.clearContextMenu()
|
||||||
self.addContextMenuItem("Enable Helper", toggleHelper)
|
self.addContextMenuItem("Enable Helper", toggleHelper)
|
||||||
|
if hasXML then self.UI.hide("Helper") end
|
||||||
if shutOff then shutOff() end
|
if shutOff then shutOff() end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,38 +1,40 @@
|
|||||||
require("playercards/CardsWithHelper")
|
require("playercards/CardsWithHelper")
|
||||||
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
||||||
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||||
local playermatApi = require("playermat/PlayermatApi")
|
local playermatApi = require("playermat/PlayermatApi")
|
||||||
|
|
||||||
local isHelperEnabled = false
|
-- intentionally global
|
||||||
local updated
|
hasXML = true
|
||||||
|
isHelperEnabled = false
|
||||||
|
local updated, loopId
|
||||||
|
|
||||||
function updateSave()
|
function updateSave()
|
||||||
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
self.script_state = JSON.encode({
|
||||||
|
isHelperEnabled = isHelperEnabled,
|
||||||
|
loopId = loopId
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function onLoad(savedData)
|
function onLoad(savedData)
|
||||||
self.addTag("CardWithHelper")
|
|
||||||
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()
|
syncDisplayWithOptionPanel()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hide buttons and stop monitoring
|
|
||||||
function shutOff()
|
function shutOff()
|
||||||
self.UI.hide("Helper")
|
if loopId then
|
||||||
Wait.stopAll()
|
Wait.stop(loopId)
|
||||||
updateSave()
|
loopId = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- show buttons and begin monitoring chaos bag for curse and bless tokens
|
|
||||||
function initialize()
|
function initialize()
|
||||||
self.UI.show("Helper")
|
|
||||||
maybeUpdateButtonState()
|
maybeUpdateButtonState()
|
||||||
Wait.time(maybeUpdateButtonState, 1, -1)
|
loopId = Wait.time(maybeUpdateButtonState, 1, -1)
|
||||||
updateSave()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function resolveToken(player, _, tokenType)
|
function resolveToken(player, _, tokenType)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
require("playercards/CardsWithHelper")
|
require("playercards/CardsWithHelper")
|
||||||
local playermatApi = require("playermat/PlayermatApi")
|
local playermatApi = require("playermat/PlayermatApi")
|
||||||
|
|
||||||
|
-- intentionally global
|
||||||
|
hasXML = false
|
||||||
|
isHelperEnabled = false
|
||||||
|
|
||||||
-- common button parameters
|
-- common button parameters
|
||||||
local buttonParameters = {}
|
local buttonParameters = {}
|
||||||
@ -28,7 +32,6 @@ local customizableList = {
|
|||||||
|
|
||||||
-- index of the currently selected button (0-indexed from the top)
|
-- index of the currently selected button (0-indexed from the top)
|
||||||
local activeButtonIndex = -1
|
local activeButtonIndex = -1
|
||||||
local isHelperEnabled = false
|
|
||||||
local hypothesisList = {}
|
local hypothesisList = {}
|
||||||
|
|
||||||
function updateSave()
|
function updateSave()
|
||||||
@ -39,17 +42,17 @@ function updateSave()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function onLoad(savedData)
|
function onLoad(savedData)
|
||||||
self.addTag("CardWithHelper")
|
|
||||||
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
|
||||||
activeButtonIndex = loadedData.activeButtonIndex
|
activeButtonIndex = loadedData.activeButtonIndex
|
||||||
end
|
end
|
||||||
checkOptionPanel()
|
|
||||||
|
|
||||||
if activeButtonIndex > 0 then
|
if activeButtonIndex > 0 then
|
||||||
selectButton(activeButtonIndex)
|
selectButton(activeButtonIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
syncDisplayWithOptionPanel()
|
||||||
end
|
end
|
||||||
|
|
||||||
function initialize()
|
function initialize()
|
||||||
@ -74,7 +77,7 @@ function selectButton(index)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create buttons based on the button parameters
|
-- create buttons based on the button parameters
|
||||||
function createButtons()
|
function createButtons()
|
||||||
self.clearButtons()
|
self.clearButtons()
|
||||||
|
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
require("playercards/CardsWithHelper")
|
require("playercards/CardsWithHelper")
|
||||||
local playermatApi = require("playermat/PlayermatApi")
|
local playermatApi = require("playermat/PlayermatApi")
|
||||||
local searchLib = require("util/SearchLib")
|
local searchLib = require("util/SearchLib")
|
||||||
local tokenManager = require("core/token/TokenManager")
|
local tokenManager = require("core/token/TokenManager")
|
||||||
|
|
||||||
local isHelperEnabled = false
|
-- intentionally global
|
||||||
|
hasXML = true
|
||||||
|
isHelperEnabled = false
|
||||||
local clickableResourceCounter = nil
|
local clickableResourceCounter = nil
|
||||||
local foundTokens = 0
|
local foundTokens = 0
|
||||||
|
|
||||||
function updateSave()
|
function updateSave()
|
||||||
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
||||||
end
|
end
|
||||||
|
|
||||||
function onLoad()
|
function onLoad(savedData)
|
||||||
self.addTag("CardWithHelper")
|
|
||||||
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
|
||||||
end
|
end
|
||||||
checkOptionPanel()
|
syncDisplayWithOptionPanel()
|
||||||
end
|
end
|
||||||
|
|
||||||
function searchSelf()
|
function searchSelf()
|
||||||
@ -66,15 +67,3 @@ function loseAll(player)
|
|||||||
end
|
end
|
||||||
printToColor("Discarded " .. foundTokens .. " resource(s).", player.color)
|
printToColor("Discarded " .. foundTokens .. " resource(s).", player.color)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hide buttons
|
|
||||||
function shutOff()
|
|
||||||
self.UI.hide("Helper")
|
|
||||||
updateSave()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- show buttons
|
|
||||||
function initialize()
|
|
||||||
self.UI.show("Helper")
|
|
||||||
updateSave()
|
|
||||||
end
|
|
||||||
|
@ -5,8 +5,10 @@ local playermatApi = require("playermat/PlayermatApi")
|
|||||||
local searchLib = require("util/SearchLib")
|
local searchLib = require("util/SearchLib")
|
||||||
local tokenManager = require("core/token/TokenManager")
|
local tokenManager = require("core/token/TokenManager")
|
||||||
|
|
||||||
local isHelperEnabled = false
|
-- intentionally global
|
||||||
local updated
|
hasXML = true
|
||||||
|
isHelperEnabled = false
|
||||||
|
local updated, loopId
|
||||||
|
|
||||||
local xmlData = {
|
local xmlData = {
|
||||||
Action = { color = "#6D202CE6", onClick = "removeAndExtraAction" },
|
Action = { color = "#6D202CE6", onClick = "removeAndExtraAction" },
|
||||||
@ -16,31 +18,31 @@ local xmlData = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateSave()
|
function updateSave()
|
||||||
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
self.script_state = JSON.encode({
|
||||||
|
isHelperEnabled = isHelperEnabled,
|
||||||
|
loopId = loopId
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function onLoad(savedData)
|
function onLoad(savedData)
|
||||||
self.addTag("CardWithHelper")
|
|
||||||
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()
|
syncDisplayWithOptionPanel()
|
||||||
end
|
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()
|
function initialize()
|
||||||
self.UI.show("Helper")
|
|
||||||
maybeUpdateButtonState()
|
maybeUpdateButtonState()
|
||||||
Wait.time(maybeUpdateButtonState, 1, -1)
|
loopId = Wait.time(maybeUpdateButtonState, 1, -1)
|
||||||
updateSave()
|
end
|
||||||
|
|
||||||
|
function shutOff()
|
||||||
|
if loopId then
|
||||||
|
Wait.stop(loopId)
|
||||||
|
loopId = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function addTokenToBag(_, _, tokenType)
|
function addTokenToBag(_, _, tokenType)
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
require("playercards/CardsWithHelper")
|
require("playercards/CardsWithHelper")
|
||||||
local playermatApi = require("playermat/PlayermatApi")
|
local playermatApi = require("playermat/PlayermatApi")
|
||||||
|
|
||||||
|
-- intentionally global
|
||||||
|
hasXML = false
|
||||||
|
isHelperEnabled = false
|
||||||
|
|
||||||
|
local modValue, loopId
|
||||||
|
|
||||||
local buttonParameters = {
|
local buttonParameters = {
|
||||||
click_function = "shutOff",
|
click_function = "shutOff",
|
||||||
@ -10,13 +16,20 @@ local buttonParameters = {
|
|||||||
height = 175
|
height = 175
|
||||||
}
|
}
|
||||||
|
|
||||||
local modValue
|
|
||||||
|
|
||||||
function updateSave()
|
function updateSave()
|
||||||
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
|
self.script_state = JSON.encode({
|
||||||
|
isHelperEnabled = isHelperEnabled,
|
||||||
|
loopId = loopId
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function onLoad(savedData)
|
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
|
-- use metadata to detect level and adjust modValue accordingly
|
||||||
if JSON.decode(self.getGMNotes()).level == 0 then
|
if JSON.decode(self.getGMNotes()).level == 0 then
|
||||||
modValue = 5
|
modValue = 5
|
||||||
@ -24,25 +37,22 @@ function onLoad(savedData)
|
|||||||
modValue = 4
|
modValue = 4
|
||||||
end
|
end
|
||||||
|
|
||||||
self.addTag("CardWithHelper")
|
syncDisplayWithOptionPanel()
|
||||||
if savedData and savedData ~= "" then
|
|
||||||
local loadedData = JSON.decode(savedData)
|
|
||||||
isHelperEnabled = loadedData.isHelperEnabled
|
|
||||||
end
|
|
||||||
checkOptionPanel()
|
|
||||||
updateDisplay()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function initialize()
|
function initialize()
|
||||||
self.clearButtons()
|
self.clearButtons()
|
||||||
self.createButton(buttonParameters)
|
self.createButton(buttonParameters)
|
||||||
updateButton()
|
updateButton()
|
||||||
Wait.time(updateButton, 2, -1)
|
loopId = Wait.time(updateButton, 2, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function shutOff()
|
function shutOff()
|
||||||
self.clearButtons()
|
self.clearButtons()
|
||||||
Wait.stopAll()
|
if loopId then
|
||||||
|
Wait.stop(loopId)
|
||||||
|
loopId = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateButton()
|
function updateButton()
|
||||||
|
Loading…
Reference in New Issue
Block a user