local tokenManager = require("core/token/TokenManager") --------------------------------------------------------- -- general setup --------------------------------------------------------- -- set true to enable debug logging DEBUG = false -- we use this to turn off collision handling until onLoad() is complete COLLISION_ENABLED = false local SHIFT_OFFSETS = { left = { x = 0.00, y = 0, z = 7.67 }, right = { x = 0.00, y = 0, z = -7.67 }, up = { x = 6.54, y = 0, z = 0.00 }, down = { x = -6.54, y = 0, z = 0.00 } } local SHIFT_EXCLUSION = { ["b7b45b"] = true, ["f182ee"] = true, ["721ba2"] = true } local INVESTIGATOR_COUNTER_GUID = "f182ee" local PLAY_AREA_ZONE_GUID = "a2f932" local currentScenario --------------------------------------------------------- -- general code --------------------------------------------------------- function onSave() return JSON.encode({ currentScenario = currentScenario }) end function onLoad(saveState) -- records locations we have spawned clues for local saveData = JSON.decode(saveState) or {} currentScenario = saveData.currentScenario self.interactable = DEBUG Wait.time(function() COLLISION_ENABLED = true end, 1) end function log(message) if DEBUG then print(message) end end -- Called by Custom Data Helpers to push their location data into the Data Helper. This adds the -- data to the local token manager instance. ---@param args Table Single-value array holding the GUID of the Custom Data Helper making the call function updateLocations(args) local customDataHelper = getObjectFromGUID(args[1]) if customDataHelper ~= nil then tokenManager.addLocationData(customDataHelper.getTable("LOCATIONS_DATA")) end end function onCollisionEnter(collision_info) if not COLLISION_ENABLED then return end -- check if we should spawn clues here and do so according to playercount local card = collision_info.collision_object if shouldSpawnTokens(card) then tokenManager.spawnForCard(card) end end function shouldSpawnTokens(card) local metadata = JSON.decode(card.getGMNotes()) if metadata == nil then return tokenManager.hasLocationData(card) ~= nil end return metadata.type == "Location" or metadata.type == "Enemy" or metadata.type == "Treachery" or metadata.weakness end -- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain -- fixed objects will be ignored, as will anything the player has tagged with -- 'displacement_excluded' ---@param playerColor Color of the player requesting the shift. Used solely to send an error --- message in the unlikely case that the scripting zone has been deleted function shiftContentsUp(playerColor) shiftContents(playerColor, "up") end function shiftContentsDown(playerColor) shiftContents(playerColor, "down") end function shiftContentsLeft(playerColor) shiftContents(playerColor, "left") end function shiftContentsRight(playerColor) shiftContents(playerColor, "right") end function shiftContents(playerColor, direction) local zone = getObjectFromGUID(PLAY_AREA_ZONE_GUID) if not zone then broadcastToColor("Scripting zone couldn't be found.", playerColor, "Red") return end for _, object in ipairs(zone.getObjects()) do if not (SHIFT_EXCLUSION[object.getGUID()] or object.hasTag("displacement_excluded")) then object.translate(SHIFT_OFFSETS[direction]) end end end -- Returns the current value of the investigator counter from the playmat ---@return Integer. Number of investigators currently set on the counter function getInvestigatorCount() local investigatorCounter = getObjectFromGUID("f182ee") return investigatorCounter.getVar("val") end -- Reset the play area's tracking of which cards have had tokens spawned. function resetSpawnedCards() spawnedLocationGUIDs = {} end function onScenarioChanged(scenarioName) currentScenario = scenarioName Global.call('titleSplash', {scenarioName = scenarioName}) end