fixed empty space

This commit is contained in:
dscarpac 2024-04-17 23:08:30 -05:00
parent 4955c09e65
commit a878a15efd
2 changed files with 36 additions and 20 deletions

View File

@ -304,6 +304,7 @@ function drawChaosToken(params)
-- add the token to the list, compute new position based on list length
if params.returnedToken then
trackChaosToken(params.returnedToken.getName(), matGUID, "subtract")
indexOfReturnedToken = getTokenIndex(params.returnedToken)
tokenPosition = params.returnedToken.getPosition()
if #chaosTokens > indexOfReturnedToken then
@ -317,8 +318,9 @@ function drawChaosToken(params)
end
local token
-- resolve a sealed token from a card
if params.guidToBeResolved then
if params.guidToBeResolved then
token = getObjectFromGUID(params.guidToBeResolved)
token.setPositionSmooth(tokenPosition)
local guid = token.getGUID()
@ -328,7 +330,7 @@ function drawChaosToken(params)
end
tokenArrangerApi.layout()
-- take a token from the bag, either specified or random
else
else
local takeParameters = {
position = tokenPosition,
rotation = tokenRotation
@ -346,15 +348,18 @@ function drawChaosToken(params)
end
-- get data for token description
local name = token.getName()
if name == "" then name = "Custom" end
local tokenData = mythosAreaApi.returnTokenData().tokenData or {}
local specificData = tokenData[name] or {}
token.setDescription(specificData.description or "")
-- track the chaos token (for stat tracker and future returning)
trackChaosToken(name, matGUID)
chaosTokens[#chaosTokens + 1] = token
trackChaosToken(name, matGUID, "add")
if params.returnedToken then
chaosTokens[indexOfReturnedToken] = token
else
chaosTokens[#chaosTokens + 1] = token
end
else
returnChaosTokens()
end
@ -375,13 +380,19 @@ end
-- chaos token stat tracker
---------------------------------------------------------
function trackChaosToken(tokenName, matGUID)
function trackChaosToken(tokenName, matGUID, addOrSubtract)
-- initialize tables
if not tokenDrawingStats[matGUID] then tokenDrawingStats[matGUID] = {} end
if tokenName == "" then tokenName = "Custom" end
-- increase stats by 1
tokenDrawingStats["Overall"][tokenName] = (tokenDrawingStats["Overall"][tokenName] or 0) + 1
tokenDrawingStats[matGUID][tokenName] = (tokenDrawingStats[matGUID][tokenName] or 0) + 1
-- increase stats by 1 or decreause if token is returned
if addOrSubtract == "add" then
tokenDrawingStats["Overall"][tokenName] = (tokenDrawingStats["Overall"][tokenName] or 0) + 1
tokenDrawingStats[matGUID][tokenName] = (tokenDrawingStats[matGUID][tokenName] or 0) + 1
else
tokenDrawingStats["Overall"][tokenName] = (tokenDrawingStats["Overall"][tokenName] or 0) - 1
tokenDrawingStats[matGUID][tokenName] = (tokenDrawingStats[matGUID][tokenName] or 0) - 1
end
end
-- Left-click: print stats, Right-click: reset stats

View File

@ -33,7 +33,7 @@ function onSave()
end
function onLoad(savedData)
self.addContextMenuItem("Enable Helper", createButtons)
self.addContextMenuItem("Enable Helper", chooseSigil)
sigil= JSON.decode(savedData)
if sigil and sigil ~= nil then
makeXMLButton(sigil)
@ -69,8 +69,8 @@ function makeXMLButton(chosenToken)
)
end
-- Create buttons to choose sigil
function createButtons(playerColor)
-- Create dialog window to choose sigil and create sigil-drawing button
function chooseSigil(playerColor)
self.clearContextMenu()
self.addContextMenuItem("Clear Helper", deleteButtons)
Player[playerColor].showOptionsDialog("Choose Sigil", tokenNames, 1,
@ -88,7 +88,7 @@ end
-- Delete button and remove sigil
function deleteButtons()
self.clearContextMenu()
self.addContextMenuItem("Enable Helper", createButtons)
self.addContextMenuItem("Enable Helper", chooseSigil)
self.UI.setXml("")
sigil = nil
end
@ -113,11 +113,19 @@ function resolveSigil()
return
end
local symbolMatch = false
local matchingSymbolsInPlay = {}
for j, token in ipairs(tokensInPlay) do
if (token.getName() == "Cultist" or token.getName() == "Elder Thing" or token.getName() == "Tablet") and token.getName() ~= sigil then
symbolMatch = true
matchingSymbolsInPlay[#matchingSymbolsInPlay + 1] = token
end
end
if #matchingSymbolsInPlay == 0 then
broadcastToAll("No eligible symbol token found in play area", "Red")
return
elseif #matchingSymbolsInPlay > 1 then
for j, token in ipairs(matchingSymbolsInPlay) do
-- draw XML to return token to bag
token.UI.setXmlTable({
{
@ -156,11 +164,8 @@ function resolveSigil()
}
})
end
end
if not symbolMatch then
broadcastToAll("No eligible symbol token found in play area", "Red")
return
else
drawSigil(_, matchingSymbolsInPlay[1].getGUID())
end
end