Merge pull request #799 from argonui/mythos-area
Added better detection for scenario reference cards
This commit is contained in:
commit
a8a42ecf0e
@ -54,35 +54,50 @@ function onCollisionEnter(collisionInfo)
|
|||||||
-- early exit for better performance
|
-- early exit for better performance
|
||||||
if object.type ~= "Card" then return end
|
if object.type ~= "Card" then return end
|
||||||
|
|
||||||
|
-- reset spawned tokens and remove tokens from cards in encounter deck / discard area
|
||||||
|
local localPos = self.positionToLocal(object.getPosition())
|
||||||
|
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
|
||||||
|
Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
|
||||||
|
removeTokensFromObject(object)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get metadata
|
||||||
|
local md = JSON.decode(object.getGMNotes()) or {}
|
||||||
|
|
||||||
-- get scenario name and maybe fire followup event
|
-- get scenario name and maybe fire followup event
|
||||||
if object.getName() == "Scenario" then
|
local cardName = object.getName()
|
||||||
local description = object.getDescription()
|
if object.getName() == "Scenario" or md.type == "ScenarioReference" then
|
||||||
|
getDataFromReferenceCard(object, cardName, md)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- maybe load data from reference card
|
||||||
|
function getDataFromReferenceCard(card, cardName, md)
|
||||||
|
local newScenarioName
|
||||||
|
if cardName == "Scenario" then
|
||||||
|
newScenarioName = card.getDescription()
|
||||||
|
else
|
||||||
|
newScenarioName = cardName
|
||||||
|
end
|
||||||
|
|
||||||
-- detect if a new scenario card is placed down
|
-- detect if a new scenario card is placed down
|
||||||
if currentScenario ~= description then
|
if currentScenario ~= newScenarioName then
|
||||||
currentScenario = description
|
currentScenario = newScenarioName
|
||||||
fireScenarioChangedEvent()
|
fireScenarioChangedEvent()
|
||||||
end
|
end
|
||||||
|
|
||||||
local metadata = JSON.decode(object.getGMNotes()) or {}
|
if not md["tokens"] then
|
||||||
if not metadata["tokens"] then
|
|
||||||
tokenData = {}
|
tokenData = {}
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- detect orientation of scenario card (for difficulty)
|
-- detect orientation of scenario card (for difficulty)
|
||||||
useFrontData = not object.is_face_down
|
useFrontData = not card.is_face_down
|
||||||
tokenData = metadata["tokens"][(useFrontData and "front" or "back")]
|
tokenData = md["tokens"][(useFrontData and "front" or "back")]
|
||||||
fireTokenDataChangedEvent()
|
fireTokenDataChangedEvent()
|
||||||
end
|
end
|
||||||
|
|
||||||
local localPos = self.positionToLocal(object.getPosition())
|
|
||||||
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
|
|
||||||
Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
|
|
||||||
removeTokensFromObject(object)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TTS event handler. Handles scenario name event triggering
|
-- TTS event handler. Handles scenario name event triggering
|
||||||
function onCollisionExit(collisionInfo)
|
function onCollisionExit(collisionInfo)
|
||||||
local object = collisionInfo.collision_object
|
local object = collisionInfo.collision_object
|
||||||
|
Loading…
Reference in New Issue
Block a user