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
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
---------------------------------------------------------

View File

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

View File

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

View File

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