Add an event generator for scenario name changes

Based in the newly-named Mythos Area, when a Scenario card lands the name will be extracted and sent to interested objects.

Playarea will use this for special location handling, and there will be other cases in the future.
This commit is contained in:
Buhallin 2022-12-15 00:29:56 -08:00
parent f1bdf1f7a0
commit bf8f9bd12b
No known key found for this signature in database
GPG Key ID: DB3C362823852294
6 changed files with 61 additions and 10 deletions

View File

@ -39,7 +39,7 @@
"Custom_Assetbundle.9f95fd",
"Custom_Assetbundle.35b95f",
"Custom_Assetbundle.5af8f2",
"Custom_Tile.9f334f",
"AgendaArea.9f334f",
"Custom_Tile.91dd9b",
"Custom_Assetbundle.5706ae",
"Custom_Tile.6161b4",

View File

@ -58,18 +58,18 @@
"HideWhenFaceDown": false,
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": true,
"LuaScript": "",
"LuaScriptState": "",
"Locked": false,
"LuaScript": "require(\"core/MythosArea\")",
"LuaScriptState": "[]",
"MeasureMovement": false,
"Name": "Custom_Tile",
"Nickname": "",
"Nickname": "Mythos Area",
"Snap": true,
"Sticky": true,
"Tooltip": false,
"Transform": {
"posX": -1.309,
"posY": 1.483,
"posY": 1.477,
"posZ": 0.034,
"rotX": 0,
"rotY": 270,

View File

@ -34,7 +34,7 @@
"LayoutGroupSortIndex": 0,
"Locked": true,
"LuaScript": "require(\"core/PlayArea\")",
"LuaScriptState": "[]",
"LuaScriptState": "{\"spawnedLocs\":[]}",
"MeasureMovement": false,
"Name": "Custom_Token",
"Nickname": "Playarea",

View File

@ -0,0 +1,31 @@
local playAreaApi = require("core/PlayAreaApi")
local currentScenario
function onLoad(saveState)
if saveState ~= nil then
local loadedState = JSON.decode(saveState) or { }
currentScenario = loadedState.currentScenario
end
end
function onSave()
return JSON.encode({
currentScenario = currentScenario
})
end
-- TTS event handler. Checks for a scenrio card, extracts the scenario name from the description,
-- and fires it to the relevant listeners.
function onCollisionEnter(collisionInfo)
local object = collisionInfo.collision_object
if object.getName() == "Scenario" then
log("Collision: " .. object.getGUID())
currentScenario = object.getDescription()
fireScenarioChangedEvent()
end
end
function fireScenarioChangedEvent()
playAreaApi.onScenarioChanged(currentScenario)
end

View File

@ -25,16 +25,25 @@ local PLAY_AREA_ZONE_GUID = "a2f932"
local clueData = {}
spawnedLocationGUIDs = {}
local currentScenario
---------------------------------------------------------
-- general code
---------------------------------------------------------
function onSave() return JSON.encode(spawnedLocationGUIDs) end
function onSave()
-- return JSON.encode({})
return JSON.encode({
spawnedLocs = spawnedLocationGUIDs,
currentScenario = currentScenario
})
end
function onLoad(save_state)
function onLoad(saveState)
-- records locations we have spawned clues for
spawnedLocationGUIDs = JSON.decode(save_state) or {}
local saveData = JSON.decode(saveState) or {}
spawnedLocationGUIDs = saveData.spawnedLocs or { }
currentScenario = saveData.currentScenario
local TOKEN_DATA = Global.getTable('TOKEN_DATA')
clueData = {
@ -182,3 +191,7 @@ end
function resetSpawnedCards()
spawnedLocationGUIDs = {}
end
function onScenarioChanged(scenarioName)
currentScenario = scenarioName
end

View File

@ -35,5 +35,12 @@ do
return getObjectFromGUID(PLAY_AREA_GUID).call("resetSpawnedCards")
end
-- Event to be called when the current scenario has changed.
---@param scenarioName Name of the new scenario
PlayAreaApi.onScenarioChanged = function(scenarioName)
log("In API")
getObjectFromGUID(PLAY_AREA_GUID).call("onScenarioChanged", scenarioName)
end
return PlayAreaApi
end