added option to include drawn tokens
This commit is contained in:
parent
769249c21f
commit
8cc5170c10
@ -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]}}
|
||||||
|
@ -26,12 +26,13 @@ percentageLabel.width = 0
|
|||||||
percentageLabel.height = 0
|
percentageLabel.height = 0
|
||||||
|
|
||||||
-- variables with save function
|
-- variables with save function
|
||||||
local tokenPrecedence = {}
|
local tokenPrecedence = {}
|
||||||
local percentage = false
|
local percentage = false
|
||||||
|
local includeDrawnTokens = true
|
||||||
|
|
||||||
-- variables without save function
|
-- variables without save function
|
||||||
local updating = false
|
local updating = false
|
||||||
local TOKEN_NAMES = {
|
local TOKEN_NAMES = {
|
||||||
"Elder Sign",
|
"Elder Sign",
|
||||||
"Skull",
|
"Skull",
|
||||||
"Cultist",
|
"Cultist",
|
||||||
@ -47,17 +48,19 @@ local TOKEN_NAMES = {
|
|||||||
-- saving the precedence settings and information on the most recently loaded data
|
-- saving the precedence settings and information on the most recently loaded data
|
||||||
function onSave()
|
function onSave()
|
||||||
return JSON.encode({
|
return JSON.encode({
|
||||||
tokenPrecedence = tokenPrecedence,
|
tokenPrecedence = tokenPrecedence,
|
||||||
percentage = percentage
|
percentage = percentage,
|
||||||
|
includeDrawnTokens = includeDrawnTokens
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- loading data, button creation and initial layouting
|
-- loading data, button creation and initial layouting
|
||||||
function onLoad(saveState)
|
function onLoad(saveState)
|
||||||
if saveState ~= nil and saveState ~= "" then
|
if saveState ~= nil and saveState ~= "" then
|
||||||
local loadedData = JSON.decode(saveState)
|
local loadedData = JSON.decode(saveState)
|
||||||
tokenPrecedence = loadedData.tokenPrecedence
|
tokenPrecedence = loadedData.tokenPrecedence
|
||||||
percentage = loadedData.percentage
|
percentage = loadedData.percentage
|
||||||
|
includeDrawnTokens = loadedData.includeDrawnTokens
|
||||||
else
|
else
|
||||||
loadDefaultValues()
|
loadDefaultValues()
|
||||||
|
|
||||||
@ -74,23 +77,32 @@ function onLoad(saveState)
|
|||||||
layout()
|
layout()
|
||||||
end)
|
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
|
if percentage then
|
||||||
percentage = false
|
percentage = false
|
||||||
else
|
else
|
||||||
percentage = "basic"
|
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
|
end
|
||||||
layout()
|
layout()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self.addContextMenuItem("Toggle cumulative", function()
|
self.addContextMenuItem("Toggle cumulative", function()
|
||||||
if percentage == "cumulative" then
|
if percentage == "cumulative" then
|
||||||
percentage = "basic"
|
percentage = "basic"
|
||||||
else
|
else
|
||||||
percentage = "cumulative"
|
percentage = "cumulative"
|
||||||
end
|
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()
|
layout()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -156,7 +168,7 @@ function createButtonsAndInputs()
|
|||||||
inputParameters.position = { pos.x[1] + offset, 0.1, pos.z + i * offset }
|
inputParameters.position = { pos.x[1] + offset, 0.1, pos.z + i * offset }
|
||||||
else
|
else
|
||||||
buttonParameters.position = { pos.x[2], 0, pos.z + (i - 5) * offset }
|
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
|
end
|
||||||
|
|
||||||
buttonParameters.click_function = "tokenClick" .. i
|
buttonParameters.click_function = "tokenClick" .. i
|
||||||
@ -226,23 +238,23 @@ function createPercentageButton(tokenCount, valueCount, tokenName)
|
|||||||
local startPos = Vector(2.3, -0.05, 0.875 * valueCount)
|
local startPos = Vector(2.3, -0.05, 0.875 * valueCount)
|
||||||
|
|
||||||
if percentage == "cumulative" then
|
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)
|
percentageLabel.position = startPos - Vector(0, 0, 2.85)
|
||||||
else
|
else
|
||||||
percentageLabel.scale = {2, 2, 2}
|
percentageLabel.scale = { 2, 2, 2 }
|
||||||
percentageLabel.position = startPos - Vector(0, 0, 2.675)
|
percentageLabel.position = startPos - Vector(0, 0, 2.675)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- determine font_color
|
-- determine font_color
|
||||||
if tokenName == "Elder Sign" then
|
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
|
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)
|
-- check if the tokenName contains letters (e.g. symbol token)
|
||||||
elseif string.match(tokenName, "%a") ~= nil then
|
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
|
else
|
||||||
percentageLabel.font_color = {0.85, 0.67, 0.33}
|
percentageLabel.font_color = { 0.85, 0.67, 0.33 }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create label for base percentage
|
-- create label for base percentage
|
||||||
@ -253,8 +265,8 @@ function createPercentageButton(tokenCount, valueCount, tokenName)
|
|||||||
-- optionally create label for cumulative percentage
|
-- optionally create label for cumulative percentage
|
||||||
if percentage == "cumulative" then
|
if percentage == "cumulative" then
|
||||||
percentageLabel.position = startPos - Vector(0, 0, 2.45)
|
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%
|
-- only display one digit for 100%
|
||||||
if tokenCount.sum == tokenCount.total then
|
if tokenCount.sum == tokenCount.total then
|
||||||
percentageLabel.label = "100.0%"
|
percentageLabel.label = "100.0%"
|
||||||
@ -278,7 +290,7 @@ function layout(_, _, isRightClick)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get ChaosBag and stop if not found
|
-- get ChaosBag and stop if not found
|
||||||
local chaosBag = chaosBagApi.findChaosBag()
|
local chaosBag = chaosBagApi.findChaosBag()
|
||||||
if not chaosBag then
|
if not chaosBag then
|
||||||
updating = false
|
updating = false
|
||||||
@ -286,8 +298,18 @@ function layout(_, _, isRightClick)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- clone tokens from chaos bag (default position above trash can)
|
-- 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 = {}
|
local data = {}
|
||||||
for i, objData in ipairs(chaosBag.getData().ContainedObjects) do
|
for i, objData in ipairs(rawData) do
|
||||||
objData["Tags"] = { "tempToken" }
|
objData["Tags"] = { "tempToken" }
|
||||||
local value = tonumber(objData.Nickname)
|
local value = tonumber(objData.Nickname)
|
||||||
local precedence = tokenPrecedence[objData.Nickname]
|
local precedence = tokenPrecedence[objData.Nickname]
|
||||||
@ -316,7 +338,7 @@ function layout(_, _, isRightClick)
|
|||||||
local rotation = self.getRotation()
|
local rotation = self.getRotation()
|
||||||
local currentValue = data[1].value
|
local currentValue = data[1].value
|
||||||
local tokenCount = { row = 0, sum = 0, total = #data }
|
local tokenCount = { row = 0, sum = 0, total = #data }
|
||||||
local valueCount = 1
|
local valueCount = 1
|
||||||
local tokenName = false
|
local tokenName = false
|
||||||
|
|
||||||
for i, item in ipairs(data) do
|
for i, item in ipairs(data) do
|
||||||
@ -339,8 +361,8 @@ function layout(_, _, isRightClick)
|
|||||||
position = location,
|
position = location,
|
||||||
rotation = rotation
|
rotation = rotation
|
||||||
})
|
})
|
||||||
tokenName = item.token.Nickname
|
tokenName = item.token.Nickname
|
||||||
location.z = location.z - 1.75
|
location.z = location.z - 1.75
|
||||||
tokenCount.row = tokenCount.row + 1
|
tokenCount.row = tokenCount.row + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,6 +23,11 @@ do
|
|||||||
return Global.call("findChaosBag")
|
return Global.call("findChaosBag")
|
||||||
end
|
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
|
-- returns all sealed tokens on cards to the chaos bag
|
||||||
ChaosBagApi.releaseAllSealedTokens = function(playerColor)
|
ChaosBagApi.releaseAllSealedTokens = function(playerColor)
|
||||||
return Global.call("releaseAllSealedTokens", playerColor)
|
return Global.call("releaseAllSealedTokens", playerColor)
|
||||||
|
@ -32,8 +32,10 @@ local NOT_INTERACTABLE = {
|
|||||||
"975c39", -- vertical border right
|
"975c39", -- vertical border right
|
||||||
}
|
}
|
||||||
|
|
||||||
local chaosTokens = {}
|
-- global variable for access
|
||||||
|
chaosTokens = {}
|
||||||
local chaosTokensLastMat = nil
|
local chaosTokensLastMat = nil
|
||||||
|
|
||||||
local bagSearchers = {}
|
local bagSearchers = {}
|
||||||
local MAT_COLORS = {"White", "Orange", "Green", "Red"}
|
local MAT_COLORS = {"White", "Orange", "Green", "Red"}
|
||||||
local hideTitleSplashWaitFunctionId = nil
|
local hideTitleSplashWaitFunctionId = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user