clean up helper update to dynamic references

This commit is contained in:
Chr1Z93 2023-09-29 17:00:31 +02:00
parent 3292f2a2d1
commit 4c0c025319
14 changed files with 176 additions and 181 deletions

View File

@ -67,6 +67,7 @@
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore",
"displacement_excluded"
],
"Tooltip": true,

View File

@ -44,6 +44,9 @@
"Nickname": "Clue tokens",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": true,
"Transform": {
"posX": 2.857,

View File

@ -44,6 +44,9 @@
"Nickname": "Connection markers",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": true,
"Transform": {
"posX": -51,

View File

@ -67,6 +67,7 @@
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore",
"displacement_excluded"
],
"Tooltip": true,

View File

@ -36,10 +36,14 @@
"LuaScript": "require(\"core/DoomCounter\")",
"LuaScriptState": "[0,{\"Agenda\":true,\"Playarea\":true,\"Playermats\":true}]",
"MeasureMovement": false,
"Memo": "{\"matColor\":\"Mythos\",\"type\":\"DoomCounter\"}",
"Name": "Custom_Token",
"Nickname": "Doom Counter",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": true,
"Transform": {
"posX": -5.3,

View File

@ -44,6 +44,9 @@
"Nickname": "Doom tokens",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": true,
"Transform": {
"posX": -55.48,

View File

@ -44,6 +44,9 @@
"Nickname": "Doom tokens",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": true,
"Transform": {
"posX": 2.761,

View File

@ -37,9 +37,12 @@
"LuaScriptState": "false",
"MeasureMovement": false,
"Name": "Custom_Token",
"Nickname": "Master Clue Counter\n",
"Nickname": "Master Clue Counter",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": true,
"Transform": {
"posX": -5.3,

View File

@ -67,6 +67,9 @@
"Nickname": "Mythos Area",
"Snap": true,
"Sticky": true,
"Tags": [
"CleanUpHelper_ignore"
],
"Tooltip": false,
"Transform": {
"posX": -1.309,

View File

@ -10,43 +10,15 @@ local playmatApi = require("playermat/PlaymatApi")
local soundCubeApi = require("core/SoundCubeApi")
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
-- these objects will be ignored
local IGNORE_GUIDS = {
-- big playmat, change image panel and investigator counter
"b7b45b", "f182ee", "721ba2",
-- bless/curse manager
"afa06b", "bd0253", "5933fb",
-- stuff on mythos area
"85c4c6", "4a3aa4", "fea079", "b015d8", "11e0cf", "9f334f", "70b9f6", "0a5a29",
-- doom/location token bag
"47ffc3", "170f10",
-- table
"4ee1f2"
}
-- objects with this tag will be ignored
local IGNORE_TAG = "CleanUpHelper_ignore"
-- colors and order for following tables
local COLORS = { "White", "Orange", "Green", "Red", "Mythos" }
-- counter GUIDS (4x damage and 4x horror)
local DAMAGE_HORROR_GUIDS = {
"eb08d6", "e64eec", "1f5a0a", "591a45",
"468e88", "0257d9", "7b5729", "beb964",
}
local campaignLog
local RESET_VALUES = {}
-- GUIDS of objects (in order of ownership relating to 'COLORS')
local PLAYERMAT_GUIDS = { "8b081b", "bd0ff4", "383d8b", "0840d5" }
local RESOURCE_GUIDS = { "4406f0", "816d84", "cd15ac", "a4b60d" }
local TRACKER_GUIDS = { "e598c2", "b4a5f7", "af7ed7", "e74881" }
local CLUE_GUIDS = { "d86b7c", "1769ed", "032300", "37be78" }
local CLUE_CLICKER_GUIDS = { "db85d6", "3f22e5", "891403", "4111de" }
local TRASHCAN_GUIDS = { "147e80", "f7b6c8", "5f896a", "4b8594", "70b9f6" }
-- values for physics.cast (4 entries for player zones, 5th entry for mythos area, 6th for campaign log)
local PHYSICS_POSITION = {
{ -54.5, 2, 21 },
@ -131,14 +103,6 @@ function onLoad(savedData)
buttonParameters.position.z = 1.1
buttonParameters.width = 1550
self.createButton(buttonParameters)
-- create single table for ignoring
for _, v in ipairs(CLUE_GUIDS) do table.insert(IGNORE_GUIDS, v) end
for _, v in ipairs(CLUE_CLICKER_GUIDS) do table.insert(IGNORE_GUIDS, v) end
for _, v in ipairs(RESOURCE_GUIDS) do table.insert(IGNORE_GUIDS, v) end
for _, v in ipairs(TRASHCAN_GUIDS) do table.insert(IGNORE_GUIDS, v) end
for _, v in ipairs(PLAYERMAT_GUIDS) do table.insert(IGNORE_GUIDS, v) end
for _, v in ipairs(DAMAGE_HORROR_GUIDS) do table.insert(IGNORE_GUIDS, v) end
end
---------------------------------------------------------
@ -178,13 +142,8 @@ function cleanUp(_, color)
getTrauma()
-- delay to account for potential state change
Wait.time(function()
updateCounters(RESOURCE_GUIDS, 5, "Resource")
updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clicker")
updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror")
end, 0.2)
Wait.time(updateCounters, 0.2)
resetSkillTrackers()
resetDoomCounter()
blessCurseManagerApi.removeAll(color)
removeLines()
@ -200,39 +159,20 @@ end
-- modular functions, called by other functions
---------------------------------------------------------
function updateCounters(tableOfGUIDs, newValues, info)
-- instead of a table, this will be used if just a single value is provided
local singleValue = tonumber(newValues)
function updateCounters()
playmatApi.updateCounter("All", "ResourceCounter" , 5)
playmatApi.updateCounter("All", "ClickableClueCounter" , 0)
playmatApi.resetSkillTracker("All")
for i, guid in ipairs(tableOfGUIDs) do
local TOKEN = getObjectFromGUID(guid)
local newValue = singleValue or newValues[i]
if TOKEN ~= nil then
TOKEN.call("updateVal", newValue)
else
printToAll(info .. ": No. " .. i .. " could not be found.", "Yellow")
end
end
end
-- set investigator skill trackers to "1, 1, 1, 1"
function resetSkillTrackers()
for i, guid in ipairs(TRACKER_GUIDS) do
local obj = getObjectFromGUID(guid)
if obj ~= nil then
obj.call("updateStats", { 1, 1, 1, 1 })
else
printToAll("Skill tracker for " .. COLORS[i] .. " playmat could not be found.", "Yellow")
end
for i = 1, 4 do
playmatApi.updateCounter(COLORS[i], "DamageCounter", RESET_VALUES.Damage[i])
playmatApi.updateCounter(COLORS[i], "HorrorCounter", RESET_VALUES.Horror[i])
end
end
-- reset doom on agenda
function resetDoomCounter()
local doomCounter = getObjectFromGUID("85c4c6")
local doomCounter = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "DoomCounter"})
if doomCounter ~= nil then
doomCounter.call("updateVal")
else
@ -240,19 +180,19 @@ function resetDoomCounter()
end
end
-- gets the GUID of a custom data helper (if present) and adds it to the ignore list
-- adds the ignore tag to the custom data helper
function ignoreCustomDataHelper()
local customDataHelper = playAreaApi.getCustomDataHelper()
if customDataHelper then
table.insert(IGNORE_GUIDS, customDataHelper.getGUID())
customDataHelper.addTag(IGNORE_TAG)
end
end
-- read values for trauma from campaign log if enabled
function getTrauma()
RESET_VALUES = {
0, 0, 0, 0,
0, 0, 0, 0
Damage = { 0, 0, 0, 0 },
Horror = { 0, 0, 0, 0 }
}
-- stop here if trauma import is disabled
@ -279,7 +219,14 @@ function loadTrauma()
if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green")
RESET_VALUES = campaignLog.call("returnTrauma")
trauma = campaignLog.call("returnTrauma")
for i = 1, 8 do
if i < 5 then
RESET_VALUES.Damage[i] = trauma[i]
else
RESET_VALUES.Horror[i-4] = trauma[i]
end
end
loadingFailedBefore = false
elseif loadingFailedBefore then
printToAll("Trauma values could not be found in campaign log!", "Yellow")
@ -302,7 +249,7 @@ end
-- remove drawn lines
function removeLines()
if options["removeDrawnLines"] then
printToAll("Removing vector lines...", "White")
printToAll("Removing global vector lines...", "White")
Global.setVectorLines({})
end
end
@ -311,30 +258,30 @@ end
function discardHands()
if not options["tidyPlayermats"] then return end
for i = 1, 4 do
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i])
if trashcan == nil then return end
local trash = Global.call("getObjectFromMemo", {matColor = COLORS[i], type = "Trash"})
if trash == nil then return end
local hand = Player[playmatApi.getPlayerColor(COLORS[i])].getHandObjects()
for j = #hand, 1, -1 do
trashcan.putObject(hand[j])
trash.putObject(hand[j])
end
end
end
-- clean up for play area
function tidyPlayareaCoroutine()
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[5])
local PLAYMATZONE = getObjectFromGUID("a2f932")
local trash = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "Trash"})
local playAreaZone = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayAreaZone"})
if PLAYMATZONE == nil then
if playAreaZone == nil then
printToAll("Scripting zone for main play area could not be found!", "Red")
elseif trashcan == nil then
elseif trash == nil then
printToAll("Trashcan for main play area could not be found!", "Red")
else
for _, obj in ipairs(PLAYMATZONE.getObjects()) do
for _, obj in ipairs(playAreaZone.getObjects()) do
-- ignore these elements
if not tableContains(IGNORE_GUIDS, obj.getGUID()) and obj.hasTag(IGNORE_TAG) == false then
if obj.hasTag(IGNORE_TAG) == false then
coroutine.yield(0)
trashcan.putObject(obj)
trash.putObject(obj)
end
end
end
@ -352,34 +299,32 @@ function tidyPlayerMatCoroutine()
-- delay for animation purpose
for k = 1, 30 do coroutine.yield(0) end
-- get respective trashcan
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i])
if trashcan == nil then
-- get respective trash
local trash = Global.call("getObjectFromMemo", {matColor = COLORS[i], type = "Trash"})
if trash == nil then
printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red")
return 1
end
for _, entry in ipairs(findObjects(i)) do
local obj = entry.hit_object
local desc_low = string.lower(obj.getDescription())
-- ignore these elements
if not tableContains(IGNORE_GUIDS, obj.getGUID())
and obj.hasTag(IGNORE_TAG) == false
and desc_low ~= "chaos bag"
and desc_low ~= "action token" then
if obj.hasTag(IGNORE_TAG) == false
and obj.hasTag("ActionToken") == false
and obj.hasTag("chaosBag") == false then
coroutine.yield(0)
trashcan.putObject(obj)
trash.putObject(obj)
-- flip action tokens back to ready
elseif desc_low == "action token" and obj.is_face_down then
elseif obj.hasTag("ActionToken") == false and obj.is_face_down then
obj.flip()
end
end
-- reset "activeInvestigatorId"
if i < 5 then
local playermat = getObjectFromGUID(PLAYERMAT_GUIDS[i])
local playermat = Global.call("getObjectFromMemo", {matColor = COLORS[i], type = "Playermat"})
if playermat then
playermat.setVar("activeInvestigatorId", "00000")
end
@ -387,7 +332,7 @@ function tidyPlayerMatCoroutine()
end
end
local datahelper = getObjectFromGUID("708279")
local datahelper = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "DataHelper"})
if datahelper then
datahelper.setTable("SPAWNED_PLAYER_CARD_GUIDS", {})
end
@ -412,13 +357,3 @@ function findObjects(num)
debug = false
})
end
-- search a table for a value, return true if found (else returns false)
function tableContains(table, value)
for _, v in ipairs(table) do
if v == value then
return true
end
end
return false
end

