Merge pull request #100 from argonui/scenario-event

Add an event generator for scenario name changes
This commit is contained in:
Buhallin 2022-12-15 20:33:34 -08:00 committed by GitHub
commit 1851e0addb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 8 deletions

View File

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

View File

@ -59,11 +59,11 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": true,
"LuaScript": "",
"LuaScriptState": "",
"LuaScript": "require(\"core/MythosArea\")",
"LuaScriptState": "[]",
"MeasureMovement": false,
"Name": "Custom_Tile",
"Nickname": "",
"Nickname": "Mythos Area",
"Snap": true,
"Sticky": true,
"Tooltip": false,

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,33 @@
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
if currentScenario ~= object.getDescription() then
currentScenario = object.getDescription()
fireScenarioChangedEvent()
end
end
end
function fireScenarioChangedEvent()
log("Firing")
playAreaApi.onScenarioChanged(currentScenario)
end

View File

@ -25,16 +25,24 @@ 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({
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 +190,7 @@ end
function resetSpawnedCards()
spawnedLocationGUIDs = {}
end
function onScenarioChanged(scenarioName)
currentScenario = scenarioName
end

View File

@ -35,5 +35,11 @@ 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)
getObjectFromGUID(PLAY_AREA_GUID).call("onScenarioChanged", scenarioName)
end
return PlayAreaApi
end