added option to include drawn tokens

This commit is contained in:
Chr1Z93 2023-09-28 19:44:54 +02:00
parent 769249c21f
commit 8cc5170c10
4 changed files with 59 additions and 30 deletions

View File

@ -1 +1 @@
{"percentage":false,"tokenPrecedence":{"":[0,11],"Auto-fail":[-100,7],"Bless":[101,8],"Cultist":[-2,4],"Curse":[-101,9],"Elder Sign":[100,2],"Elder Thing":[-4,6],"Frost":[-99,10],"Skull":[-1,3],"Tablet":[-3,5]}}
{"includeDrawnTokens":true,"percentage":false,"tokenPrecedence":{"":[0,11],"Auto-fail":[-100,7],"Bless":[101,8],"Cultist":[-2,4],"Curse":[-101,9],"Elder Sign":[100,2],"Elder Thing":[-4,6],"Frost":[-99,10],"Skull":[-1,3],"Tablet":[-3,5]}}

View File

@ -28,6 +28,7 @@ percentageLabel.height = 0
-- variables with save function
local tokenPrecedence = {}
local percentage = false
local includeDrawnTokens = true
-- variables without save function
local updating = false
@ -48,7 +49,8 @@ local TOKEN_NAMES = {
function onSave()
return JSON.encode({
tokenPrecedence = tokenPrecedence,
percentage = percentage
percentage = percentage,
includeDrawnTokens = includeDrawnTokens
})
end
@ -58,6 +60,7 @@ function onLoad(saveState)
local loadedData = JSON.decode(saveState)
tokenPrecedence = loadedData.tokenPrecedence
percentage = loadedData.percentage
includeDrawnTokens = loadedData.includeDrawnTokens
else
loadDefaultValues()
@ -74,12 +77,20 @@ function onLoad(saveState)
layout()
end)
self.addContextMenuItem("Include drawn tokens", function()
includeDrawnTokens = not includeDrawnTokens
local text = includeDrawnTokens and " " or " not "
broadcastToAll("Token Arranger will" .. text .. "include currently drawn chaos tokens.", "Orange")
layout()
end)
self.addContextMenuItem("Toggle percentages", function()
if percentage then
percentage = false
else
percentage = "basic"
broadcastToAll("Percentages are unreliable when using tokens that draw other tokens (bless or curse for example).", "Yellow")
broadcastToAll("Percentages are unreliable when using tokens that draw other tokens (bless or curse for example).",
"Yellow")
end
layout()
end)
@ -90,7 +101,8 @@ function onLoad(saveState)
else
percentage = "cumulative"
end
broadcastToAll("Percentages are unreliable when using tokens that draw other tokens (bless or curse for example).", "Yellow")
broadcastToAll("Percentages are unreliable when using tokens that draw other tokens (bless or curse for example).",
"Yellow")
layout()
end)
end
@ -226,23 +238,23 @@ function createPercentageButton(tokenCount, valueCount, tokenName)
local startPos = Vector(2.3, -0.05, 0.875 * valueCount)
if percentage == "cumulative" then
percentageLabel.scale = {1.5, 1.5, 1.5}
percentageLabel.scale = { 1.5, 1.5, 1.5 }
percentageLabel.position = startPos - Vector(0, 0, 2.85)
else
percentageLabel.scale = {2, 2, 2}
percentageLabel.scale = { 2, 2, 2 }
percentageLabel.position = startPos - Vector(0, 0, 2.675)
end
-- determine font_color
if tokenName == "Elder Sign" then
percentageLabel.font_color = {0.35, 0.71, 0.85}
percentageLabel.font_color = { 0.35, 0.71, 0.85 }
elseif tokenName == "Auto-fail" then
percentageLabel.font_color = {0.86, 0.1, 0.1}
percentageLabel.font_color = { 0.86, 0.1, 0.1 }
-- check if the tokenName contains letters (e.g. symbol token)
elseif string.match(tokenName, "%a") ~= nil then
percentageLabel.font_color = {0.68, 0.53, 0.86}
percentageLabel.font_color = { 0.68, 0.53, 0.86 }
else
percentageLabel.font_color = {0.85, 0.67, 0.33}
percentageLabel.font_color = { 0.85, 0.67, 0.33 }
end
-- create label for base percentage
@ -253,7 +265,7 @@ function createPercentageButton(tokenCount, valueCount, tokenName)
-- optionally create label for cumulative percentage
if percentage == "cumulative" then
percentageLabel.position = startPos - Vector(0, 0, 2.45)
percentageLabel.font_color = {1, 1, 1}
percentageLabel.font_color = { 1, 1, 1 }
-- only display one digit for 100%
if tokenCount.sum == tokenCount.total then
@ -286,8 +298,18 @@ function layout(_, _, isRightClick)
end
-- clone tokens from chaos bag (default position above trash can)
local rawData = chaosBag.getData().ContainedObjects
-- optionally get the data for tokens in play
if includeDrawnTokens then
for _, token in pairs(chaosBagApi.getTokensInPlay()) do
if token ~= nil then table.insert(rawData, token.getData()) end
end
end
-- generate layout data
local data = {}
for i, objData in ipairs(chaosBag.getData().ContainedObjects) do
for i, objData in ipairs(rawData) do
objData["Tags"] = { "tempToken" }
local value = tonumber(objData.Nickname)
local precedence = tokenPrecedence[objData.Nickname]

View File

@ -23,6 +23,11 @@ do
return Global.call("findChaosBag")
end
-- returns a table of object references to the tokens in play (does not include sealed tokens!)
ChaosBagApi.getTokensInPlay = function()
return Global.getTable("chaosTokens")
end
-- returns all sealed tokens on cards to the chaos bag
ChaosBagApi.releaseAllSealedTokens = function(playerColor)
return Global.call("releaseAllSealedTokens", playerColor)

View File

@ -32,8 +32,10 @@ local NOT_INTERACTABLE = {
"975c39", -- vertical border right
}
local chaosTokens = {}
-- global variable for access
chaosTokens = {}
local chaosTokensLastMat = nil
local bagSearchers = {}
local MAT_COLORS = {"White", "Orange", "Green", "Red"}
local hideTitleSplashWaitFunctionId = nil