View File

@ -16,8 +16,8 @@ function searchSelf()
for _, obj in ipairs(searchArea(self.getPosition(), { 2.5, 0.5, 3.5 })) do
local obj = obj.hit_object
if obj.getCustomObject().image ==
"http://cloud-3.steamusercontent.com/ugc/1758068501357192910/11DDDC7EF621320962FDCF3AE3211D5EDC3D1573/" then
local image = obj.getCustomObject().image
if image == "http://cloud-3.steamusercontent.com/ugc/1758068501357192910/11DDDC7EF621320962FDCF3AE3211D5EDC3D1573/" then
foundTokens = foundTokens + math.abs(obj.getQuantity())
obj.destruct()
elseif obj.getMemo() == "resourceCounter" then
@ -47,7 +47,7 @@ end
function takeAll(playerColor)
searchSelf()
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
playmatApi.gainResources(foundTokens, matColor)
playmatApi.updateCounter(matColor, "ResourceCounter", foundTokens)
if clickableResourceCounter then
clickableResourceCounter.call("updateVal", 0)

View File

@ -7,66 +7,65 @@ local modValue = 5 -- level 0 Well Connected
local loopId = nil
local b_display = {
click_function = "toggleCounter",
function_owner = self,
position = {0.88,0.5,-1.33},
font_size = 150,
width = 175,
height = 175
click_function = "toggleCounter",
function_owner = self,
position = { 0.88, 0.5, -1.33 },
font_size = 150,
width = 175,
height = 175
}
function onLoad(saved_data)
local notes = JSON.decode(self.getGMNotes())
local notes = JSON.decode(self.getGMNotes())
if notes.id == "54006" then -- hardcoded card id for upgraded Well Connected (3)
modValue = 4 -- Well Connected (3)
end
if notes.id == "54006" then -- hardcoded card id for upgraded Well Connected (3)
modValue = 4 -- Well Connected (3)
end
if saved_data != '' then
local loaded_data = JSON.decode(saved_data)
display = not loaded_data.saved_display
if saved_data != '' then
local loaded_data = JSON.decode(saved_data)
display = not loaded_data.saved_display
self.clearButtons()
toggleCounter()
end
self.clearButtons()
toggleCounter()
end
self.addContextMenuItem('Toggle Counter', toggleCounter)
self.addContextMenuItem('Toggle Counter', toggleCounter)
end
function onSave()
return JSON.encode({saved_display = display})
return JSON.encode({ saved_display = display })
end
function toggleCounter()
display = not display
display = not display
if display then
createUpdateDisplay()
loopId = Wait.time(|| createUpdateDisplay(), 2, -1)
else
if loopId ~= nil then
Wait.stop(loopId)
end
self.clearButtons()
loopId = nil
if display then
createUpdateDisplay()
loopId = Wait.time(createUpdateDisplay, 2, -1)
else
if loopId ~= nil then
Wait.stop(loopId)
end
self.clearButtons()
loopId = nil
end
end
function createUpdateDisplay()
count = math.max(math.floor(getPlayerResources() / modValue), 0)
count = math.max(math.floor(getPlayerResources() / modValue), 0)
b_display.label = tostring(count)
b_display.label = tostring(count)
if loopId == nil then
self.createButton(b_display)
else
self.editButton(b_display)
end
if loopId == nil then
self.createButton(b_display)
else
self.editButton(b_display)
end
end
function getPlayerResources()
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
return playmatApi.getResourceCount(matColor)
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
return playmatApi.getCounterValue(matColor, "ResourceCounter")
end

