Merge pull request #693 from argonui/hand-helper

Updated DES detection for Hand Helper // Increased search area
This commit is contained in:
dscarpac 2024-06-05 17:18:08 -05:00 committed by GitHub
commit 1621be3594
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 77 additions and 50 deletions

View File

@ -22,7 +22,7 @@
"ImageURL": "http://cloud-3.steamusercontent.com/ugc/1704036721123215146/E44A3B99EACF310E49E94977151A03C9A3DC7F17/", "ImageURL": "http://cloud-3.steamusercontent.com/ugc/1704036721123215146/E44A3B99EACF310E49E94977151A03C9A3DC7F17/",
"WidthScale": 0 "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 see the regular count).\n\nAllows you to randomly discard a card from your hand.",
"DragSelectable": true, "DragSelectable": true,
"GMNotes": "", "GMNotes": "",
"GUID": "450688", "GUID": "450688",

View File

@ -1,7 +1,7 @@
local playmatApi = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
-- forward declaration of variables that are used across functions -- forward declaration of variables that are used across functions
local matColor, handColor, loopId, hovering local matColor, handColor, hovering
function onLoad() function onLoad()
local buttonParamaters = {} local buttonParamaters = {}
@ -10,7 +10,7 @@ function onLoad()
-- index 0: button as hand size label -- index 0: button as hand size label
buttonParamaters.hover_color = "White" buttonParamaters.hover_color = "White"
buttonParamaters.click_function = "none" buttonParamaters.click_function = "none"
buttonParamaters.position = { 0, 0.11, -0.4 } buttonParamaters.position = Vector(0, 0.11, -0.4)
buttonParamaters.height = 0 buttonParamaters.height = 0
buttonParamaters.width = 0 buttonParamaters.width = 0
buttonParamaters.font_size = 500 buttonParamaters.font_size = 500
@ -19,17 +19,14 @@ function onLoad()
-- index 1: button to toggle "des" -- index 1: button to toggle "des"
buttonParamaters.label = "DES: ✗" buttonParamaters.label = "DES: ✗"
buttonParamaters.click_function = "none" buttonParamaters.position.z = 0.25
buttonParamaters.position = { 0, 0.11, 0.25 }
buttonParamaters.height = 0
buttonParamaters.width = 0
buttonParamaters.font_size = 120 buttonParamaters.font_size = 120
self.createButton(buttonParamaters) self.createButton(buttonParamaters)
-- index 2: button to discard a card -- index 2: button to discard a card
buttonParamaters.label = "discard random card" buttonParamaters.label = "Discard Random Card"
buttonParamaters.click_function = "discardRandom" buttonParamaters.click_function = "discardRandom"
buttonParamaters.position = { 0, 0.11, 0.7 } buttonParamaters.position.z = 0.7
buttonParamaters.height = 175 buttonParamaters.height = 175
buttonParamaters.width = 900 buttonParamaters.width = 900
buttonParamaters.font_size = 90 buttonParamaters.font_size = 90
@ -39,27 +36,24 @@ function onLoad()
updateColors() updateColors()
-- start loop to update card count -- start loop to update card count
loopId = Wait.time(updateValue, 1, -1) playmatApi.checkForDES(matColor)
Wait.time(updateValue, 1, -1)
end end
-- updates colors when object is dropped somewhere -- updates colors when object is dropped somewhere
function onDrop() updateColors() end function onDrop() updateColors() end
-- toggles counting method briefly -- disables DES counting while hovered
function onObjectHover(hover_color, obj) function onObjectHover(hoverColor, object)
-- only continue if correct player hovers over "self" if hoverColor ~= handColor then return end
if obj ~= self or hover_color ~= handColor or hovering then return end
-- toggle this flag so this doesn't get executed multiple times during the delay if object == self then
hovering = true hovering = true
playmatApi.checkForDES(matColor)
-- stop loop, toggle "des" and displayed value briefly, then start new loop after 2s updateValue()
Wait.stop(loopId) else
updateValue(true)
Wait.time(function()
loopId = Wait.time(updateValue, 1, -1)
hovering = false hovering = false
end, 1) end
end end
-- updates the matcolor and handcolor variable -- updates the matcolor and handcolor variable
@ -70,7 +64,7 @@ function updateColors()
end end
-- count cards in hand (by name for DES) -- count cards in hand (by name for DES)
function updateValue(toggle) function updateValue()
-- update colors if handColor doesn't own a handzone -- update colors if handColor doesn't own a handzone
if Player[handColor].getHandCount() == 0 then if Player[handColor].getHandCount() == 0 then
updateColors() updateColors()
@ -79,19 +73,24 @@ function updateValue(toggle)
-- if there is still no handzone, then end here -- if there is still no handzone, then end here
if Player[handColor].getHandCount() == 0 then return end 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 des = playmatApi.isDES(matColor) local hasDES = playmatApi.hasDES(matColor)
if toggle then des = not des end
self.editButton({ index = 1, label = "DES: " .. (des and "✓" or "✗") }) -- default to regular count if hovered
if hovering then
hasDES = false
end
self.editButton({ index = 1, label = "DES: " .. (hasDES and "✓" or "✗") })
-- count cards in hand -- count cards in hand
local hand = Player[handColor].getHandObjects() local hand = Player[handColor].getHandObjects()
local size = 0 local size = 0
if des then if hasDES then
local cardHash = {} local cardHash = {}
for _, obj in pairs(hand) do for _, obj in pairs(hand) do
if obj.tag == "Card" then if obj.type == "Card" then
local name = obj.getName() local name = obj.getName()
local title = string.match(name, '(.+)(%s%(%d+%))') or name local title = string.match(name, '(.+)(%s%(%d+%))') or name
cardHash[title] = true cardHash[title] = true
@ -102,12 +101,14 @@ function updateValue(toggle)
end end
else else
for _, obj in pairs(hand) do 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
end end
-- update button label and color -- 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 end
-- discards a random non-hidden card from hand -- discards a random non-hidden card from hand

