- first changes to make missions addon compatible (can load)

This commit is contained in:
Slawek Mikula 2017-10-10 09:35:13 +02:00
parent 27f0425089
commit 579b1b69d8
73 changed files with 69 additions and 24 deletions

View File

@ -137,7 +137,7 @@
var update_list = func {
list.removeChildren("value");
var dir = directory(getprop("/sim/fg-root") ~ "/Missions");
var dir = directory(getprop("/sim/mission/root_path") ~ "/Missions");
foreach (var a; dir)
if (a != "." and a != ".." and a != "Generic")
list.addChild("value").setValue(a);
@ -147,7 +147,7 @@
var select_mission = func {
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: ""});
io.read_properties(mission_root ~ "/metadata.xml", data_node);
@ -155,7 +155,7 @@
img.set("src", mission_root ~ "/image.png").setSize(250, 250);
}
update_list();

View File

Before

Width:  |  Height:  |  Size: 409 KiB

After

Width:  |  Height:  |  Size: 409 KiB

View File

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 246 KiB

View File

Before

Width:  |  Height:  |  Size: 899 KiB

After

Width:  |  Height:  |  Size: 899 KiB

View File

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 246 KiB

View File

Before

Width:  |  Height:  |  Size: 899 KiB

After

Width:  |  Height:  |  Size: 899 KiB

View File

@ -10,20 +10,28 @@ var handlers = [];
var hasmember = view.hasmember;
var addExtension = func (type, h) {
if (type == "MissionObject")
if (type == "MissionObject") {
append (objects, h);
elsif (type == "Handler")
} elsif (type == "Handler") {
append (handlers, h);
}
}
var extension_list = func {
var v = [];
var path = getprop("/sim/fg-root") ~ "/Nasal/mission/extensions";
if((var dir = directory(path)) == nil) return;
foreach(var file; sort(dir, cmp))
if(size(file) > 4)
if (substr(file, -4) == ".nas")
var path = getprop("/sim/mission/root_path") ~ "/Nasal/extensions";
if((var dir = directory(path)) == nil) {
return;
}
foreach(var file; sort(dir, cmp)) {
if(size(file) > 4) {
if (substr(file, -4) == ".nas") {
append(v, file);
}
}
}
return v;
}
@ -33,11 +41,13 @@ var load_nasal = func(file, module) { # (copy-paste from io.nas)
if (size(err)) {
if (substr(err[0], 0, 12) == "Parse error:") { # hack around Nasal feature
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 "]);
}
}
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);
}
debug.printerror(err);
return 0;
}
@ -56,8 +66,11 @@ var load_preferences = func() {
var start_mission = func(name) {
if (mission_started) return;
mission_root = resolvepath("Missions/" ~ name);
if (mission_root == "") return;
# FIXME - ResourceLoader in FG Source
mission_root = resolvepath("/Aircraft/Missions/" ~ name);
if (mission_root == "") {
return;
}
load_preferences();
@ -71,9 +84,9 @@ var start_mission = func(name) {
}
var timeofday = mission_node.getChild("timeofday");
if (timeofday != nil)
if (timeofday != nil) {
fgcommand("timeofday", props.Node.new({ "timeofday" : timeofday.getValue() }));
}
globals["__mission"] = {};
@ -101,14 +114,19 @@ var _start_mission = func {
return;
}
foreach (var h; handlers)
if( hasmember(h, "init") )
foreach (var h; handlers) {
if( hasmember(h, "init") ) {
h.init();
}
}
foreach(var c; mission_node.getChildren("object"))
foreach(var obj; objects)
if (c.getValue("type") == obj.type)
foreach(var c; mission_node.getChildren("object")) {
foreach(var obj; objects) {
if (c.getValue("type") == obj.type) {
append(mission_objects, obj.new(c));
}
}
}
foreach(var obj; mission_objects)
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 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
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/volume", 1.0);
init_gui();
});
print("Mission initalized");
});
print("Mission loaded");

3
config.xml Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
</PropertyList>

19
main.nas Normal file
View 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" );
}
}

View File

Before

Width:  |  Height:  |  Size: 445 KiB

After

Width:  |  Height:  |  Size: 445 KiB