Here's a small Nasal file to play with (attached). If you put
it into $FG_ROOT/Nasal, start fgfs with the ufo and press the
g-key, then you get a file-select dialog where you can select
a parking.xml file. When you click the "Load" button, then an
object is placed at every TaxiNode of the chosen airport.
And what is it good for? For *nothing*. Well, for showing off
some recent Nasal additions: the file selector, the put_model
function, and the xml parser. If the coordinates weren't in a
funny format, then it could have been done in very few lines.
m.
# opens file selector on g-key press, loads the selected parking.xml file,
# and puts a radar object on every TaxiNode.
var uncheesify = func(c) {
var i = 0;
for (; i < size(c); i += 1)
if (!string.isspace(c[i]))
break;
i < size(c) or die("empty coordinate"); ## added "i < "
if (c[0] == `N` or c[0] == `E`)
var sign = 1;
elsif (c[0] == `S` or c[0] == `W`)
var sign = -1
else
die("first character not one of N,S,E,W");
var s = "";
for (i += 1; i < size(c); i += 1) {
if (string.isdigit(c[i]))
s ~= chr(c[i]);
else
break;
}
var deg = num(s);
deg != nil or die("invalid degree");
for (; i < size(c); i += 1)
if (!string.isspace(c[i]))
break;
var s = "";
for (; i < size(c); i += 1) {
if (string.isdigit(c[i]) or c[i] == `.`)
s ~= chr(c[i]);
else
break;
}
var min = num(s);
min != nil or die("invalid minutes");
return sign * (deg + min / 60);
}
var load_file = func {
if ((var tree = xml.process_file(cmdarg().getValue(), xml.tree, "")) ==
nil)
die("error loading " ~ file);
foreach (var taxi; tree.getNode("groundnet/TaxiNodes",
1).getChildren("node")) {
var lat = uncheesify(taxi.getNode("lat", 1).getValue());
var lon = uncheesify(taxi.getNode("lon", 1).getValue());
var n = geo.put_model("Models/Airport/radar.ac", lat, lon);
}
}
var gearDown = func(v) {
file_selector.open();
old_gearDown(v);
}
var old_gearDown = nil;
var file_selector = nil;
setlistener("/sim/signals/nasal-dir-initialized", func {
if (getprop("/sim/aircraft") != "ufo")
return;
file_selector = gui.FileSelector.new(load_file,
"Select parking.xml file", "Load Models",
["parking.xml"],
getprop("/sim/fg-root") ~ "/AI/Airports",
"parking.xml");
old_gearDown = controls.gearDown;
controls.gearDown = gearDown;
});
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel