From 6c2741a9df8966953b1a3a086999195567db222d Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 21 May 2024 14:03:53 +0200 Subject: [PATCH 1/5] updated DES detection for Hand Helper --- .../HandHelper.450688.json | 2 +- src/accessories/HandHelper.ttslua | 47 ++++++++++--------- src/playermat/Playmat.ttslua | 28 +++++------ src/playermat/PlaymatApi.ttslua | 4 +- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/objects/OptionPanelSource.830bd0/HandHelper.450688.json b/objects/OptionPanelSource.830bd0/HandHelper.450688.json index 1861ff83..21b6edb4 100644 --- a/objects/OptionPanelSource.830bd0/HandHelper.450688.json +++ b/objects/OptionPanelSource.830bd0/HandHelper.450688.json @@ -22,7 +22,7 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/1704036721123215146/E44A3B99EACF310E49E94977151A03C9A3DC7F17/", "WidthScale": 0 }, - "Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\"), hover over it to briefly toggle counting method.\n\nAllows you to randomly discard a card from your hand.", + "Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\"), hover over it to temporarily toggle counting method.\n\nWill detect if DES is present during each Upkeep.\n\nAllows you to randomly discard a card from your hand.", "DragSelectable": true, "GMNotes": "", "GUID": "450688", diff --git a/src/accessories/HandHelper.ttslua b/src/accessories/HandHelper.ttslua index b72c5ef5..75aa86ce 100644 --- a/src/accessories/HandHelper.ttslua +++ b/src/accessories/HandHelper.ttslua @@ -39,27 +39,23 @@ function onLoad() updateColors() -- start loop to update card count - loopId = Wait.time(updateValue, 1, -1) + Wait.time(updateValue, 1, -1) end -- updates colors when object is dropped somewhere function onDrop() updateColors() end --- toggles counting method briefly -function onObjectHover(hover_color, obj) - -- only continue if correct player hovers over "self" - if obj ~= self or hover_color ~= handColor or hovering then return end +-- toggles counting method while hovered +function onObjectHover(hoverColor, object) + if hoverColor ~= handColor then return end - -- toggle this flag so this doesn't get executed multiple times during the delay - hovering = true - - -- stop loop, toggle "des" and displayed value briefly, then start new loop after 2s - Wait.stop(loopId) - updateValue(true) - Wait.time(function() - loopId = Wait.time(updateValue, 1, -1) + if object == self then + hovering = true + else hovering = false - end, 1) + end + + updateValue() end -- updates the matcolor and handcolor variable @@ -70,7 +66,7 @@ function updateColors() end -- count cards in hand (by name for DES) -function updateValue(toggle) +function updateValue() -- update colors if handColor doesn't own a handzone if Player[handColor].getHandCount() == 0 then updateColors() @@ -80,18 +76,23 @@ function updateValue(toggle) if Player[handColor].getHandCount() == 0 then return end -- get state of "Dream-Enhancing Serum" from playermat and update button label - local des = playmatApi.isDES(matColor) - if toggle then des = not des end - self.editButton({ index = 1, label = "DES: " .. (des and "✓" or "✗") }) + local hasDES = playmatApi.hasDES(matColor) + + -- get opposite value if currently hovered + if hovering then + hasDES = not hasDES + end + + self.editButton({ index = 1, label = "DES: " .. (hasDES and "✓" or "✗") }) -- count cards in hand local hand = Player[handColor].getHandObjects() local size = 0 - if des then + if hasDES then local cardHash = {} for _, obj in pairs(hand) do - if obj.tag == "Card" then + if obj.type == "Card" then local name = obj.getName() local title = string.match(name, '(.+)(%s%(%d+%))') or name cardHash[title] = true @@ -102,12 +103,14 @@ function updateValue(toggle) end else for _, obj in pairs(hand) do - if obj.tag == "Card" then size = size + 1 end + if obj.type == "Card" then + size = size + 1 + end end end -- update button label and color - self.editButton({ index = 0, font_color = des and "Green" or "White", label = size }) + self.editButton({ index = 0, font_color = hasDES and "Green" or "White", label = size }) end -- discards a random non-hidden card from hand diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index b117134d..15892956 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -87,7 +87,7 @@ activeInvestigatorId = "00000" local isDrawButtonVisible = false -- global variable to report "Dream-Enhancing Serum" status -isDES = false +hasDES = false -- table of type-object reference pairs of all owned objects local ownedObjects = {} @@ -167,14 +167,17 @@ end -- finds all objects on the playmat and associated set aside zone. function searchAroundSelf(filter) local bounds = self.getBoundsNormalized() + -- Increase the width to cover the set aside zone bounds.size.x = bounds.size.x + SEARCH_AROUND_SELF_X_BUFFER bounds.size.y = 1 - -- Since the cast is centered on the position, shift left or right to keep the non-set aside edge - -- of the cast at the edge of the playmat - -- setAsideDirection accounts for the set aside zone being on the left or right, depending on the - -- table position of the playmat + + -- 'setAsideDirection' accounts for the set aside zone being on the left or right, + -- depending on the table position of the playmat local setAsideDirection = bounds.center.z > 0 and 1 or -1 + + -- Since the cast is centered on the position, shift left or right to keep + -- the non-set aside edge of the cast at the edge of the playmat local localCenter = self.positionToLocal(bounds.center) localCenter.x = localCenter.x + setAsideDirection * SEARCH_AROUND_SELF_X_BUFFER / 2 / self.getScale().x return searchArea(self.positionToWorld(localCenter), bounds.size, filter) @@ -287,8 +290,9 @@ function doUpkeep(_, clickedByColor, isRightClick) updateMessageColor(clickedByColor) - -- unexhaust cards in play zone, flip action tokens and find forcedLearning + -- unexhaust cards in play zone, flip action tokens and find Forced Learning / Dream-Enhancing Serum local forcedLearning = false + hasDES = false local rot = self.getRotation() for _, obj in ipairs(searchAroundSelf()) do if obj.getDescription() == "Action Token" and obj.is_face_down then @@ -315,9 +319,11 @@ function doUpkeep(_, clickedByColor, isRightClick) obj.setRotation({ rot.x, rot.y + yRotDiff, rot.z }) end - -- detect forced learning to handle card drawing accordingly + -- detect Forced Learning to handle card drawing accordingly if cardMetadata.id == "08031" then forcedLearning = true + elseif cardMetadata.id == "06159" then + hasDES = true end -- maybe replenish uses on certain cards @@ -750,9 +756,6 @@ function onCollisionEnter(collisionInfo) -- only continue for cards if object.type ~= "Card" then return end - -- detect if "Dream-Enhancing Serum" is placed - if object.getName() == "Dream-Enhancing Serum" then isDES = true end - maybeUpdateActiveInvestigator(object) syncCustomizableMetadata(object) @@ -765,11 +768,6 @@ function onCollisionEnter(collisionInfo) end end --- detect if "Dream-Enhancing Serum" is removed -function onCollisionExit(collisionInfo) - if collisionInfo.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end -end - -- checks if tokens should be spawned for the provided card function shouldSpawnTokens(card) if card.is_face_down then diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 17af3a37..e724fdbe 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -49,9 +49,9 @@ do -- Returns if there is the card "Dream-Enhancing Serum" on the requested playmat ---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All") - PlaymatApi.isDES = function(matColor) + PlaymatApi.hasDES = function(matColor) for _, mat in pairs(getMatForColor(matColor)) do - return mat.getVar("isDES") + return mat.getVar("hasDES") end end From 5eb2fcf071ddee6363d8399410a55da8bef141cd Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 21 May 2024 14:29:05 +0200 Subject: [PATCH 2/5] increased physics.cast() for action tokens above mat --- src/playermat/Playmat.ttslua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 15892956..0e4fba5a 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -16,6 +16,7 @@ local DISCARD_BUTTON_X_START = -1.365 local DISCARD_BUTTON_X_OFFSET = 0.455 local SEARCH_AROUND_SELF_X_BUFFER = 8 +local SEARCH_AROUND_SELF_Z_BUFFER = 1.75 -- defined areas for object searching local MAIN_PLAY_AREA = { @@ -166,11 +167,13 @@ end -- finds all objects on the playmat and associated set aside zone. function searchAroundSelf(filter) + local scale = self.getScale() local bounds = self.getBoundsNormalized() -- Increase the width to cover the set aside zone bounds.size.x = bounds.size.x + SEARCH_AROUND_SELF_X_BUFFER bounds.size.y = 1 + bounds.size.z = bounds.size.z + SEARCH_AROUND_SELF_Z_BUFFER -- 'setAsideDirection' accounts for the set aside zone being on the left or right, -- depending on the table position of the playmat @@ -179,7 +182,8 @@ function searchAroundSelf(filter) -- Since the cast is centered on the position, shift left or right to keep -- the non-set aside edge of the cast at the edge of the playmat local localCenter = self.positionToLocal(bounds.center) - localCenter.x = localCenter.x + setAsideDirection * SEARCH_AROUND_SELF_X_BUFFER / 2 / self.getScale().x + localCenter.x = localCenter.x + setAsideDirection * SEARCH_AROUND_SELF_X_BUFFER / 2 / scale.x + localCenter.z = localCenter.z - SEARCH_AROUND_SELF_Z_BUFFER / 2 / scale.z return searchArea(self.positionToWorld(localCenter), bounds.size, filter) end From 52c19cd6dde51497fccf4756317a11e8fd9bb86c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 5 Jun 2024 20:38:06 +0200 Subject: [PATCH 3/5] updated hover mode --- objects/OptionPanelSource.830bd0/HandHelper.450688.json | 2 +- src/accessories/HandHelper.ttslua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/objects/OptionPanelSource.830bd0/HandHelper.450688.json b/objects/OptionPanelSource.830bd0/HandHelper.450688.json index 21b6edb4..bb0c1c3b 100644 --- a/objects/OptionPanelSource.830bd0/HandHelper.450688.json +++ b/objects/OptionPanelSource.830bd0/HandHelper.450688.json @@ -22,7 +22,7 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/1704036721123215146/E44A3B99EACF310E49E94977151A03C9A3DC7F17/", "WidthScale": 0 }, - "Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\"), hover over it to temporarily toggle counting method.\n\nWill detect if DES is present during each Upkeep.\n\nAllows you to randomly discard a card from your hand.", + "Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\" - hover over it to temporarily to see the regular count).\n\nWill detect if DES is present during each Upkeep.\n\nAllows you to randomly discard a card from your hand.", "DragSelectable": true, "GMNotes": "", "GUID": "450688", diff --git a/src/accessories/HandHelper.ttslua b/src/accessories/HandHelper.ttslua index 75aa86ce..2e6f3984 100644 --- a/src/accessories/HandHelper.ttslua +++ b/src/accessories/HandHelper.ttslua @@ -45,7 +45,7 @@ end -- updates colors when object is dropped somewhere function onDrop() updateColors() end --- toggles counting method while hovered +-- disables DES counting while hovered function onObjectHover(hoverColor, object) if hoverColor ~= handColor then return end @@ -80,7 +80,7 @@ function updateValue() -- get opposite value if currently hovered if hovering then - hasDES = not hasDES + hasDES = false end self.editButton({ index = 1, label = "DES: " .. (hasDES and "✓" or "✗") }) From 2f21b2f2cfe01d873ebf6a4773c90a8a52c63b7e Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 5 Jun 2024 23:43:03 +0200 Subject: [PATCH 4/5] updated code to update onHover --- .../HandHelper.450688.json | 2 +- src/accessories/HandHelper.ttslua | 21 ++++++++----------- src/playermat/Playmat.ttslua | 21 ++++++++++++++++--- src/playermat/PlaymatApi.ttslua | 9 ++++++++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/objects/OptionPanelSource.830bd0/HandHelper.450688.json b/objects/OptionPanelSource.830bd0/HandHelper.450688.json index bb0c1c3b..572c3772 100644 --- a/objects/OptionPanelSource.830bd0/HandHelper.450688.json +++ b/objects/OptionPanelSource.830bd0/HandHelper.450688.json @@ -22,7 +22,7 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/1704036721123215146/E44A3B99EACF310E49E94977151A03C9A3DC7F17/", "WidthScale": 0 }, - "Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\" - hover over it to temporarily to see the regular count).\n\nWill detect if DES is present during each Upkeep.\n\nAllows you to randomly discard a card from your hand.", + "Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\" - hover over it to see the regular count).\n\nAllows you to randomly discard a card from your hand.", "DragSelectable": true, "GMNotes": "", "GUID": "450688", diff --git a/src/accessories/HandHelper.ttslua b/src/accessories/HandHelper.ttslua index 2e6f3984..70cbd5f0 100644 --- a/src/accessories/HandHelper.ttslua +++ b/src/accessories/HandHelper.ttslua @@ -1,7 +1,7 @@ local playmatApi = require("playermat/PlaymatApi") -- forward declaration of variables that are used across functions -local matColor, handColor, loopId, hovering +local matColor, handColor, hovering function onLoad() local buttonParamaters = {} @@ -10,7 +10,7 @@ function onLoad() -- index 0: button as hand size label buttonParamaters.hover_color = "White" buttonParamaters.click_function = "none" - buttonParamaters.position = { 0, 0.11, -0.4 } + buttonParamaters.position = Vector(0, 0.11, -0.4) buttonParamaters.height = 0 buttonParamaters.width = 0 buttonParamaters.font_size = 500 @@ -19,17 +19,14 @@ function onLoad() -- index 1: button to toggle "des" buttonParamaters.label = "DES: ✗" - buttonParamaters.click_function = "none" - buttonParamaters.position = { 0, 0.11, 0.25 } - buttonParamaters.height = 0 - buttonParamaters.width = 0 + buttonParamaters.position.z = 0.25 buttonParamaters.font_size = 120 self.createButton(buttonParamaters) -- index 2: button to discard a card - buttonParamaters.label = "discard random card" + buttonParamaters.label = "Discard Random Card" buttonParamaters.click_function = "discardRandom" - buttonParamaters.position = { 0, 0.11, 0.7 } + buttonParamaters.position.z = 0.7 buttonParamaters.height = 175 buttonParamaters.width = 900 buttonParamaters.font_size = 90 @@ -51,11 +48,11 @@ function onObjectHover(hoverColor, object) if object == self then hovering = true + playmatApi.checkForDES(matColor) + updateValue() else hovering = false end - - updateValue() end -- updates the matcolor and handcolor variable @@ -75,10 +72,10 @@ function updateValue() -- if there is still no handzone, then end here if Player[handColor].getHandCount() == 0 then return end - -- get state of "Dream-Enhancing Serum" from playermat and update button label + -- get state of "Dream-Enhancing Serum" from playermat local hasDES = playmatApi.hasDES(matColor) - -- get opposite value if currently hovered + -- default to regular count if hovered if hovering then hasDES = false end diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index f4dd30f5..c1b0ec9e 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -295,8 +295,8 @@ function doUpkeep(_, clickedByColor, isRightClick) updateMessageColor(clickedByColor) -- unexhaust cards in play zone, flip action tokens and find Forced Learning / Dream-Enhancing Serum + checkForDES() local forcedLearning = false - hasDES = false local rot = self.getRotation() for _, obj in ipairs(searchAroundSelf()) do if obj.getDescription() == "Action Token" and obj.is_face_down then @@ -326,8 +326,6 @@ function doUpkeep(_, clickedByColor, isRightClick) -- detect Forced Learning to handle card drawing accordingly if cardMetadata.id == "08031" then forcedLearning = true - elseif cardMetadata.id == "06159" then - hasDES = true end -- maybe replenish uses on certain cards @@ -541,6 +539,23 @@ function doDiscardOne() end end +-- checks if DES is present +function checkForDES() + hasDES = false + for _, obj in ipairs(searchAroundSelf()) do + if obj.type == "Card" then + local cardMetadata = JSON.decode(obj.getGMNotes()) or {} + + -- position is used to exclude deck / discard + local cardPos = self.positionToLocal(obj.getPosition()) + if cardMetadata.id == "06159" and cardPos.x < 1 then + hasDES = true + break + end + end + end +end + --------------------------------------------------------- -- slot symbol displaying --------------------------------------------------------- diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 57ef0660..1484cc39 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -47,8 +47,17 @@ do end end + -- Instructs a playmat to check for DES + ---@param matColor string Color of the playmat - White, Orange, Green, Red or All + PlaymatApi.checkForDES = function(matColor) + for _, mat in pairs(getMatForColor(matColor)) do + mat.call("checkForDES") + end + end + -- Returns if there is the card "Dream-Enhancing Serum" on the requested playmat ---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All") + ---@return boolean: whether DES is present on the playmat PlaymatApi.hasDES = function(matColor) for _, mat in pairs(getMatForColor(matColor)) do return mat.getVar("hasDES") From 47e81b403a0e738fb1cb72a868dbf476176f1ba3 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 6 Jun 2024 00:08:14 +0200 Subject: [PATCH 5/5] updated DES position testing --- src/accessories/HandHelper.ttslua | 1 + src/playermat/Playmat.ttslua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/accessories/HandHelper.ttslua b/src/accessories/HandHelper.ttslua index 70cbd5f0..7d8d97ef 100644 --- a/src/accessories/HandHelper.ttslua +++ b/src/accessories/HandHelper.ttslua @@ -36,6 +36,7 @@ function onLoad() updateColors() -- start loop to update card count + playmatApi.checkForDES(matColor) Wait.time(updateValue, 1, -1) end diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index c1b0ec9e..90f0670f 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -548,7 +548,7 @@ function checkForDES() -- position is used to exclude deck / discard local cardPos = self.positionToLocal(obj.getPosition()) - if cardMetadata.id == "06159" and cardPos.x < 1 then + if cardMetadata.id == "06159" and cardPos.x > -1 then hasDES = true break end