Merge pull request #294 from argonui/tokenarranger
Token-Arranger: removes check for new data to support scenario card flip
This commit is contained in:
commit
118adb2c83
@ -20,7 +20,6 @@ inputParameters.tab = 2
|
||||
|
||||
-- variables with save function
|
||||
local tokenPrecedence = {}
|
||||
local latestLoad = "XXX"
|
||||
local percentage = false
|
||||
|
||||
-- variables without save function
|
||||
@ -42,7 +41,6 @@ local TOKEN_NAMES = {
|
||||
function onSave()
|
||||
return JSON.encode({
|
||||
tokenPrecedence = tokenPrecedence,
|
||||
latestLoad = latestLoad,
|
||||
percentage = percentage
|
||||
})
|
||||
end
|
||||
@ -52,10 +50,12 @@ function onLoad(saveState)
|
||||
if saveState ~= nil and saveState ~= "" then
|
||||
local loadedData = JSON.decode(saveState)
|
||||
tokenPrecedence = loadedData.tokenPrecedence
|
||||
latestLoad = loadedData.latestLoad or "XXX"
|
||||
percentage = loadedData.percentage
|
||||
else
|
||||
loadDefaultValues()
|
||||
|
||||
-- grab token metadata from mythos area
|
||||
Wait.time(function() onTokenDataChanged(mythosAreaApi.returnTokenData()) end, 0.2)
|
||||
end
|
||||
|
||||
createButtonsAndInputs(true)
|
||||
@ -63,7 +63,6 @@ function onLoad(saveState)
|
||||
|
||||
-- context menu items
|
||||
self.addContextMenuItem("Load default values", function()
|
||||
latestLoad = "XXX"
|
||||
loadDefaultValues()
|
||||
updateUI()
|
||||
layout()
|
||||
@ -90,9 +89,6 @@ function onLoad(saveState)
|
||||
"Yellow")
|
||||
layout()
|
||||
end)
|
||||
|
||||
-- grab token metadata from mythos area
|
||||
Wait.time(function() onTokenDataChanged(mythosAreaApi.returnTokenData()) end, 0.2)
|
||||
end
|
||||
|
||||
-- delete temporary tokens when destroyed
|
||||
@ -383,11 +379,6 @@ function onTokenDataChanged(parameters)
|
||||
local currentScenario = parameters.currentScenario or ""
|
||||
local useFrontData = parameters.useFrontData
|
||||
|
||||
-- only update if this data is new
|
||||
local info = currentScenario .. tostring(useFrontData)
|
||||
if latestLoad == info then return end
|
||||
latestLoad = info
|
||||
|
||||
-- update token precedence
|
||||
for key, table in pairs(tokenData) do
|
||||
local modifier = table.modifier
|
||||
|
@ -43,37 +43,28 @@ end
|
||||
|
||||
-- TTS event handler. Handles scenario name event triggering and encounter card token resets.
|
||||
function onCollisionEnter(collisionInfo)
|
||||
if not collisionEnabled then
|
||||
return
|
||||
end
|
||||
if not collisionEnabled then return end
|
||||
local object = collisionInfo.collision_object
|
||||
|
||||
if object.getName() == "Scenario" then
|
||||
local updateNeeded = false
|
||||
local description = object.getDescription()
|
||||
|
||||
-- detect if orientation of scenario card changed (flipped to other side)
|
||||
if object.is_face_down == useFrontData then
|
||||
useFrontData = not useFrontData
|
||||
updateNeeded = true
|
||||
end
|
||||
|
||||
-- detect if another scenario card is placed down
|
||||
-- detect if a new scenario card is placed down
|
||||
if currentScenario ~= description then
|
||||
currentScenario = description
|
||||
updateNeeded = true
|
||||
fireScenarioChangedEvent()
|
||||
end
|
||||
|
||||
-- trigger update if a change was detected and push new data
|
||||
if updateNeeded then
|
||||
local metadata = JSON.decode(object.getGMNotes()) or {}
|
||||
if not metadata["tokens"] then
|
||||
tokenData = {}
|
||||
return
|
||||
end
|
||||
tokenData = metadata["tokens"][(useFrontData and "front" or "back")]
|
||||
fireTokenDataChangedEvent()
|
||||
local metadata = JSON.decode(object.getGMNotes()) or {}
|
||||
if not metadata["tokens"] then
|
||||
tokenData = {}
|
||||
return
|
||||
end
|
||||
|
||||
-- detect orientation of scenario card (for difficulty)
|
||||
useFrontData = not object.is_face_down
|
||||
tokenData = metadata["tokens"][(useFrontData and "front" or "back")]
|
||||
fireTokenDataChangedEvent()
|
||||
end
|
||||
|
||||
local localPos = self.positionToLocal(object.getPosition())
|
||||
|
Loading…
x
Reference in New Issue
Block a user