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

@ -26,12 +26,13 @@ percentageLabel.width = 0
percentageLabel.height = 0
-- variables with save function
local tokenPrecedence = {}
local percentage = false
local tokenPrecedence = {}
local percentage = false
local includeDrawnTokens = true
-- variables without save function
local updating = false
local TOKEN_NAMES = {
local updating = false
local TOKEN_NAMES = {
"Elder Sign",
"Skull",
"Cultist",
@ -47,17 +48,19 @@ local TOKEN_NAMES = {
-- saving the precedence settings and information on the most recently loaded data
function onSave()
return JSON.encode({
tokenPrecedence = tokenPrecedence,
percentage = percentage
tokenPrecedence = tokenPrecedence,
percentage = percentage,
includeDrawnTokens = includeDrawnTokens
})
end
-- loading data, button creation and initial layouting
function onLoad(saveState)
if saveState ~= nil and saveState ~= "" then
local loadedData = JSON.decode(saveState)
tokenPrecedence = loadedData.tokenPrecedence
percentage = loadedData.percentage
local loadedData = JSON.decode(saveState)
tokenPrecedence = loadedData.tokenPrecedence
percentage = loadedData.percentage
includeDrawnTokens = loadedData.includeDrawnTokens
else
loadDefaultValues()
@ -74,23 +77,32 @@ function onLoad(saveState)
layout()
end)
self.addContextMenuItem("Toggle percentages", function()
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)
self.addContextMenuItem("Toggle cumulative", function()
self.addContextMenuItem("Toggle cumulative", function()
if percentage == "cumulative" then
percentage = "basic"
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
@ -156,7 +168,7 @@ function createButtonsAndInputs()
inputParameters.position = { pos.x[1] + offset, 0.1, pos.z + i * offset }
else
buttonParameters.position = { pos.x[2], 0, pos.z + (i - 5) * offset }
inputParameters.position = { pos.x[2] + offset, 0.1, pos.z + (i - 5) * offset }
inputParameters.position = { pos.x[2] + offset, 0.1, pos.z + (i - 5) * offset }
end
buttonParameters.click_function = "tokenClick" .. i
@ -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}
-- check if the tokenName contains letters (e.g. symbol token)
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,8 +265,8 @@ 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
percentageLabel.label = "100.0%"
@ -278,7 +290,7 @@ function layout(_, _, isRightClick)
return
end
-- get ChaosBag and stop if not found
-- get ChaosBag and stop if not found
local chaosBag = chaosBagApi.findChaosBag()
if not chaosBag then
updating = false
@ -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]
@ -316,7 +338,7 @@ function layout(_, _, isRightClick)
local rotation = self.getRotation()
local currentValue = data[1].value
local tokenCount = { row = 0, sum = 0, total = #data }
local valueCount = 1
local valueCount = 1
local tokenName = false
for i, item in ipairs(data) do
@ -339,8 +361,8 @@ function layout(_, _, isRightClick)
position = location,
rotation = rotation
})
tokenName = item.token.Nickname
location.z = location.z - 1.75
tokenName = item.token.Nickname
location.z = location.z - 1.75
tokenCount.row = tokenCount.row + 1
end

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