From 4159dfc43d31337c6e2baef2e9706f9451965390 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 18 Oct 2023 20:55:38 +0200 Subject: [PATCH] resolving review comments --- .../CampaignImporterExporter.ttslua | 5 ++-- src/accessories/CleanUpHelper.ttslua | 29 +++++++++---------- src/accessories/TokenArrangerApi.ttslua | 4 +-- src/arkhamdb/DeckImporterApi.ttslua | 5 ++-- src/chaosbag/BlessCurseManagerApi.ttslua | 4 +-- src/core/DoomCounter.ttslua | 9 +++--- src/core/DoomInPlayCounter.ttslua | 7 ++--- src/core/GUIDReferenceApi.ttslua | 28 ++++++++++++++++++ src/core/GUIDReferenceHandler.ttslua | 6 ++-- src/core/GameKeyHandler.ttslua | 5 ++-- src/core/Global.ttslua | 4 +-- src/core/MythosArea.ttslua | 7 ++--- src/core/MythosAreaApi.ttslua | 4 +-- src/core/NavigationOverlayApi.ttslua | 4 +-- src/core/PlayArea.ttslua | 4 +-- src/core/PlayAreaApi.ttslua | 7 ++--- src/core/SoundCubeApi.ttslua | 4 +-- src/core/VictoryDisplay.ttslua | 17 ++--------- src/core/VictoryDisplayApi.ttslua | 4 +-- src/core/token/TokenManager.ttslua | 9 +++--- src/core/token/TokenSpawnTracker.ttslua | 14 +-------- src/core/token/TokenSpawnTrackerApi.ttslua | 4 +-- src/core/tour/TourManager.ttslua | 11 +++---- src/playercards/AllCardsBagApi.ttslua | 4 +-- src/playermat/ClueCounter.ttslua | 20 +++++-------- src/playermat/Playmat.ttslua | 5 ++-- src/playermat/PlaymatApi.ttslua | 6 ++-- 27 files changed, 112 insertions(+), 118 deletions(-) create mode 100644 src/core/GUIDReferenceApi.ttslua diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 8b5e6075..80facb5f 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -1,12 +1,11 @@ local blessCurseApi = require("chaosbag/BlessCurseManagerApi") local chaosBagApi = require("chaosbag/ChaosBagApi") local deckImporterApi = require("arkhamdb/DeckImporterApi") +local guidReferenceApi = require("core/GUIDReferenceApi") local optionPanelApi = require("core/OptionPanelApi") local playAreaApi = require("core/PlayAreaApi") local playmatApi = require("playermat/PlaymatApi") -local guidHandler = getObjectFromGUID("123456") - local campaignTokenData = { Name = "Custom_Model", Transform = { @@ -165,7 +164,7 @@ function createCampaignFromToken(importData) Wait.time(function() optionPanelApi.loadSettings(importData["options"]) end, 0.5) -- destroy Tour Starter token - local tourStarter = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "TourStarter" }) + local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter") tourStarter.destruct() -- restore PlayArea image diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index c1d66f5b..8fef10e5 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -3,14 +3,13 @@ - puts everything on playmats and hands into respective trashcans - use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore")]] -local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") -local chaosBagApi = require("chaosbag/ChaosBagApi") -local playAreaApi = require("core/PlayAreaApi") -local playmatApi = require("playermat/PlaymatApi") -local soundCubeApi = require("core/SoundCubeApi") -local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") - -local guidHandler = getObjectFromGUID("123456") +local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") +local chaosBagApi = require("chaosbag/ChaosBagApi") +local guidReferenceApi = require("core/GUIDReferenceApi") +local playAreaApi = require("core/PlayAreaApi") +local playmatApi = require("playermat/PlaymatApi") +local soundCubeApi = require("core/SoundCubeApi") +local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") -- objects with this tag will be ignored local IGNORE_TAG = "CleanUpHelper_ignore" @@ -146,7 +145,7 @@ end -- reset doom on agenda function resetDoomCounter() - local doomCounter = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DoomCounter" }) + local doomCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomCounter") if doomCounter ~= nil then doomCounter.call("updateVal") else @@ -231,7 +230,7 @@ end function discardHands() if not options["tidyPlayermats"] then return end for i = 1, 4 do - local trash = guidHandler.call("getObjectByOwnerAndType", { owner = COLORS[i], type = "Trash" }) + local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash") if trash == nil then return end local hand = Player[playmatApi.getPlayerColor(COLORS[i])].getHandObjects() for j = #hand, 1, -1 do @@ -242,8 +241,8 @@ end -- clean up for play area function tidyPlayareaCoroutine() - local trash = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "Trash" }) - local playAreaZone = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "PlayAreaZone" }) + local trash = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") + local playAreaZone = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone") if playAreaZone == nil then printToAll("Scripting zone for main play area could not be found!", "Red") @@ -273,7 +272,7 @@ function tidyPlayerMatCoroutine() for k = 1, 30 do coroutine.yield(0) end -- get respective trash - local trash = guidHandler.call("getObjectByOwnerAndType", { owner = COLORS[i], type = "Trash" }) + local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash") if trash == nil then printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red") return 1 @@ -303,7 +302,7 @@ function tidyPlayerMatCoroutine() -- reset "activeInvestigatorId" if i < 5 then - local playermat = guidHandler.call("getObjectByOwnerAndType", { owner = COLORS[i], type = "Playermat" }) + local playermat = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Playermat") if playermat then playermat.setVar("activeInvestigatorId", "00000") end @@ -311,7 +310,7 @@ function tidyPlayerMatCoroutine() end end - local datahelper = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DataHelper" }) + local datahelper = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper") if datahelper then datahelper.setTable("SPAWNED_PLAYER_CARD_GUIDS", {}) end diff --git a/src/accessories/TokenArrangerApi.ttslua b/src/accessories/TokenArrangerApi.ttslua index 846c0648..75d44839 100644 --- a/src/accessories/TokenArrangerApi.ttslua +++ b/src/accessories/TokenArrangerApi.ttslua @@ -1,12 +1,12 @@ do local TokenArrangerApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") -- local function to call the token arranger, if it is on the table ---@param functionName String Name of the function to cal ---@param argument Variant Parameter to pass local function callIfExistent(functionName, argument) - local guidHandler = getObjectFromGUID("123456") - local tokenArranger = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "TokenArranger" }) + local tokenArranger = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TokenArranger") if tokenArranger ~= nil then tokenArranger.call(functionName, argument) end diff --git a/src/arkhamdb/DeckImporterApi.ttslua b/src/arkhamdb/DeckImporterApi.ttslua index 221a5f5d..8628b6c4 100644 --- a/src/arkhamdb/DeckImporterApi.ttslua +++ b/src/arkhamdb/DeckImporterApi.ttslua @@ -1,10 +1,9 @@ do local DeckImporterApi = {} - + local guidReferenceApi = require("core/GUIDReferenceApi") local function getDeckImporter() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DeckImporter" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "DeckImporter") end -- Returns a table with the full state of the UI, including options and deck IDs. diff --git a/src/chaosbag/BlessCurseManagerApi.ttslua b/src/chaosbag/BlessCurseManagerApi.ttslua index d0cd5b9c..7612eae5 100644 --- a/src/chaosbag/BlessCurseManagerApi.ttslua +++ b/src/chaosbag/BlessCurseManagerApi.ttslua @@ -1,9 +1,9 @@ do local BlessCurseManagerApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getManager() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "BlessCurseManager" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "BlessCurseManager") end -- removes all taken tokens and resets the counts diff --git a/src/core/DoomCounter.ttslua b/src/core/DoomCounter.ttslua index f39ad72d..ae649189 100644 --- a/src/core/DoomCounter.ttslua +++ b/src/core/DoomCounter.ttslua @@ -1,10 +1,11 @@ +local guidReferenceApi = require("core/GUIDReferenceApi") + local optionsVisible = false local options = { Agenda = true, Playarea = true, Playermats = true } -local guidHandler = getObjectFromGUID("123456") val = 0 @@ -65,9 +66,9 @@ function startReset() if options.Agenda then updateVal(0) end - local DoomInPlayCounter = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DoomInPlayCounter" }) - if DoomInPlayCounter then - DoomInPlayCounter.call("removeDoom", options) + local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter") + if doomInPlayCounter then + doomInPlayCounter.call("removeDoom", options) end end diff --git a/src/core/DoomInPlayCounter.ttslua b/src/core/DoomInPlayCounter.ttslua index cb851055..b844939a 100644 --- a/src/core/DoomInPlayCounter.ttslua +++ b/src/core/DoomInPlayCounter.ttslua @@ -1,7 +1,6 @@ +local guidReferenceApi = require("core/GUIDReferenceApi") local playmatApi = require("playermat/PlaymatApi") -local guidHandler = getObjectFromGUID("123456") - local ZONE, TRASH, loopID local doomURL = "https://i.imgur.com/EoL7yaZ.png" local IGNORE_TAG = "DoomCounter_ignore" @@ -31,8 +30,8 @@ function onLoad() color = { 0, 0, 0, 0 } }) - TRASH = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "Trash" }) - ZONE = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "PlayAreaZone" }) + TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") + ZONE = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone") loopID = Wait.time(countDoom, 2, -1) end diff --git a/src/core/GUIDReferenceApi.ttslua b/src/core/GUIDReferenceApi.ttslua new file mode 100644 index 00000000..3728eb09 --- /dev/null +++ b/src/core/GUIDReferenceApi.ttslua @@ -0,0 +1,28 @@ +do + local GUIDReferenceApi = {} + + local function getGuidHandler() + return getObjectFromGUID("123456") + end + + -- returns all matching objects as a table with references + ---@param owner String Parent object for this search + ---@param type String Type of object to search for + GUIDReferenceApi.getObjectByOwnerAndType = function(owner, type) + return getGuidHandler().call("getObjectByOwnerAndType", { owner = owner, type = type }) + end + + -- returns all matching objects as a table with references + ---@param type String Type of object to search for + GUIDReferenceApi.getObjectsByType = function(type) + return getGuidHandler().call("getObjectsByType", type) + end + + -- returns all matching objects as a table with references + ---@param owner String Parent object for this search + GUIDReferenceApi.getObjectsByOwner = function(owner) + return getGuidHandler().call("getObjectsByOwner", owner) + end + + return GUIDReferenceApi +end diff --git a/src/core/GUIDReferenceHandler.ttslua b/src/core/GUIDReferenceHandler.ttslua index c125f5d1..b770c057 100644 --- a/src/core/GUIDReferenceHandler.ttslua +++ b/src/core/GUIDReferenceHandler.ttslua @@ -71,9 +71,9 @@ local GuidReferences = { } } -function getObjectByOwnerAndType(param) - local owner = param.owner - local type = param.type +function getObjectByOwnerAndType(params) + local owner = params.owner or "Mythos" + local type = params.type return getObjectFromGUID(GuidReferences[owner][type]) end diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index b1427e37..5fb80afd 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -1,10 +1,9 @@ local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") +local guidReferenceApi = require("core/GUIDReferenceApi") local optionPanelApi = require("core/OptionPanelApi") local playmatApi = require("playermat/PlaymatApi") local victoryDisplayApi = require("core/VictoryDisplayApi") -local guidHandler = getObjectFromGUID("123456") - function onLoad() addHotkey("Add Doom to Agenda", addDoomToAgenda) addHotkey("Bless/Curse Status", showBlessCurseStatus) @@ -43,7 +42,7 @@ end -- adds 1 doom to the agenda function addDoomToAgenda() - local doomCounter = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DoomCounter" }) + local doomCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomCounter") doomCounter.call("addVal", 1) end diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index bb2ba922..5add6fe7 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -1,4 +1,5 @@ local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") +local guidReferenceApi = require("core/GUIDReferenceApi") local mythosAreaApi = require("core/MythosAreaApi") local navigationOverlayApi = require("core/NavigationOverlayApi") local playAreaApi = require("core/PlayAreaApi") @@ -135,8 +136,7 @@ function onLoad(savedData) if obj ~= nil then obj.interactable = false end end - guidHandler = getObjectFromGUID("123456") - DATA_HELPER = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DataHelper" }) + DATA_HELPER = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper") resetChaosTokenStatTracker() getModVersion() math.randomseed(os.time()) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 12100390..fada0072 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -1,10 +1,9 @@ +local guidReferenceApi = require("core/GUIDReferenceApi") local playAreaApi = require("core/PlayAreaApi") local tokenArrangerApi = require("accessories/TokenArrangerApi") local tokenChecker = require("core/token/TokenChecker") local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") -local guidHandler = getObjectFromGUID("123456") - local ENCOUNTER_DECK_AREA = { upperLeft = { x = 0.9, z = 0.42 }, lowerRight = { x = 0.86, z = 0.38 }, @@ -35,8 +34,8 @@ function onLoad(saveState) useFrontData = loadedState.useFrontData or true tokenData = loadedState.tokenData or {} end - TRASH = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "Trash" }) - DATA_HELPER = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DataHelper" }) + TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") + DATA_HELPER = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper") collisionEnabled = true end diff --git a/src/core/MythosAreaApi.ttslua b/src/core/MythosAreaApi.ttslua index e9908ab7..08caeb1d 100644 --- a/src/core/MythosAreaApi.ttslua +++ b/src/core/MythosAreaApi.ttslua @@ -1,9 +1,9 @@ do local MythosAreaApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getMythosArea() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "MythosArea" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "MythosArea") end -- returns the chaos token metadata (if provided through scenario reference card) diff --git a/src/core/NavigationOverlayApi.ttslua b/src/core/NavigationOverlayApi.ttslua index e1249730..a39b0879 100644 --- a/src/core/NavigationOverlayApi.ttslua +++ b/src/core/NavigationOverlayApi.ttslua @@ -1,9 +1,9 @@ do local NavigationOverlayApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getNOHandler() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "NavigationOverlayHandler" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "NavigationOverlayHandler") end -- Copies the visibility for the Navigation overlay diff --git a/src/core/PlayArea.ttslua b/src/core/PlayArea.ttslua index 9a284a59..453de993 100644 --- a/src/core/PlayArea.ttslua +++ b/src/core/PlayArea.ttslua @@ -44,6 +44,7 @@ local LOC_LINK_EXCLUDE_SCENARIOS = { ["The Heart of Madness"] = true } +local guidReferenceApi = require("core/GUIDReferenceApi") local tokenManager = require("core/token/TokenManager") local clueData = {} @@ -513,8 +514,7 @@ function shiftContentsRight(playerColor) end function shiftContents(playerColor, direction) - local guidHandler = getObjectFromGUID("123456") - local zone = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "PlayAreaZone" }) + local zone = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone") if not zone then broadcastToColor("Scripting zone couldn't be found.", playerColor, "Red") return diff --git a/src/core/PlayAreaApi.ttslua b/src/core/PlayAreaApi.ttslua index e903e2c8..f1281b40 100644 --- a/src/core/PlayAreaApi.ttslua +++ b/src/core/PlayAreaApi.ttslua @@ -1,14 +1,13 @@ do local PlayAreaApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getPlayArea() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "PlayArea" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayArea") end local function getInvestigatorCounter() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "InvestigatorCounter" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "InvestigatorCounter") end -- Returns the current value of the investigator counter from the playmat diff --git a/src/core/SoundCubeApi.ttslua b/src/core/SoundCubeApi.ttslua index 36db9085..8aec117b 100644 --- a/src/core/SoundCubeApi.ttslua +++ b/src/core/SoundCubeApi.ttslua @@ -1,5 +1,6 @@ do local SoundCubeApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") -- this table links the name of a trigger effect to its index local soundIndices = { @@ -9,8 +10,7 @@ do } local function playTriggerEffect(index) - local guidHandler = getObjectFromGUID("123456") - local SoundCube = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "SoundCube" }) + local SoundCube = guidReferenceApi.getObjectByOwnerAndType("Mythos", "SoundCube") SoundCube.AssetBundle.playTriggerEffect(index) end diff --git a/src/core/VictoryDisplay.ttslua b/src/core/VictoryDisplay.ttslua index 3226cbbc..c4c95a0e 100644 --- a/src/core/VictoryDisplay.ttslua +++ b/src/core/VictoryDisplay.ttslua @@ -1,4 +1,5 @@ local chaosBagApi = require("chaosbag/ChaosBagApi") +local guidReferenceApi = require("core/GUIDReferenceApi") local playAreaApi = require("core/PlayAreaApi") local tokenChecker = require("core/token/TokenChecker") @@ -10,8 +11,6 @@ local countedVP = {} local highlightMissing = false local highlightCounted = false -local guidHandler = getObjectFromGUID("123456") - -- button creation when loading the game function onLoad() -- index 0: VP - "Display" @@ -250,7 +249,7 @@ end -- places the provided card in the first empty spot function placeCard(card) - local TRASH = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "Trash" }) + local trash = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") -- check snap point states local snaps = self.getSnapPoints() @@ -281,7 +280,7 @@ function placeCard(card) local chaosBag = chaosBagApi.findChaosBag() chaosBag.putObject(obj) elseif obj.memo ~= nil and obj.getLock() == false then - TRASH.putObject(obj) + trash.putObject(obj) end end @@ -325,13 +324,3 @@ function checkSnapPointState(pos) origin = pos }) 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 diff --git a/src/core/VictoryDisplayApi.ttslua b/src/core/VictoryDisplayApi.ttslua index 32ee9878..ae057130 100644 --- a/src/core/VictoryDisplayApi.ttslua +++ b/src/core/VictoryDisplayApi.ttslua @@ -1,9 +1,9 @@ do local VictoryDisplayApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getVictoryDisplay() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "VictoryDisplay" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "VictoryDisplay") end -- triggers an update of the Victory count diff --git a/src/core/token/TokenManager.ttslua b/src/core/token/TokenManager.ttslua index 297c7061..adcfae82 100644 --- a/src/core/token/TokenManager.ttslua +++ b/src/core/token/TokenManager.ttslua @@ -1,4 +1,5 @@ do + local guidReferenceApi = require("core/GUIDReferenceApi") local optionPanelApi = require("core/OptionPanelApi") local playAreaApi = require("core/PlayAreaApi") local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") @@ -335,9 +336,8 @@ do if tokenTemplates ~= nil then return end - tokenTemplates = { } - local guidHandler = getObjectFromGUID("123456") - local tokenSource = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "TokenSource" }) + tokenTemplates = {} + local tokenSource = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TokenSource") for _, tokenTemplate in ipairs(tokenSource.getData().ContainedObjects) do local tokenName = tokenTemplate.Memo tokenTemplates[tokenName] = tokenTemplate @@ -349,8 +349,7 @@ do if playerCardData ~= nil then return end - local guidHandler = getObjectFromGUID("123456") - local dataHelper = guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "DataHelper" }) + local dataHelper = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper") playerCardData = dataHelper.getTable('PLAYER_CARD_DATA') locationData = dataHelper.getTable('LOCATIONS_DATA') end diff --git a/src/core/token/TokenSpawnTracker.ttslua b/src/core/token/TokenSpawnTracker.ttslua index 6c9fc9eb..02aaf415 100644 --- a/src/core/token/TokenSpawnTracker.ttslua +++ b/src/core/token/TokenSpawnTracker.ttslua @@ -53,19 +53,7 @@ end -- Listener to reset card token spawns when they enter a hand. function onObjectEnterZone(zone, enterObject) - if checkMemo(zone) then + if zone.type == "Hand" and enterObject.type == "Card" then resetTokensSpawned(enterObject.getGUID()) end end - --- checks if the object is owned by a playermat -function checkMemo(obj) - local memo = obj.getMemo() - if memo then - local decoded = JSON.decode(memo) or {} - if decoded.matColor ~= "Mythos" then - return true - end - end - return false -end diff --git a/src/core/token/TokenSpawnTrackerApi.ttslua b/src/core/token/TokenSpawnTrackerApi.ttslua index e82f3057..1ba4c261 100644 --- a/src/core/token/TokenSpawnTrackerApi.ttslua +++ b/src/core/token/TokenSpawnTrackerApi.ttslua @@ -1,9 +1,9 @@ do local TokenSpawnTracker = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getSpawnTracker() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "TokenSpawnTracker" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "TokenSpawnTracker") end TokenSpawnTracker.hasSpawnedTokens = function(cardGuid) diff --git a/src/core/tour/TourManager.ttslua b/src/core/tour/TourManager.ttslua index 2b0ec255..c27939ee 100644 --- a/src/core/tour/TourManager.ttslua +++ b/src/core/tour/TourManager.ttslua @@ -1,8 +1,9 @@ do require("core/tour/TourScript") require("core/tour/TourCard") - local TourManager = { } - local internal = { } + local TourManager = {} + local internal = {} + local guidReferenceApi = require("core/GUIDReferenceApi") -- Base IDs for various tour card UI elements. Actual IDs will have _[playerColor] appended local CARD_ID = "tourCard" @@ -123,9 +124,9 @@ do delay = delay + 0.5 end local lookPos - if TOUR_SCRIPT[cardIndex].objReferenceData ~= nil then - local guidHandler = getObjectFromGUID("123456") - local lookAtObj = guidHandler.call("getObjectByOwnerAndType", TOUR_SCRIPT[cardIndex].objReferenceData) + local objReferenceData = TOUR_SCRIPT[cardIndex].objReferenceData + if objReferenceData ~= nil then + local lookAtObj = guidReferenceApi.getObjectByOwnerAndType(objReferenceData.owner, objReferenceData.type) lookPos = lookAtObj.getPosition() lookPos.y = TOUR_SCRIPT[cardIndex].distanceFromObj or 0 -- Since camera isn't directly above the hook, changing the Y affects the visual position of diff --git a/src/playercards/AllCardsBagApi.ttslua b/src/playercards/AllCardsBagApi.ttslua index 6178c6f1..83cf6463 100644 --- a/src/playercards/AllCardsBagApi.ttslua +++ b/src/playercards/AllCardsBagApi.ttslua @@ -1,9 +1,9 @@ do local AllCardsBagApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") local function getAllCardsBag() - local guidHandler = getObjectFromGUID("123456") - return guidHandler.call("getObjectByOwnerAndType", { owner = "Mythos", type = "AllCardsBag" }) + return guidReferenceApi.getObjectByOwnerAndType("Mythos", "AllCardsBag") end -- Returns a specific card from the bag, based on ArkhamDB ID diff --git a/src/playermat/ClueCounter.ttslua b/src/playermat/ClueCounter.ttslua index 251fb070..cce78085 100644 --- a/src/playermat/ClueCounter.ttslua +++ b/src/playermat/ClueCounter.ttslua @@ -26,16 +26,15 @@ end -- Activated once per second, counts items in bowls function countItems() local totalValue = 0 - local countableItems = findValidItemsInSphere() - for _, entry in ipairs(countableItems) do - local descValue = tonumber(entry.hit_object.getDescription()) - local stackMult = math.abs(entry.hit_object.getQuantity()) + for _, item in ipairs(findValidItemsInSphere()) do + local descValue = tonumber(item.getDescription()) + local stackMult = math.abs(item.getQuantity()) -- Use value in description if available if descValue ~= nil then totalValue = totalValue + descValue * stackMult else -- Otherwise use the value in validCountItemList - totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult + totalValue = totalValue + validCountItemList[item.getName()] * stackMult end end exposedValue = totalValue @@ -51,18 +50,15 @@ function findValidItemsInSphere() size = { 2, 2, 2 } }) - retval = {} + local validItemList = {} for _, entry in ipairs(items) do - --Ignore the bowl if entry.hit_object ~= self then - --Ignore if not in validCountItemList - local tableEntry = validCountItemList[entry.hit_object.getName()] - if tableEntry ~= nil then - table.insert(retval, entry) + if validCountItemList[entry.hit_object.getName()] ~= nil then + table.insert(validItemList, entry.hit_object) end end end - return retval + return validItemList end function removeAllClues(trash) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 0159b886..3ddefdfb 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -1,11 +1,10 @@ local chaosBagApi = require("chaosbag/ChaosBagApi") +local guidReferenceApi = require("core/GUIDReferenceApi") local mythosAreaApi = require("core/MythosAreaApi") local navigationOverlayApi = require("core/NavigationOverlayApi") local tokenChecker = require("core/token/TokenChecker") local tokenManager = require("core/token/TokenManager") -local guidHandler = getObjectFromGUID("123456") - -- set true to enable debug logging and show Physics.cast() local DEBUG = false @@ -105,7 +104,7 @@ function onLoad(saveState) self.interactable = DEBUG -- get object references to owned objects - ownedObjects = guidHandler.call("getObjectsByOwner", matColor) + ownedObjects = guidReferenceApi.getObjectsByOwner(matColor) -- button creation for i = 1, 6 do diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 6fb11f28..a051cfe6 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -1,15 +1,15 @@ do local PlaymatApi = {} + local guidReferenceApi = require("core/GUIDReferenceApi") -- Convenience function to look up a mat's object by color, or get all mats. ---@param matColor String Color of the playmat - White, Orange, Green, Red or All ---@return array Table Single-element if only single playmat is requested local function getMatForColor(matColor) - local guidHandler = getObjectFromGUID("123456") if matColor == "All" then - return guidHandler.call("getObjectsByType", "Playermat") + return guidReferenceApi.getObjectsByType("Playermat") else - return { matColor = guidHandler.call("getObjectByOwnerAndType", { owner = matColor, type = "Playermat" }) } + return { matColor = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") } end end