From e564a1f1feff261d60560d673ca53c99419c12cb Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 14 Jun 2023 22:17:55 +0200 Subject: [PATCH 1/2] trigger update from clue hotkey --- src/core/GameKeyHandler.ttslua | 3 +++ src/core/VictoryDisplay.ttslua | 21 +++++++++------------ src/core/VictoryDisplayApi.ttslua | 12 ++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 src/core/VictoryDisplayApi.ttslua diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index daaa243c..6e61ed8f 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -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) @@ -121,6 +122,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 diff --git a/src/core/VictoryDisplay.ttslua b/src/core/VictoryDisplay.ttslua index 49b4ca7b..eaaebac8 100644 --- a/src/core/VictoryDisplay.ttslua +++ b/src/core/VictoryDisplay.ttslua @@ -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 diff --git a/src/core/VictoryDisplayApi.ttslua b/src/core/VictoryDisplayApi.ttslua new file mode 100644 index 00000000..bbf47b9f --- /dev/null +++ b/src/core/VictoryDisplayApi.ttslua @@ -0,0 +1,12 @@ +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 + + return VictoryDisplayApi +end From 4fb8b3786ed46b580e7550218a6db340e772d071 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 15 Jun 2023 23:18:17 +0200 Subject: [PATCH 2/2] moved "placeCard" into API --- src/core/GameKeyHandler.ttslua | 6 ++---- src/core/VictoryDisplayApi.ttslua | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index 6e61ed8f..f43ddbea 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -44,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 diff --git a/src/core/VictoryDisplayApi.ttslua b/src/core/VictoryDisplayApi.ttslua index bbf47b9f..2401ba43 100644 --- a/src/core/VictoryDisplayApi.ttslua +++ b/src/core/VictoryDisplayApi.ttslua @@ -8,5 +8,13 @@ do 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