View File

@ -16,6 +16,7 @@ local DISCARD_BUTTON_X_START = -1.365
local DISCARD_BUTTON_X_OFFSET = 0.455 local DISCARD_BUTTON_X_OFFSET = 0.455
local SEARCH_AROUND_SELF_X_BUFFER = 8 local SEARCH_AROUND_SELF_X_BUFFER = 8
local SEARCH_AROUND_SELF_Z_BUFFER = 1.75
-- defined areas for object searching -- defined areas for object searching
local MAIN_PLAY_AREA = { local MAIN_PLAY_AREA = {
@ -87,7 +88,7 @@ activeInvestigatorId = "00000"
local isDrawButtonVisible = false local isDrawButtonVisible = false
-- global variable to report "Dream-Enhancing Serum" status -- global variable to report "Dream-Enhancing Serum" status
isDES = false hasDES = false
-- table of type-object reference pairs of all owned objects -- table of type-object reference pairs of all owned objects
local ownedObjects = {} local ownedObjects = {}
@ -166,17 +167,23 @@ end
-- finds all objects on the playmat and associated set aside zone. -- finds all objects on the playmat and associated set aside zone.
function searchAroundSelf(filter) function searchAroundSelf(filter)
local scale = self.getScale()
local bounds = self.getBoundsNormalized() local bounds = self.getBoundsNormalized()
-- Increase the width to cover the set aside zone -- Increase the width to cover the set aside zone
bounds.size.x = bounds.size.x + SEARCH_AROUND_SELF_X_BUFFER bounds.size.x = bounds.size.x + SEARCH_AROUND_SELF_X_BUFFER
bounds.size.y = 1 bounds.size.y = 1
-- Since the cast is centered on the position, shift left or right to keep the non-set aside edge bounds.size.z = bounds.size.z + SEARCH_AROUND_SELF_Z_BUFFER
-- 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 -- 'setAsideDirection' accounts for the set aside zone being on the left or right,
-- table position of the playmat -- depending on the table position of the playmat
local setAsideDirection = bounds.center.z > 0 and 1 or -1 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) 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) return searchArea(self.positionToWorld(localCenter), bounds.size, filter)
end end
@ -287,7 +294,8 @@ function doUpkeep(_, clickedByColor, isRightClick)
updateMessageColor(clickedByColor) 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
checkForDES()
local forcedLearning = false local forcedLearning = false
local rot = self.getRotation() local rot = self.getRotation()
for _, obj in ipairs(searchAroundSelf()) do for _, obj in ipairs(searchAroundSelf()) do
@ -315,7 +323,7 @@ function doUpkeep(_, clickedByColor, isRightClick)
obj.setRotation({ rot.x, rot.y + yRotDiff, rot.z }) obj.setRotation({ rot.x, rot.y + yRotDiff, rot.z })
end end
-- detect forced learning to handle card drawing accordingly -- detect Forced Learning to handle card drawing accordingly
if cardMetadata.id == "08031" then if cardMetadata.id == "08031" then
forcedLearning = true forcedLearning = true
end end
@ -531,6 +539,23 @@ function doDiscardOne()
end end
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 -- slot symbol displaying
--------------------------------------------------------- ---------------------------------------------------------
@ -750,9 +775,6 @@ function onCollisionEnter(collisionInfo)
-- only continue for cards -- only continue for cards
if object.type ~= "Card" then return end 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) maybeUpdateActiveInvestigator(object)
syncCustomizableMetadata(object) syncCustomizableMetadata(object)
@ -765,11 +787,6 @@ function onCollisionEnter(collisionInfo)
end end
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 -- checks if tokens should be spawned for the provided card
function shouldSpawnTokens(card) function shouldSpawnTokens(card)
if card.is_face_down then if card.is_face_down then

View File

@ -47,11 +47,20 @@ do
end end
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 -- 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") ---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.isDES = function(matColor) ---@return boolean: whether DES is present on the playmat
PlaymatApi.hasDES = function(matColor)
for _, mat in pairs(getMatForColor(matColor)) do for _, mat in pairs(getMatForColor(matColor)) do
return mat.getVar("isDES") return mat.getVar("hasDES")
end end
end end