more updates

This commit is contained in:
dscarpac 2024-07-02 17:14:18 -05:00
parent e94c8431ff
commit cfa95bbc14
4 changed files with 37 additions and 39 deletions

View File

@ -266,6 +266,19 @@ function updateDisplayAndBroadcast(type)
end end
end end
function getBlessCurseInBag()
local numInBag = { Bless = 0, Curse = 0 }
local chaosBag = chaosBagApi.findChaosBag()
for _, v in ipairs(chaosBag.getObjects()) do
if v.name == "Bless" or v.name == "Curse" then
numInBag[v.name] = numInBag[v.name] + 1
end
end
return numInBag
end
--------------------------------------------------------- ---------------------------------------------------------
-- main functions: add and remove -- main functions: add and remove
--------------------------------------------------------- ---------------------------------------------------------

View File

@ -67,5 +67,9 @@ do
getManager().call("removeToken", type) getManager().call("removeToken", type)
end end
BlessCurseManagerApi.getBlessCurseInBag = function()
return getManager().call("getBlessCurseInBag", {})
end
return BlessCurseManagerApi return BlessCurseManagerApi
end end

View File

@ -1,4 +1,5 @@
require("playercards/CardsWithHelper") require("playercards/CardsWithHelper")
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi") local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
@ -34,6 +35,7 @@ function initialize()
end end
function resolveToken(player, _, tokenType) function resolveToken(player, _, tokenType)
if not updated then return end
local matColor local matColor
if player.color == "Black" then if player.color == "Black" then
matColor = playermatApi.getMatColorByPosition(self.getPosition()) matColor = playermatApi.getMatColorByPosition(self.getPosition())
@ -43,11 +45,13 @@ function resolveToken(player, _, tokenType)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
chaosBagApi.drawChaosToken(mat, true, tokenType) chaosBagApi.drawChaosToken(mat, true, tokenType)
updated = false
Wait.frames(maybeUpdateButtonState, 2)
end end
-- count tokens in the bag and show appropriate buttons -- count tokens in the bag and show appropriate buttons
function maybeUpdateButtonState() function maybeUpdateButtonState()
local numInBag = getBlessCurseInBag() local numInBag = blessCurseManagerApi.getBlessCurseInBag()
local state = { Bless = false, Curse = false } local state = { Bless = false, Curse = false }
if numInBag.Bless >= numInBag.Curse and numInBag.Bless > 0 then if numInBag.Bless >= numInBag.Curse and numInBag.Bless > 0 then
@ -59,19 +63,7 @@ function maybeUpdateButtonState()
end end
setUiState(state) setUiState(state)
end updated = true
function getBlessCurseInBag()
local numInBag = { Bless = 0, Curse = 0 }
local chaosBag = chaosBagApi.findChaosBag()
for _, v in ipairs(chaosBag.getObjects()) do
if v.name == "Bless" or v.name == "Curse" then
numInBag[v.name] = numInBag[v.name] + 1
end
end
return numInBag
end end
function setUiState(params) function setUiState(params)
@ -87,7 +79,7 @@ function setUiState(params)
end end
function errorMessage() function errorMessage()
local numInBag = getBlessCurseInBag() local numInBag = blessCurseManagerApi.getBlessCurseInBag()
if numInBag.Bless == 0 and numInBag.Curse == 0 then if numInBag.Bless == 0 and numInBag.Curse == 0 then
broadcastToAll("There are no Bless or Curse tokens in the chaos bag.", "Red") broadcastToAll("There are no Bless or Curse tokens in the chaos bag.", "Red")

View File

@ -1,10 +1,10 @@
require("playercards/CardsWithHelper") require("playercards/CardsWithHelper")
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager") local tokenManager = require("core/token/TokenManager")
local updated
function updateSave() function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled }) self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
@ -36,7 +36,10 @@ function initialize()
end end
function addTokenToBag(_, _, tokenType) function addTokenToBag(_, _, tokenType)
if not updated then return end
blessCurseManagerApi.addToken(tokenType) blessCurseManagerApi.addToken(tokenType)
updated = false
Wait.frames(maybeUpdateButtonState, 2)
end end
function removeAndExtraAction() function removeAndExtraAction()
@ -57,13 +60,11 @@ function removeAndExtraAction()
-- get first empty slot -- get first empty slot
local fullSlots = {} local fullSlots = {}
local positions = {} local positions = {}
local j = 1 for _, snap in ipairs(snaps) do
for i, snap in ipairs(snaps) do if snap.tags[1] == "UniversalToken" then
if snaps[i].tags[1] == "UniversalToken" then table.insert(positions, mat.positionToWorld(snap.position))
positions[j] = mat.positionToWorld(snap.position) local searchResult = searchLib.atPosition(positions[#positions], "isUniversalToken")
local searchResult = searchLib.atPosition(positions[j], "isUniversalToken") table.insert(fullSlots, #searchResult > 0)
fullSlots[j] = #searchResult > 0
j = j + 1
end end
end end
@ -87,7 +88,7 @@ end
-- count tokens in the bag and show appropriate buttons -- count tokens in the bag and show appropriate buttons
function maybeUpdateButtonState() function maybeUpdateButtonState()
local numInBag = getBlessCurseInBag() local numInBag = blessCurseManagerApi.getBlessCurseInBag()
local state = { Bless = false, Curse = false, Action = false, ElderSign = false } local state = { Bless = false, Curse = false, Action = false, ElderSign = false }
if numInBag.Bless <= numInBag.Curse and numInBag.Bless < 10 then if numInBag.Bless <= numInBag.Curse and numInBag.Bless < 10 then
@ -105,19 +106,7 @@ function maybeUpdateButtonState()
state.ElderSign = true state.ElderSign = true
setUiState(state) setUiState(state)
end updated = true
function getBlessCurseInBag()
local numInBag = { Bless = 0, Curse = 0 }
local chaosBag = chaosBagApi.findChaosBag()
for _, v in ipairs(chaosBag.getObjects()) do
if v.name == "Bless" or v.name == "Curse" then
numInBag[v.name] = numInBag[v.name] + 1
end
end
return numInBag
end end
function setUiState(params) function setUiState(params)
@ -133,7 +122,7 @@ function setUiState(params)
end end
function errorMessage(_, _, triggeringButton) function errorMessage(_, _, triggeringButton)
local numInBag = getBlessCurseInBag() local numInBag = blessCurseManagerApi.getBlessCurseInBag()
if triggeringButton == "inactiveAction" then if triggeringButton == "inactiveAction" then
broadcastToAll("There are not enough Blesses and/or Curses in the chaos bag.", "Red") broadcastToAll("There are not enough Blesses and/or Curses in the chaos bag.", "Red")
elseif numInBag.Bless == 10 and numInBag.Curse == 10 then elseif numInBag.Bless == 10 and numInBag.Curse == 10 then
@ -143,4 +132,4 @@ function errorMessage(_, _, triggeringButton)
else else
broadcastToAll("There are more Curse tokens than Bless tokens in the chaos bag.", "Red") broadcastToAll("There are more Curse tokens than Bless tokens in the chaos bag.", "Red")
end end
end end