1
0
Fork 0

Nasal IO changes to work with new loadxml features

This commit is contained in:
James Turner 2011-05-25 21:27:07 +01:00
parent 4e85bedee1
commit d4fb116cd2
2 changed files with 36 additions and 0 deletions

View file

@ -28,6 +28,7 @@
READ ALLOW $FG_ROOT/*
READ ALLOW $FG_HOME/*
READ ALLOW $FG_AIRCRAFT/*
READ ALLOW $FG_SCENERY/*
WRITE ALLOW /tmp/*.xml
WRITE ALLOW $FG_HOME/*.sav

View file

@ -81,6 +81,33 @@ var read_properties = func(path, target = nil) {
return fgcommand("loadxml", args) ? ret : nil;
}
# Load XML file in FlightGear's native <PropertyList> format.
# file will be located in the airport-scenery directories according to
# ICAO and filename, i,e in Airports/I/C/A/ICAO.filename.xml
# If the second, optional target parameter is set, then the properties
# are loaded to this node in the global property tree. Otherwise they
# are returned as a separate props.Node tree. Returns the data as a
# props.Node on success or nil on error.
#
# Usage: io.read_airport_properties(<icao>, <filename> [, <props.Node or property-path>]);
#
# Examples:
#
# var data = io.read_properties("KSFO", "rwyuse");
#
var read_airport_properties = func(icao, fname, target = nil) {
var args = props.Node.new({ filename: fname, icao:icao });
if (target == nil) {
var ret = args.getNode("data", 1);
} elsif (isa(target, props.Node)) {
args.getNode("targetnode", 1).setValue(target.getPath());
var ret = target;
} else {
args.getNode("targetnode", 1).setValue(target);
var ret = props.globals.getNode(target, 1);
}
return fgcommand("loadxml", args) ? ret : nil;
}
# Write XML file in FlightGear's native <PropertyList> format.
# Returns the filename on success or nil on error. If the source
@ -246,6 +273,14 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
append(rules, [pattern, allow]);
printlog("info", "IORules: appending ", pattern);
}
} elsif (substr(pattern, 0, 12) == "$FG_SCENERY/") {
var p = substr(pattern, 12);
var sim = props.globals.getNode("/sim");
foreach (var c; sim.getChildren("fg-scenery")) {
pattern = c.getValue() ~ "/" ~ p;
append(rules, [pattern, allow]);
printlog("info", "IORules: appending ", pattern);
}
} else {
if (substr(pattern, 0, 9) == "$FG_ROOT/")
pattern = root ~ "/" ~ substr(pattern, 9);