Files
OpenSpace/data/assets/examples/statemachine.asset
T
2021-08-17 08:33:00 +02:00

73 lines
1.8 KiB
Lua

-- Create a state machine with a few different states. The state machine can be controlled through
-- the scripting commands from the state machine module.
local targetNode = function(nodeIdentifier)
return [[
openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil)
openspace.setPropertyValueSingle(
"NavigationHandler.OrbitalNavigator.Anchor",
']] .. nodeIdentifier .. [['
)
openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", '')
]]
end
local states = {
{
Identifier = "Constellations",
Enter = [[
openspace.setPropertyValueSingle('Scene.Constellations.Renderable.Opacity', 1.0, 1.0)
]],
Exit = [[
openspace.setPropertyValueSingle('Scene.Constellations.Renderable.Opacity', 0.0, 1.0)
]]
},
{
Identifier = "Earth",
Enter = "openspace.setPropertyValueSingle('Scene.EarthLabel.Renderable.Enabled', true)",
Exit = "openspace.setPropertyValueSingle('Scene.EarthLabel.Renderable.Enabled', false)"
},
{
Identifier = "Moon"
}
}
local transitions = {
{
From = "Earth",
To = "Moon",
Action = targetNode("Moon")
},
{
From = "Moon",
To = "Earth",
Action = targetNode("Earth")
},
{
From = "Earth",
To = "Constellations",
},
{
From = "Constellations",
To = "Earth"
},
{
From = "Moon",
To = "Constellations",
Action = targetNode("Earth")
},
{
From = "Constellations",
To = "Moon",
Action = targetNode("Moon")
}
}
asset.onInitialize(function()
-- Setup (could be done in the profile)
openspace.setPropertyValueSingle('Scene.Constellations.Renderable.Enabled', true)
openspace.setPropertyValueSingle('Scene.Constellations.Renderable.Opacity', 0.0)
openspace.statemachine.createStateMachine(states, transitions, "Earth")
end)