io: use default attribs rather than a hard-coded number for globals identification
gui/tutorial/aircraft: use io.read_properties()/io.write_properties()
This commit is contained in:
parent
ee44cdf0db
commit
3be5c6956b
4 changed files with 15 additions and 27 deletions
|
@ -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-dir> [, <interval:10> [, <func>]]);
|
||||
# livery_update.new(<livery-dir> [, <interval:10> [, <func>]]);
|
||||
#
|
||||
# <livery-dir> ... directory with livery files, relative to $FG_ROOT
|
||||
# <interval> ... 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)
|
||||
|
|
|
@ -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)
|
||||
|
|
14
Nasal/io.nas
14
Nasal/io.nas
|
@ -87,11 +87,10 @@ var read_properties = func(path, target = nil) {
|
|||
|
||||
# Write XML file in FlightGear's native <PropertyList> 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(<filename>, <props.Node or property-path>);
|
||||
#
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 ~ "]/");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue