From bbd915122745ef8f8aad0fafe61897f5e2692368 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 15 Dec 2022 02:26:38 +0100 Subject: [PATCH] moving clue handling to playermatapi --- src/core/MasterClueCounter.ttslua | 44 +++---------------------------- src/playermat/Playmat.ttslua | 26 +++++++++++++++++- src/playermat/PlaymatApi.ttslua | 36 +++++++++++++++++++++++-- xml/Global.xml | 2 +- 4 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/core/MasterClueCounter.ttslua b/src/core/MasterClueCounter.ttslua index 71e314e9..574362b3 100644 --- a/src/core/MasterClueCounter.ttslua +++ b/src/core/MasterClueCounter.ttslua @@ -1,22 +1,7 @@ -local clueCounters = {} -local clueCounterGUIDS = { - "37be78", - "1769ed", - "032300", - "d86b7c" -} - -local clueClickers = {} -local clueClickerGUIDS = { - "db85d6", - "3f22e5", - "891403", - "4111de" -} - count = 0 useClickableCounters = false +local playmatAPI = require("playermat/PlaymatApi") function onSave() return JSON.encode(useClickableCounters) end function onLoad(savedData) @@ -37,41 +22,18 @@ function onLoad(savedData) color = { 0, 0, 0, 0 } }) - -- loading object references to the clue counters / clickers via GUID - for i = 1, 4 do - clueCounters[i] = getObjectFromGUID(clueCounterGUIDS[i]) - clueClickers[i] = getObjectFromGUID(clueClickerGUIDS[i]) - end - loopID = Wait.time(sumClues, 2, -1) end -- removes all player clues by calling the respective function from the counting bowls / clickers function removeAllPlayerClues() printToAll(count .. " clue(s) from playermats removed.", "White") - if useClickableCounters then - for i = 1, 4 do - clueClickers[i].call("updateVal", 0) - end - else - for i = 1, 4 do - clueCounters[i].call("removeAllClues") - end - end + playmatAPI.removeClues("All") self.editButton({ index = 0, label = "0" }) end -- gets the counted values from the counting bowls / clickers and sums them up function sumClues() - count = 0 - if useClickableCounters then - for i = 1, 4 do - count = count + tonumber(clueClickers[i].getVar("val")) - end - else - for i = 1, 4 do - count = count + tonumber(clueCounters[i].getVar("exposedValue")) - end - end + count = playmatAPI.getClueCount(useClickableCounters, "All") self.editButton({ index = 0, label = tostring(count) }) end diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 35ec0f09..c5902e71 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -689,7 +689,7 @@ function showDrawButton(visible) end -- Spawns / destroys a clickable clue counter for this playmat with the correct amount of clues ----@param showCounter Boolean. Whether the clickable clue counter should be present +---@param showCounter Boolean Whether the clickable clue counter should be present function clickableClues(showCounter) local CLUE_COUNTER = getObjectFromGUID(CLUE_COUNTER_GUID) local CLUE_CLICKER = getObjectFromGUID(CLUE_CLICKER_GUID) @@ -726,6 +726,30 @@ function clickableClues(showCounter) end end +-- removes all clues (moving tokens to the trash and setting counters to 0) +function removeClues() + local CLUE_COUNTER = getObjectFromGUID(CLUE_COUNTER_GUID) + local CLUE_CLICKER = getObjectFromGUID(CLUE_CLICKER_GUID) + + CLUE_COUNTER.call("removeAllClues") + CLUE_CLICKER.call("updateVal", 0) +end + +-- reports the clue count +---@param useClickableCounters Boolean Controls which type of counter is getting checked +function getClueCount(useClickableCounters) + local count = 0 + + if useClickableCounters then + local CLUE_CLICKER = getObjectFromGUID(CLUE_CLICKER_GUID) + count = tonumber(CLUE_CLICKER.getVar("val")) + else + local CLUE_COUNTER = getObjectFromGUID(CLUE_COUNTER_GUID) + count = tonumber(CLUE_COUNTER.getVar("exposedValue")) + end + return count +end + -- Sets this playermat's snap points to limit snapping to matching card types or not. If matchTypes -- is true, the main card slot snap points will only snap assets, while the investigator area point -- will only snap Investigators. If matchTypes is false, snap points will be reset to snap all diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 3b71b962..ba6f1687 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -6,7 +6,21 @@ do White = "8b081b", Orange = "bd0ff4", Green = "383d8b", - Red = "0840d5", + Red = "0840d5" + } + + local CLUE_COUNTER_GUIDS = { + White = "37be78", + Orange = "1769ed", + Green = "032300", + Red = "d86b7c" + } + + local CLUE_CLICKER_GUIDS = { + White = "db85d6", + Orange = "3f22e5", + Green = "891403", + Red = "4111de" } -- Sets the requested playermat's snap points to limit snapping to matching card types or not. If @@ -23,7 +37,6 @@ do end end - -- Sets the requested playermat's draw 1 button to visible ---@param isDrawButtonVisible Boolean. Whether the draw 1 button should be visible or not ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also @@ -44,6 +57,25 @@ do end end + -- Removes all clues (to the trash for tokens and counters set to 0) for the requested playermat + ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also + -- accepts "All" as a special value which will apply the setting to all four mats. + PlaymatApi.removeClues = function(matColor) + for _, mat in ipairs(internal.getMatForColor(matColor)) do + mat.call("removeClues") + end + end + + -- Reports the clue count for the requested playermat + ---@param useClickableCounters Boolean Controls which type of counter is getting checked + PlaymatApi.getClueCount = function(useClickableCounters, matColor) + local count = 0 + for _, mat in ipairs(internal.getMatForColor(matColor)) do + count = count + tonumber(mat.call("getClueCount", useClickableCounters)) + end + return count + end + -- Convenience function to look up a mat's object by color, or get all mats. ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also -- accepts "All" as a special value which will return all four mats. diff --git a/xml/Global.xml b/xml/Global.xml index ebb4622f..69935cd5 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -17,7 +17,7 @@