- first changes to make missions addon compatible (can load)
@ -137,7 +137,7 @@
|
|||||||
var update_list = func {
|
var update_list = func {
|
||||||
list.removeChildren("value");
|
list.removeChildren("value");
|
||||||
|
|
||||||
var dir = directory(getprop("/sim/fg-root") ~ "/Missions");
|
var dir = directory(getprop("/sim/mission/root_path") ~ "/Missions");
|
||||||
foreach (var a; dir)
|
foreach (var a; dir)
|
||||||
if (a != "." and a != ".." and a != "Generic")
|
if (a != "." and a != ".." and a != "Generic")
|
||||||
list.addChild("value").setValue(a);
|
list.addChild("value").setValue(a);
|
||||||
@ -147,7 +147,7 @@
|
|||||||
|
|
||||||
var select_mission = func {
|
var select_mission = func {
|
||||||
selected_mission = getprop("/sim/mission/gui/selected-mission");
|
selected_mission = getprop("/sim/mission/gui/selected-mission");
|
||||||
mission_root = getprop("/sim/fg-root") ~ "/Missions/" ~ selected_mission;
|
mission_root = getprop("/sim/mission/root_path") ~ "/Missions/" ~ selected_mission;
|
||||||
|
|
||||||
data_node.setValues({description: ""});
|
data_node.setValues({description: ""});
|
||||||
io.read_properties(mission_root ~ "/metadata.xml", data_node);
|
io.read_properties(mission_root ~ "/metadata.xml", data_node);
|
Before Width: | Height: | Size: 409 KiB After Width: | Height: | Size: 409 KiB |
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 246 KiB |
Before Width: | Height: | Size: 899 KiB After Width: | Height: | Size: 899 KiB |
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 246 KiB |
Before Width: | Height: | Size: 899 KiB After Width: | Height: | Size: 899 KiB |
@ -10,20 +10,28 @@ var handlers = [];
|
|||||||
var hasmember = view.hasmember;
|
var hasmember = view.hasmember;
|
||||||
|
|
||||||
var addExtension = func (type, h) {
|
var addExtension = func (type, h) {
|
||||||
if (type == "MissionObject")
|
if (type == "MissionObject") {
|
||||||
append (objects, h);
|
append (objects, h);
|
||||||
elsif (type == "Handler")
|
} elsif (type == "Handler") {
|
||||||
append (handlers, h);
|
append (handlers, h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var extension_list = func {
|
var extension_list = func {
|
||||||
var v = [];
|
var v = [];
|
||||||
var path = getprop("/sim/fg-root") ~ "/Nasal/mission/extensions";
|
var path = getprop("/sim/mission/root_path") ~ "/Nasal/extensions";
|
||||||
if((var dir = directory(path)) == nil) return;
|
if((var dir = directory(path)) == nil) {
|
||||||
foreach(var file; sort(dir, cmp))
|
return;
|
||||||
if(size(file) > 4)
|
}
|
||||||
if (substr(file, -4) == ".nas")
|
|
||||||
|
foreach(var file; sort(dir, cmp)) {
|
||||||
|
if(size(file) > 4) {
|
||||||
|
if (substr(file, -4) == ".nas") {
|
||||||
append(v, file);
|
append(v, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,11 +41,13 @@ var load_nasal = func(file, module) { # (copy-paste from io.nas)
|
|||||||
if (size(err)) {
|
if (size(err)) {
|
||||||
if (substr(err[0], 0, 12) == "Parse error:") { # hack around Nasal feature
|
if (substr(err[0], 0, 12) == "Parse error:") { # hack around Nasal feature
|
||||||
var e = split(" at line ", err[0]);
|
var e = split(" at line ", err[0]);
|
||||||
if (size(e) == 2)
|
if (size(e) == 2) {
|
||||||
err[0] = string.join("", [e[0], "\n at ", file, ", line ", e[1], "\n "]);
|
err[0] = string.join("", [e[0], "\n at ", file, ", line ", e[1], "\n "]);
|
||||||
}
|
}
|
||||||
for (var i = 1; (var c = caller(i)) != nil; i += 1)
|
}
|
||||||
|
for (var i = 1; (var c = caller(i)) != nil; i += 1) {
|
||||||
err ~= subvec(c, 2, 2);
|
err ~= subvec(c, 2, 2);
|
||||||
|
}
|
||||||
debug.printerror(err);
|
debug.printerror(err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -56,8 +66,11 @@ var load_preferences = func() {
|
|||||||
var start_mission = func(name) {
|
var start_mission = func(name) {
|
||||||
if (mission_started) return;
|
if (mission_started) return;
|
||||||
|
|
||||||
mission_root = resolvepath("Missions/" ~ name);
|
# FIXME - ResourceLoader in FG Source
|
||||||
if (mission_root == "") return;
|
mission_root = resolvepath("/Aircraft/Missions/" ~ name);
|
||||||
|
if (mission_root == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
load_preferences();
|
load_preferences();
|
||||||
|
|
||||||
@ -71,9 +84,9 @@ var start_mission = func(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var timeofday = mission_node.getChild("timeofday");
|
var timeofday = mission_node.getChild("timeofday");
|
||||||
if (timeofday != nil)
|
if (timeofday != nil) {
|
||||||
fgcommand("timeofday", props.Node.new({ "timeofday" : timeofday.getValue() }));
|
fgcommand("timeofday", props.Node.new({ "timeofday" : timeofday.getValue() }));
|
||||||
|
}
|
||||||
|
|
||||||
globals["__mission"] = {};
|
globals["__mission"] = {};
|
||||||
|
|
||||||
@ -101,14 +114,19 @@ var _start_mission = func {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var h; handlers)
|
foreach (var h; handlers) {
|
||||||
if( hasmember(h, "init") )
|
if( hasmember(h, "init") ) {
|
||||||
h.init();
|
h.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach(var c; mission_node.getChildren("object"))
|
foreach(var c; mission_node.getChildren("object")) {
|
||||||
foreach(var obj; objects)
|
foreach(var obj; objects) {
|
||||||
if (c.getValue("type") == obj.type)
|
if (c.getValue("type") == obj.type) {
|
||||||
append(mission_objects, obj.new(c));
|
append(mission_objects, obj.new(c));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach(var obj; mission_objects)
|
foreach(var obj; mission_objects)
|
||||||
if( hasmember(obj, "init") )
|
if( hasmember(obj, "init") )
|
||||||
@ -231,7 +249,7 @@ var scr_x = func getprop("/sim/startup/xsize");
|
|||||||
var scr_y = func getprop("/sim/startup/ysize");
|
var scr_y = func getprop("/sim/startup/ysize");
|
||||||
|
|
||||||
var init_gui = func {
|
var init_gui = func {
|
||||||
gui.Dialog.new("/sim/gui/dialogs/mission-browser/dialog", "Nasal/mission/GUI/mission_browser.xml");
|
gui.Dialog.new("/sim/gui/dialogs/mission-browser/dialog", getprop("/sim/mission/root_path") ~ "/GUI/mission_browser.xml");
|
||||||
|
|
||||||
#reset handling
|
#reset handling
|
||||||
foreach(var menu; props.getNode("/sim/menubar/default").getChildren("menu"))
|
foreach(var menu; props.getNode("/sim/menubar/default").getChildren("menu"))
|
||||||
@ -294,8 +312,13 @@ var load_data = func {
|
|||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
_setlistener("/nasal/mission/loaded", func {
|
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
|
||||||
|
removelistener(fdm_init_listener);
|
||||||
setprop("/sim/sound/chatter/enabled", 1);
|
setprop("/sim/sound/chatter/enabled", 1);
|
||||||
setprop("/sim/sound/chatter/volume", 1.0);
|
setprop("/sim/sound/chatter/volume", 1.0);
|
||||||
init_gui();
|
init_gui();
|
||||||
|
|
||||||
|
print("Mission initalized");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
print("Mission loaded");
|
3
config.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<PropertyList>
|
||||||
|
</PropertyList>
|
19
main.nas
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#
|
||||||
|
# Missions addon
|
||||||
|
#
|
||||||
|
# Started by Marius_A
|
||||||
|
# Started on November 2016
|
||||||
|
#
|
||||||
|
# Converted to a FlightGear addon by
|
||||||
|
# Slawek Mikula, October 2017
|
||||||
|
|
||||||
|
var main = func( root ) {
|
||||||
|
# setting root path to addon
|
||||||
|
setprop("/sim/mission/root_path", root);
|
||||||
|
|
||||||
|
# load scripts
|
||||||
|
foreach(var f; ['mission.nas'] ) {
|
||||||
|
io.load_nasal( root ~ "/Nasal/" ~ f, "missions" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Before Width: | Height: | Size: 445 KiB After Width: | Height: | Size: 445 KiB |