diff --git a/Nasal/aircraft.nas b/Nasal/aircraft.nas index 367c7b8b6..010c11354 100644 --- a/Nasal/aircraft.nas +++ b/Nasal/aircraft.nas @@ -432,15 +432,14 @@ var data = { size(me.catalog) or return; printlog("debug", "saving aircraft data to ", me.path); me.signalN.setBoolValue(1); - var args = props.Node.new({ "filename": me.path }); - var data = args.getNode("data", 1); + var data = props.Node.new(); foreach (var c; me.catalog) { if (c[0] == `/`) c = substr(c, 1); props.copy(props.globals.getNode(c, 1), data.getNode(c, 1)); } - fgcommand("savexml", args); + io.write_properties(me.path, data); }, add : func(p...) { foreach (var n; props.nodeList(p)) @@ -574,10 +573,7 @@ var livery = { foreach (var file; directory(path)) { if (substr(file, -4) != ".xml") continue; - var n = props.Node.new({ filename : path ~ file }); - fgcommand("loadxml", n); - n = n.getNode("data"); - + var n = io.read_properties(path ~ file); var name = n.getNode(me.name_path); var index = n.getNode(me.sort_path); if (name == nil or index == nil) @@ -624,7 +620,7 @@ var livery = { # in the remote aircraft accordingly. # # SYNOPSIS: -# livery_update( [, [, ]]); +# livery_update.new( [, [, ]]); # # ... directory with livery files, relative to $FG_ROOT # ... checking interval in seconds (default: 10) @@ -667,8 +663,7 @@ var livery_update = { me.running or return; var file = me.fileN.getValue(); if (file != nil and file != me.last) { - fgcommand("loadxml", props.Node.new({ filename: me.dir ~ file ~ ".xml", - targetnode: me.root })); + io.read_properties(me.dir ~ file ~ ".xml", me.root); me.last = file; if (me.callback != nil) me.callback(file); @@ -721,10 +716,7 @@ var formation = { foreach (var file; directory(path)) { if (substr(file, -4) != ".xml") continue; - var n = props.Node.new({ filename : path ~ file }); - fgcommand("loadxml", n); - n = n.getNode("data"); - + var n = io.read_properties(path ~ file); var name = n.getNode(me.name_path); var index = n.getNode(me.sort_path); if (name == nil or index == nil) diff --git a/Nasal/gui.nas b/Nasal/gui.nas index ab12e05c3..3cb08aa6a 100644 --- a/Nasal/gui.nas +++ b/Nasal/gui.nas @@ -225,8 +225,7 @@ var Dialog = { me.close(); me.prop.removeChildren(); - fgcommand("loadxml", props.Node.new({"filename": getprop("/sim/fg-root") ~ "/" ~ me.path, - "targetnode": me.prop.getPath()})); + io.read_properties(getprop("/sim/fg-root") ~ "/" ~ me.path, me.prop); var n = me.prop.getNode("name"); if (n == nil) diff --git a/Nasal/io.nas b/Nasal/io.nas index f9f9719bb..6665b7c1d 100644 --- a/Nasal/io.nas +++ b/Nasal/io.nas @@ -87,11 +87,10 @@ var read_properties = func(path, target = nil) { # Write XML file in FlightGear's native format. # Returns the filename on success or nil on error. If the source -# is a props.Node, then a unique node attribute number is used to -# determine whether the tree is a subtree of the global tree, in -# which case the branch is writen directly from that tree, as this -# yields a more accurate result. (The attributes are "readable" -# + "writable" + the lowest unused bit.) +# is a props.Node that refers to a node in the main tree, then +# the data are directly written from the tree, yielding a more +# accurate result. Otherwise the data need to be copied first, +# which may slightly change node types (FLOAT becomes DOUBLE etc.) # # Usage: io.write_properties(, ); # @@ -102,9 +101,10 @@ var read_properties = func(path, target = nil) { # io.write_properties("/tmp/foo.xml", "/sim/model"); # var write_properties = func(path, prop) { - var attr = props.globals.getAttribute("last") * 2 + 3; - props.globals.setAttribute(attr); var args = props.Node.new({ filename: path }); + # default attributes of a new node plus the lowest unused bit + var attr = args.getAttribute() + args.getAttribute("last") * 2; + props.globals.setAttribute(attr); if(isa(prop, props.Node)) { for(var root = prop; (var p = root.getParent()) != nil;) root = p; diff --git a/Nasal/tutorial.nas b/Nasal/tutorial.nas index 5d89e0b8f..a2eb99f61 100644 --- a/Nasal/tutorial.nas +++ b/Nasal/tutorial.nas @@ -468,10 +468,7 @@ var dialog = func { # var load = func(file, index = 0) { props.globals.getNode("/sim/tutorials", 1).removeChild("tutorial", index); - fgcommand("loadxml", props.Node.new({ - "filename": getprop("/sim/fg-root") ~ "/" ~ file, - "targetnode": "/sim/tutorials/tutorial[" ~ index ~ "]/", - })); + io.read_properties(getprop("/sim/fg-root") ~ "/" ~ file, "/sim/tutorials/tutorial[" ~ index ~ "]/"); }