View File

@ -63,6 +63,7 @@ activeInvestigatorId = "00000"
-- table of type-object reference pairs of all owned objects
local ownedObjects = {}
local matColor = JSON.decode(self.getMemo()).matColor
-- variable to track the status of the "Show Draw Button" option
local isDrawButtonVisible = false
@ -83,7 +84,6 @@ function onLoad(save_state)
self.interactable = DEBUG
-- get object references to owned objects
local matColor= JSON.decode(self.getMemo()).matColor
ownedObjects = Global.call("getObjectsForMatColor", matColor)
-- button creation
@ -392,10 +392,10 @@ function doUpkeep(_, clickedByColor, isRightClick)
-- gain a resource (or two if playing Jenny Barnes)
if string.match(activeInvestigatorId, "%d%d%d%d%d") == "02003" then
gainResources(2)
updateCounter({type = "ResourceCounter", modifier = 2})
printToColor("Gaining 2 resources (Jenny)", messageColor)
else
gainResources(1)
updateCounter({type = "ResourceCounter", modifier = 1})
end
-- draw a card (with handling for Patrice and Forced Learning)
@ -421,18 +421,6 @@ function doUpkeep(_, clickedByColor, isRightClick)
end
end
-- adds the specified amount of resources to the resource counter
function gainResources(amount)
local count = ownedObjects.ResourceCounter.getVar("val")
local add = tonumber(amount) or 0
ownedObjects.ResourceCounter.call("updateVal", count + add)
end
-- returns the resource counter amount
function getResourceCount()
return ownedObjects.ResourceCounter.getVar("val")
end
-- function for "draw 1 button" (that can be added via option panel)
function doDrawOne(_, color)
-- send messages to player who clicked button if no seated player found
@ -822,6 +810,40 @@ function setObjectState(obj, stateId)
if obj.getStateId() ~= stateId then obj.setState(stateId) end
end
---------------------------------------------------------
-- manipulation of owned objects
---------------------------------------------------------
-- updates the specific owned counter
---@param param Table Contains the information to update:
--- type: String Counter to target
--- newValue: Number Value to set the counter to
--- modifier: Number If newValue is not provided, the existing value will be adjusted by this modifier
function updateCounter(param)
local counter = ownedObjects[param.type]
if counter ~= nil then
counter.call("updateVal", param.newValue or (counter.getVar("val") + param.modifier))
else
printToAll(param.type .. " for " .. matColor .. " could not be found.", "Yellow")
end
end
-- returns the resource counter amount
---@param type String Counter to target
function getCounterValue(type)
return ownedObjects.type.getVar("val")
end
-- set investigator skill tracker to "1, 1, 1, 1"
function resetSkillTracker()
local obj = ownedObjects.InvestigatorSkillTracker
if obj ~= nil then
obj.call("updateStats", { 1, 1, 1, 1 })
else
printToAll("Skill tracker for " .. matColor .. " playmat could not be found.", "Yellow")
end
end
---------------------------------------------------------
-- calls to 'Global' / functions for calls from outside
---------------------------------------------------------

