Merge pull request #310 from argonui/victory-updating

Victory Display: trigger update from clue hotkey
This commit is contained in:
Chr1Z 2023-06-15 23:37:20 +02:00 committed by GitHub
commit 3539820fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 16 deletions

View File

@ -1,5 +1,6 @@
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local playmatApi = require("playermat/PlaymatApi")
local victoryDisplayApi = require("core/VictoryDisplayApi")
function onLoad()
addHotkey("Add Doom to Agenda", addDoomToAgenda)
@ -43,10 +44,8 @@ function addDoomToAgenda()
end
-- moves the hovered card to the victory display
function moveCardToVictoryDisplay(playerColor, hoveredObject)
-- check if the provided object is a card
if hoveredObject == nil or hoveredObject.tag ~= "Card" then return end
getObjectFromGUID("6ccd6d").call("placeCard", hoveredObject)
function moveCardToVictoryDisplay(_, hoveredObject)
victoryDisplayApi.placeCard(hoveredObject)
end
-- takes a clue from a location, player needs to hover the clue directly or the location
@ -121,6 +120,8 @@ function takeClueFromLocation(playerColor, hoveredObject)
else
broadcastToAll(playerName .. " took one clue.", "Green")
end
victoryDisplayApi.update()
end
-- broadcasts the bless/curse status to the calling player

View File

@ -74,18 +74,12 @@ end
-- dropping an object on the victory display
function onCollisionEnter()
-- stop if there is already an update call running
if pendingCall then return end
pendingCall = true
Wait.time(updateCount, 0.2)
startUpdate()
end
-- removing an object from the victory display
function onCollisionExit()
-- stop if there is already an update call running
if pendingCall then return end
pendingCall = true
Wait.time(updateCount, 0.2)
startUpdate()
end
-- picking a clue or location up
@ -132,11 +126,14 @@ function maybeUpdate(obj, delay, flipped)
-- only continue if the obj in in the play area
if not playAreaApi.isInPlayArea(obj) then return end
-- set this flag to limit function calls (will be reset by "updateCount")
pendingCall = true
startUpdate(delay)
end
-- update the count with delay (or 0 if no delay is provided)
-- this is needed to let tokens drop on the card
-- starts an update
function startUpdate(delay)
-- stop if there is already an update call running
if pendingCall then return end
pendingCall = true
delay = tonumber(delay) or 0
Wait.time(updateCount, delay + 0.2)
end

View File

@ -0,0 +1,20 @@
do
local VictoryDisplayApi = {}
local VD_GUID = "6ccd6d"
-- triggers an update of the Victory count
---@param delay Number Delay in seconds after which the update call is executed
VictoryDisplayApi.update = function(delay)
getObjectFromGUID(VD_GUID).call("startUpdate", delay)
end
-- moves a card to the victory display (in the first empty spot)
---@param object Object Object that should be checked and potentially moved
VictoryDisplayApi.placeCard = function(object)
if object ~= nil and object.tag == "Card" then
getObjectFromGUID(VD_GUID).call("placeCard", object)
end
end
return VictoryDisplayApi
end