Add "FlightPlanWriter" facade
This commit is contained in:
parent
3c306ca039
commit
b1f1ef4a28
@ -55,6 +55,7 @@ var loadExtraNasalFiles = func (addon) {
|
|||||||
"nasal/dialogs/thermal",
|
"nasal/dialogs/thermal",
|
||||||
"nasal/flight-plan",
|
"nasal/flight-plan",
|
||||||
"nasal/scenario",
|
"nasal/scenario",
|
||||||
|
"nasal/io/flight-plan-writer",
|
||||||
"aerotow",
|
"aerotow",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -31,17 +31,15 @@ var FlightPlan = {
|
|||||||
obj.addon = addon;
|
obj.addon = addon;
|
||||||
obj.message = message;
|
obj.message = message;
|
||||||
obj.routeDialog = routeDialog;
|
obj.routeDialog = routeDialog;
|
||||||
|
obj.flightPlanWriter = FlightPlanWriter.new(addon);
|
||||||
|
|
||||||
obj.addonNodePath = addon.node.getPath();
|
obj.addonNodePath = addon.node.getPath();
|
||||||
|
|
||||||
obj.wptCount = 0;
|
obj.wptCount = 0;
|
||||||
obj.fpFileHandler = nil; # Handler for wrire flight plan to file
|
|
||||||
obj.coord = nil; # Coordinates for flight plan
|
obj.coord = nil; # Coordinates for flight plan
|
||||||
obj.heading = nil; # AI plane heading
|
obj.heading = nil; # AI plane heading
|
||||||
obj.altitude = nil; # AI plane altitude
|
obj.altitude = nil; # AI plane altitude
|
||||||
|
|
||||||
obj.flightPlanPath = addon.storagePath ~ "/AI/FlightPlans/" ~ FlightPlan.FILENAME_FLIGHTPLAN;
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -169,14 +167,7 @@ var FlightPlan = {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
me.fpFileHandler = io.open(me.flightPlanPath, "w");
|
me.flightPlanWriter.open();
|
||||||
io.write(
|
|
||||||
me.fpFileHandler,
|
|
||||||
"<?xml version=\"1.0\"?>\n\n" ~
|
|
||||||
"<!-- This file is generated automatically by the Aerotow Everywhere add-on -->\n\n" ~
|
|
||||||
"<PropertyList>\n" ~
|
|
||||||
" <flightplan>\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
var aircraft = Aircraft.getSelected(me.addon);
|
var aircraft = Aircraft.getSelected(me.addon);
|
||||||
|
|
||||||
@ -234,12 +225,7 @@ var FlightPlan = {
|
|||||||
|
|
||||||
me.addWptEnd();
|
me.addWptEnd();
|
||||||
|
|
||||||
io.write(
|
me.flightPlanWriter.close();
|
||||||
me.fpFileHandler,
|
|
||||||
" </flightplan>\n" ~
|
|
||||||
"</PropertyList>\n\n"
|
|
||||||
);
|
|
||||||
io.close(me.fpFileHandler);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
@ -373,51 +359,8 @@ var FlightPlan = {
|
|||||||
var ktas = contains(performance, "ktas") ? performance.ktas : nil;
|
var ktas = contains(performance, "ktas") ? performance.ktas : nil;
|
||||||
|
|
||||||
name = name == nil ? me.wptCount : name;
|
name = name == nil ? me.wptCount : name;
|
||||||
var data = me.getWptString(name, coord, alt, ktas, groundAir, sec);
|
me.flightPlanWriter.write(name, coord, alt, ktas, groundAir, sec);
|
||||||
|
|
||||||
io.write(me.fpFileHandler, data);
|
|
||||||
|
|
||||||
me.wptCount = me.wptCount + 1;
|
me.wptCount = me.wptCount + 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
#
|
|
||||||
# Get single waypoint data as a string.
|
|
||||||
#
|
|
||||||
# name - Name of waypoint. Special names are: "WAIT", "END".
|
|
||||||
# coord - The Coord object
|
|
||||||
# alt - Altitude AMSL of AI plane
|
|
||||||
# ktas - True air speed of AI plane
|
|
||||||
# groundAir - Allowe value: "ground or "air". The "ground" means that AI plane is on the ground, "air" - in air
|
|
||||||
# sec - Number of seconds for "WAIT" waypoint
|
|
||||||
#
|
|
||||||
getWptString: func (name, coord = nil, alt = nil, ktas = nil, groundAir = nil, sec = nil) {
|
|
||||||
var str = " <wpt>\n"
|
|
||||||
~ " <name>" ~ name ~ "</name>\n";
|
|
||||||
|
|
||||||
if (coord != nil) {
|
|
||||||
str = str ~ " <lat>" ~ coord.lat() ~ "</lat>\n";
|
|
||||||
str = str ~ " <lon>" ~ coord.lon() ~ "</lon>\n";
|
|
||||||
str = str ~ " <!-- " ~ coord.lat() ~ "," ~ coord.lon() ~ " -->\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alt != nil) {
|
|
||||||
# str = str ~ " <alt>" ~ alt ~ "</alt>\n";
|
|
||||||
str = str ~ " <crossat>" ~ alt ~ "</crossat>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ktas != nil) {
|
|
||||||
str = str ~ " <ktas>" ~ ktas ~ "</ktas>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (groundAir != nil) {
|
|
||||||
var onGround = groundAir == "ground" ? "true" : "false";
|
|
||||||
str = str ~ " <on-ground>" ~ onGround ~ "</on-ground>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sec != nil) {
|
|
||||||
str = str ~ " <time-sec>" ~ sec ~ "</time-sec>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return str ~ " </wpt>\n";
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
111
nasal/io/flight-plan-writer.nas
Normal file
111
nasal/io/flight-plan-writer.nas
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#
|
||||||
|
# Aerotow Everywhere - Add-on for FlightGear
|
||||||
|
#
|
||||||
|
# Written and developer by Roman Ludwicki (PlayeRom, SP-ROM)
|
||||||
|
#
|
||||||
|
# Copyright (C) 2022 Roman Ludwicki
|
||||||
|
#
|
||||||
|
# Aerotow Everywhere is an Open Source project and it is licensed
|
||||||
|
# under the GNU Public License v3 (GPLv3)
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Object for write flight plan to the XML file
|
||||||
|
#
|
||||||
|
var FlightPlanWriter = {
|
||||||
|
#
|
||||||
|
# Constructor
|
||||||
|
#
|
||||||
|
# addon - Addon object
|
||||||
|
#
|
||||||
|
new: func (addon) {
|
||||||
|
var obj = { parents: [FlightPlanWriter] };
|
||||||
|
|
||||||
|
obj.fpFileHandler = nil; # Handler for wrire flight plan to file
|
||||||
|
obj.flightPlanPath = addon.storagePath ~ "/AI/FlightPlans/" ~ FlightPlan.FILENAME_FLIGHTPLAN;
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
#
|
||||||
|
# Open XML file to wrire flight plan
|
||||||
|
#
|
||||||
|
open: func () {
|
||||||
|
me.fpFileHandler = io.open(me.flightPlanPath, "w");
|
||||||
|
|
||||||
|
if (me.fpFileHandler) {
|
||||||
|
io.write(
|
||||||
|
me.fpFileHandler,
|
||||||
|
"<?xml version=\"1.0\"?>\n\n" ~
|
||||||
|
"<!-- This file is generated automatically by the Aerotow Everywhere add-on -->\n\n" ~
|
||||||
|
"<PropertyList>\n" ~
|
||||||
|
" <flightplan>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
#
|
||||||
|
# Write single waypoint to XML file with flight plan
|
||||||
|
#
|
||||||
|
# name - Name of waypoint. Special names are: "WAIT", "END".
|
||||||
|
# coord - The Coord object
|
||||||
|
# alt - Altitude AMSL of AI plane
|
||||||
|
# ktas - True air speed of AI plane
|
||||||
|
# groundAir - Allowe value: "ground or "air". The "ground" means that AI plane is on the ground, "air" - in air
|
||||||
|
# sec - Number of seconds for "WAIT" waypoint
|
||||||
|
#
|
||||||
|
write: func (name, coord = nil, alt = nil, ktas = nil, groundAir = nil, sec = nil) {
|
||||||
|
if (!me.fpFileHandler) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var str = " <wpt>\n"
|
||||||
|
~ " <name>" ~ name ~ "</name>\n";
|
||||||
|
|
||||||
|
if (coord != nil) {
|
||||||
|
str = str ~ " <lat>" ~ coord.lat() ~ "</lat>\n";
|
||||||
|
str = str ~ " <lon>" ~ coord.lon() ~ "</lon>\n";
|
||||||
|
str = str ~ " <!--\n"
|
||||||
|
~ " " ~ coord.lat() ~ "," ~ coord.lon() ~ "\n"
|
||||||
|
~ " -->\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alt != nil) {
|
||||||
|
# str = str ~ " <alt>" ~ alt ~ "</alt>\n";
|
||||||
|
str = str ~ " <crossat>" ~ alt ~ "</crossat>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ktas != nil) {
|
||||||
|
str = str ~ " <ktas>" ~ ktas ~ "</ktas>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groundAir != nil) {
|
||||||
|
var onGround = groundAir == "ground" ? "true" : "false";
|
||||||
|
str = str ~ " <on-ground>" ~ onGround ~ "</on-ground>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sec != nil) {
|
||||||
|
str = str ~ " <time-sec>" ~ sec ~ "</time-sec>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
str = str ~ " </wpt>\n";
|
||||||
|
|
||||||
|
io.write(me.fpFileHandler, str);
|
||||||
|
},
|
||||||
|
|
||||||
|
#
|
||||||
|
# Close XML file with flight plan
|
||||||
|
#
|
||||||
|
close: func () {
|
||||||
|
if (me.fpFileHandler) {
|
||||||
|
io.write(
|
||||||
|
me.fpFileHandler,
|
||||||
|
" </flightplan>\n" ~
|
||||||
|
"</PropertyList>\n\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
io.close(me.fpFileHandler);
|
||||||
|
me.fpFileHandler = nil;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user