From cf16f4de8854120301715e8890076664a835b7f2 Mon Sep 17 00:00:00 2001 From: mfranz Date: Tue, 20 Mar 2007 17:32:28 +0000 Subject: [PATCH] support definition in a tutorial file, so that tutorials can place static scenery objects, like air-racing pylons, etc. --- Nasal/tutorial.nas | 49 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/Nasal/tutorial.nas b/Nasal/tutorial.nas index ad23c7010..7b0f468cd 100644 --- a/Nasal/tutorial.nas +++ b/Nasal/tutorial.nas @@ -22,6 +22,16 @@ # # # +# +# - scenery object definition +# - path to model (relative to $FG_ROOT) +# +# +# +# +# +# - Optional: Initialization section consist of one or more # set nodes: # @@ -74,7 +84,7 @@ var startTutorial = func { tutorial = nil; foreach (var c; props.globals.getNode("/sim/tutorial").getChildren("tutorial")) { - if (c.getChild("name").getValue() == name) { + if (c.getNode("name").getValue() == name) { tutorial = c; break; } @@ -91,12 +101,13 @@ var startTutorial = func { num_step_runs = 0; num_errors = 0; - set_properties(tutorial.getChild("init")); + set_properties(tutorial.getNode("init")); set_cursor(tutorial); + set_models(tutorial.getNode("models")); init_nasal(); run_nasal(tutorial); - var dir = tutorial.getChild("audio-dir"); + var dir = tutorial.getNode("audio-dir"); if (dir != nil) { audio_dir = getprop("/sim/fg-root") ~ "/" ~ dir.getValue() ~ "/"; } else { @@ -134,6 +145,7 @@ var startTutorial = func { var stopTutorial = func { is_running(0); + remove_models(); set_cursor(props.Node.new()); } @@ -277,6 +289,37 @@ var set_properties = func(node) { +var models = []; +var set_models = func(node) { + remove_models(); + + node != nil or return; + var manager = props.globals.getNode("/models", 1); + foreach (var src; node.getChildren("model")) { + var i = 0; + while (i += 1) { + if (manager.getChild("model", i, 0) == nil) { + break; + } + } + var dest = manager.getChild("model", i, 1); + props.copy(src, dest); + dest.getNode("load", 1); # this make the modelmgr load the model + dest.removeChildren("load"); + append(models, dest); + } +} + + +var remove_models = func { + foreach (var m; models) { + m.getParent().removeChild(m.getName(), m.getIndex()); + } + models = []; +} + + + var set_cursor = func(node) { node != nil or return; var loc = node.getNode("marker");