View File

@ -150,17 +150,34 @@ do
return count
end
-- Adds the specified amount of resources to the requested playermat's resource counter
PlaymatApi.gainResources = function(amount, matColor)
-- updates the specified owned counter
---@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.
---@param type String Counter to target
---@param newValue Number Value to set the counter to
---@param modifier Number If newValue is not provided, the existing value will be adjusted by this modifier
PlaymatApi.updateCounter = function(matColor, type, newValue, modifier)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("gainResources", amount)
mat.call("updateCounter", {type = type, newValue = newValue, modifier = modifier})
end
end
-- Returns the resource counter amount for the requested playermat
PlaymatApi.getResourceCount = function(matColor)
-- returns the resource counter amount
---@param matColor String Color of the playermat
---@param type String Counter to target
PlaymatApi.getCounterValue = function(matColor, type)
local mat = Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"})
return mat.call("getResourceCount")
return mat.call("getCounterValue", type)
end
-- resets the specified skill tracker to "1, 1, 1, 1"
---@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.
PlaymatApi.resetSkillTracker = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("resetSkillTracker")
end
end
-- Discard a non-hidden card from the corresponding player's hand
@ -186,17 +203,15 @@ do
---@return: Array of playermat objects. If a single mat is requested, will return a single-element
-- array to simplify processing by consumers.
internal.getMatForColor = function(matColor)
local targetMat = Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"})
if targetMat != nil then
return { targetMatGuid }
end
if matColor == "All" then
return {
Global.call("getObjectFromMemo", {matColor = White, type = "Playermat"}),
Global.call("getObjectFromMemo", {matColor = Orange, type = "Playermat"}),
Global.call("getObjectFromMemo", {matColor = Green, type = "Playermat"}),
Global.call("getObjectFromMemo", {matColor = Red, type = "Playermat"})
Global.call("getObjectFromMemo", {matColor = "White", type = "Playermat"}),
Global.call("getObjectFromMemo", {matColor = "Orange", type = "Playermat"}),
Global.call("getObjectFromMemo", {matColor = "Green", type = "Playermat"}),
Global.call("getObjectFromMemo", {matColor = "Red", type = "Playermat"})
}
else
return { Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"}) }
end
end