Files
OpenSpace/data/assets/examples/statemachine.asset
2024-06-19 11:26:07 +02:00

84 lines
2.1 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 function targetNode(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)
asset.meta = {
Name = "State Machine",
Description = [[Example of how to create a state machine in OpenSpace, where each
state and transition between states may trigger different behaviors.]],
Author = "OpenSpace Team",
URL = "http://openspaceproject.com",
License = "MIT license"
}