45a5870121
A card can collide with the area more than once; many of the campaign memory bags caused a double collision on placement, and it would happen if the user picked up or flipped the card. This would cause any behavior that triggered from the event to each time, so suppress further events which don't actually change the scenario.
34 lines
862 B
Plaintext
34 lines
862 B
Plaintext
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
|