1
0
Fork 0

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:
mfranz 2008-07-11 09:37:33 +00:00
parent ee44cdf0db
commit 3be5c6956b
4 changed files with 15 additions and 27 deletions

View file

@ -432,15 +432,14 @@ var data = {
size(me.catalog) or return; size(me.catalog) or return;
printlog("debug", "saving aircraft data to ", me.path); printlog("debug", "saving aircraft data to ", me.path);
me.signalN.setBoolValue(1); me.signalN.setBoolValue(1);
var args = props.Node.new({ "filename": me.path }); var data = props.Node.new();
var data = args.getNode("data", 1);
foreach (var c; me.catalog) { foreach (var c; me.catalog) {
if (c[0] == `/`) if (c[0] == `/`)
c = substr(c, 1); c = substr(c, 1);
props.copy(props.globals.getNode(c, 1), data.getNode(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...) { add : func(p...) {
foreach (var n; props.nodeList(p)) foreach (var n; props.nodeList(p))
@ -574,10 +573,7 @@ var livery = {
foreach (var file; directory(path)) { foreach (var file; directory(path)) {
if (substr(file, -4) != ".xml") if (substr(file, -4) != ".xml")
continue; continue;
var n = props.Node.new({ filename : path ~ file }); var n = io.read_properties(path ~ file);
fgcommand("loadxml", n);
n = n.getNode("data");
var name = n.getNode(me.name_path); var name = n.getNode(me.name_path);
var index = n.getNode(me.sort_path); var index = n.getNode(me.sort_path);
if (name == nil or index == nil) if (name == nil or index == nil)
@ -624,7 +620,7 @@ var livery = {
# in the remote aircraft accordingly. # in the remote aircraft accordingly.
# #
# SYNOPSIS: # 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 # <livery-dir> ... directory with livery files, relative to $FG_ROOT
# <interval> ... checking interval in seconds (default: 10) # <interval> ... checking interval in seconds (default: 10)
@ -667,8 +663,7 @@ var livery_update = {
me.running or return; me.running or return;
var file = me.fileN.getValue(); var file = me.fileN.getValue();
if (file != nil and file != me.last) { if (file != nil and file != me.last) {
fgcommand("loadxml", props.Node.new({ filename: me.dir ~ file ~ ".xml", io.read_properties(me.dir ~ file ~ ".xml", me.root);
targetnode: me.root }));
me.last = file; me.last = file;
if (me.callback != nil) if (me.callback != nil)
me.callback(file); me.callback(file);
@ -721,10 +716,7 @@ var formation = {
foreach (var file; directory(path)) { foreach (var file; directory(path)) {
if (substr(file, -4) != ".xml") if (substr(file, -4) != ".xml")
continue; continue;
var n = props.Node.new({ filename : path ~ file }); var n = io.read_properties(path ~ file);
fgcommand("loadxml", n);
n = n.getNode("data");
var name = n.getNode(me.name_path); var name = n.getNode(me.name_path);
var index = n.getNode(me.sort_path); var index = n.getNode(me.sort_path);
if (name == nil or index == nil) if (name == nil or index == nil)

View file

@ -225,8 +225,7 @@ var Dialog = {
me.close(); me.close();
me.prop.removeChildren(); me.prop.removeChildren();
fgcommand("loadxml", props.Node.new({"filename": getprop("/sim/fg-root") ~ "/" ~ me.path, io.read_properties(getprop("/sim/fg-root") ~ "/" ~ me.path, me.prop);
"targetnode": me.prop.getPath()}));
var n = me.prop.getNode("name"); var n = me.prop.getNode("name");
if (n == nil) if (n == nil)

View file

@ -87,11 +87,10 @@ var read_properties = func(path, target = nil) {
# Write XML file in FlightGear's native <PropertyList> format. # Write XML file in FlightGear's native <PropertyList> format.
# Returns the filename on success or nil on error. If the source # 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 # is a props.Node that refers to a node in the main tree, then
# determine whether the tree is a subtree of the global tree, in # the data are directly written from the tree, yielding a more
# which case the branch is writen directly from that tree, as this # accurate result. Otherwise the data need to be copied first,
# yields a more accurate result. (The attributes are "readable" # which may slightly change node types (FLOAT becomes DOUBLE etc.)
# + "writable" + the lowest unused bit.)
# #
# Usage: io.write_properties(<filename>, <props.Node or property-path>); # 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"); # io.write_properties("/tmp/foo.xml", "/sim/model");
# #
var write_properties = func(path, prop) { 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 }); 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)) { if(isa(prop, props.Node)) {
for(var root = prop; (var p = root.getParent()) != nil;) for(var root = prop; (var p = root.getParent()) != nil;)
root = p; root = p;

View file

@ -468,10 +468,7 @@ var dialog = func {
# #
var load = func(file, index = 0) { var load = func(file, index = 0) {
props.globals.getNode("/sim/tutorials", 1).removeChild("tutorial", index); props.globals.getNode("/sim/tutorials", 1).removeChild("tutorial", index);
fgcommand("loadxml", props.Node.new({ io.read_properties(getprop("/sim/fg-root") ~ "/" ~ file, "/sim/tutorials/tutorial[" ~ index ~ "]/");
"filename": getprop("/sim/fg-root") ~ "/" ~ file,
"targetnode": "/sim/tutorials/tutorial[" ~ index ~ "]/",
}));
} }