added support for manually returning tokens
This commit is contained in:
parent
d8b7d23c5c
commit
b7664906f9
@ -56,7 +56,6 @@ function resetTables()
|
|||||||
numInPlay = { Bless = 0, Curse = 0 }
|
numInPlay = { Bless = 0, Curse = 0 }
|
||||||
tokensTaken = { Bless = {}, Curse = {} }
|
tokensTaken = { Bless = {}, Curse = {} }
|
||||||
sealedTokens = {}
|
sealedTokens = {}
|
||||||
updateButtonLabels()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function initializeState()
|
function initializeState()
|
||||||
@ -86,6 +85,8 @@ function initializeState()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
updateButtonLabels()
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateButtonLabels()
|
function updateButtonLabels()
|
||||||
@ -95,7 +96,7 @@ end
|
|||||||
|
|
||||||
function broadcastCount(token)
|
function broadcastCount(token)
|
||||||
local count = formatTokenCount(token)
|
local count = formatTokenCount(token)
|
||||||
if count == "(0/0)" then return end
|
if count == "(0 + 0)" then return end
|
||||||
broadcastToAll(token .. " Tokens " .. count, "White")
|
broadcastToAll(token .. " Tokens " .. count, "White")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,6 +105,36 @@ function broadcastStatus(color)
|
|||||||
broadcastToColor("Bless Tokens " .. formatTokenCount("Bless"), color, "White")
|
broadcastToColor("Bless Tokens " .. formatTokenCount("Bless"), color, "White")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---------------------------------------------------------
|
||||||
|
-- TTS event handling
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
-- enable tracking of bag changes for 1 second
|
||||||
|
function onObjectDrop(_, object)
|
||||||
|
if not isBlurseToken(object) then return end
|
||||||
|
|
||||||
|
trackBagChange = true
|
||||||
|
Wait.time(function() trackBagChange = false end, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- handle manual returning of bless / curse tokens
|
||||||
|
function onObjectEnterContainer(container, object)
|
||||||
|
if not (trackBagChange and isChaosbag(container) and isBlurseToken(object)) then return end
|
||||||
|
|
||||||
|
-- small delay to ensure token has entered bag
|
||||||
|
Wait.time(doReset, 0.5)
|
||||||
|
end
|
||||||
|
|
||||||
|
function isChaosbag(obj)
|
||||||
|
if obj.getDescription() ~= "Chaos Bag" then return end -- early exit for performance
|
||||||
|
return obj == chaosBagApi.findChaosBag()
|
||||||
|
end
|
||||||
|
|
||||||
|
function isBlurseToken(obj)
|
||||||
|
local name = obj.getName()
|
||||||
|
return name == "Bless" or name == "Curse"
|
||||||
|
end
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- context menu functions
|
-- context menu functions
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
@ -128,10 +159,11 @@ function doRemove(color)
|
|||||||
broadcastToColor("Removed " .. removeTakenTokens("Bless") .. " Bless and " .. removeTakenTokens("Curse") .. " Curse tokens from play.", color, "White")
|
broadcastToColor("Removed " .. removeTakenTokens("Bless") .. " Bless and " .. removeTakenTokens("Curse") .. " Curse tokens from play.", color, "White")
|
||||||
|
|
||||||
resetTables()
|
resetTables()
|
||||||
|
updateButtonLabels()
|
||||||
tokenArrangerApi.layout()
|
tokenArrangerApi.layout()
|
||||||
end
|
end
|
||||||
|
|
||||||
function doReset(color)
|
function doReset()
|
||||||
initializeState()
|
initializeState()
|
||||||
broadcastCount("Curse")
|
broadcastCount("Curse")
|
||||||
broadcastCount("Bless")
|
broadcastCount("Bless")
|
||||||
@ -173,9 +205,9 @@ function formatTokenCount(type, omitBrackets)
|
|||||||
if type == nil then type = mode end
|
if type == nil then type = mode end
|
||||||
|
|
||||||
if omitBrackets then
|
if omitBrackets then
|
||||||
return (numInPlay[type] - #tokensTaken[type]) .. "/" .. #tokensTaken[type]
|
return (numInPlay[type] - #tokensTaken[type]) .. " + " .. #tokensTaken[type]
|
||||||
else
|
else
|
||||||
return "(" .. (numInPlay[type] - #tokensTaken[type]) .. "/" .. #tokensTaken[type] .. ")"
|
return "(" .. (numInPlay[type] - #tokensTaken[type]) .. " + " .. #tokensTaken[type] .. ")"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user