Files
OpenSpace/data/assets/examples/statemachine.asset
Emil Axelsson c2cc2bab17 Feature/state machine (#673)
* Implement simple state machine example in Lua
* Use defaults for trail widths
2018-07-13 10:29:45 -04:00

49 lines
1.3 KiB
Plaintext

local stateMachineHelper = asset.require('util/state_machine_helper')
states = {
{
Title = "Highlight EarthTrail",
Play = function ()
openspace.setPropertyValue("Scene.EarthTrail.renderable.LineWidth", 10, 1)
end,
Rewind = function ()
openspace.setPropertyValue("Scene.EarthTrail.renderable.LineWidth", 2, 1)
end
},
{
Title = "Highlight MarsTrail",
Play = function ()
openspace.setPropertyValue("Scene.EarthTrail.renderable.LineWidth", 2, 1)
openspace.setPropertyValue("Scene.MarsTrail.renderable.LineWidth", 10, 1)
end,
Rewind = function ()
openspace.setPropertyValue("Scene.MarsTrail.renderable.LineWidth", 2, 1)
openspace.setPropertyValue("Scene.EarthTrail.renderable.LineWidth", 10, 1)
end
}
}
local stateMachine
function next()
stateMachine.goToNextState()
end
function previous()
stateMachine.goToPreviousState()
end
asset.onInitialize(function ()
stateMachine = stateMachineHelper.createStateMachine(states)
openspace.bindKey('RIGHT', 'next()')
openspace.bindKey('LEFT', 'previous()')
end)
asset.onDeinitialize(function ()
stateMachine = nil
openspace.clearKey('RIGHT')
openspace.clearKey('LEFT')
end)