- bug - presets does not work - reloading FG causes whole addon reload and lost of mission state
- persisted mission_root between repositioning - refactored code (new separate files, function move)
This commit is contained in:
parent
5959faed74
commit
4d68efa714
@ -1,27 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<PropertyList>
|
||||
|
||||
<name>Test mission</name>
|
||||
|
||||
<description>
|
||||
Hoops / gates / checkpoints
|
||||
</description>
|
||||
|
||||
<!--include>timer_trigger.obj</include>
|
||||
<include>object_activation.obj</include>
|
||||
<include>property_trigger.obj</include>
|
||||
<include>point_of_interest.obj</include>
|
||||
<include>proximity_trigger.obj</include>
|
||||
<include>rectangle_area.obj</include>
|
||||
<include>model.obj</include>
|
||||
<include>message.obj</include>
|
||||
<include>single_shot_sound.obj</include>
|
||||
<include>timer.mgr</include>
|
||||
<include>message.mgr</include>
|
||||
<include>mission_compass.mgr</include-->
|
||||
|
||||
<audio-dir>Missions/Hoops-mission</audio-dir>
|
||||
|
||||
<presets>
|
||||
<altitude>-9999</altitude>
|
||||
<altitude-ft>-9999</altitude-ft>
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
var objects = [];
|
||||
var handlers = [];
|
||||
|
||||
var extensions_load = func {
|
||||
|
||||
@ -10,18 +12,28 @@ var extensions_load = func {
|
||||
#load mission extension
|
||||
foreach(var script; mission_node.getChildren("include")) {
|
||||
globals["__mission"][k = "__" ~ i] = {};
|
||||
load_nasal(mission_root ~ "/extensions/" ~ script.getValue(), k);
|
||||
_load_nasal(mission_root ~ "/extensions/" ~ script.getValue(), k);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
#load core extensions
|
||||
foreach(var script; extension_list()) {
|
||||
globals["__mission"][k = "__" ~ i] = {};
|
||||
load_nasal(getprop("/sim/mission/root_path") ~ "/Nasal/extensions/" ~ script, k);
|
||||
_load_nasal(getprop("/sim/mission/root_path") ~ "/Nasal/extensions/" ~ script, k);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
var extensions_clear = func {
|
||||
setsize(objects, 0);
|
||||
|
||||
foreach (var h; handlers) {
|
||||
if (hasmember(h, "stop")) {
|
||||
h.stop();
|
||||
}
|
||||
}
|
||||
setsize(handlers, 0);
|
||||
}
|
||||
|
||||
var extension_add = func (type, h) {
|
||||
if (type == "MissionObject") {
|
||||
@ -49,8 +61,29 @@ var extension_list = func {
|
||||
return v;
|
||||
}
|
||||
|
||||
var extensions_models_init = func() {
|
||||
foreach (var h; handlers) {
|
||||
if( hasmember(h, "init") ) {
|
||||
h.init();
|
||||
}
|
||||
}
|
||||
|
||||
var load_nasal = func(file, module) { # (copy-paste from io.nas)
|
||||
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") ) {
|
||||
obj.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _load_nasal = func(file, module) { # (copy-paste from io.nas)
|
||||
var code = call(func compile(io.readfile(file), file), nil, var err = []);
|
||||
if (size(err)) {
|
||||
if (substr(err[0], 0, 12) == "Parse error:") { # hack around Nasal feature
|
||||
|
@ -3,13 +3,10 @@ var mission_objects = [];
|
||||
var mission_started = 0;
|
||||
var mission_node = props.getNode("/sim/mission/data", 1);
|
||||
var mission_root = "";
|
||||
var objects = [];
|
||||
var handlers = [];
|
||||
|
||||
|
||||
var hasmember = view.hasmember;
|
||||
|
||||
var load_preferences = func() {
|
||||
var preferences_load = func() {
|
||||
foreach (var a; directory(mission_root)) {
|
||||
if (a == "preferences.xml") {
|
||||
io.read_properties(mission_root ~ "/preferences.xml", props.getNode(""));
|
||||
@ -28,64 +25,49 @@ var start_mission = func(name) {
|
||||
if (mission_root == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
load_preferences();
|
||||
# save mission root for repositioning (will reset addon)
|
||||
setprop("/sim/mission/current_mission/path", mission_root);
|
||||
|
||||
mission_node.removeAllChildren();
|
||||
io.read_properties(mission_root ~ "/mission.xml", mission_node);
|
||||
|
||||
# set flightgear main state (location, weather)
|
||||
var presets = mission_node.getChild("presets");
|
||||
# causes FG reload and reinit all data
|
||||
# if (presets != nil) {
|
||||
# props.copy(presets, props.getNode("/sim/presets"));
|
||||
# fgcommand("reposition");
|
||||
# }
|
||||
if (presets != nil) {
|
||||
props.copy(presets, props.getNode("/sim/presets"));
|
||||
fgcommand("reposition");
|
||||
}
|
||||
|
||||
var timeofday = mission_node.getChild("timeofday");
|
||||
if (timeofday != nil) {
|
||||
fgcommand("timeofday", props.Node.new({ "timeofday" : timeofday.getValue() }));
|
||||
}
|
||||
|
||||
extensions_load();
|
||||
|
||||
# wait for simulator restart & proceed
|
||||
settimer (func _start_mission(), 0);
|
||||
}
|
||||
|
||||
var _start_mission = func {
|
||||
# wait for splash screen closing
|
||||
if (splash_screen()) {
|
||||
settimer(func _start_mission(), 2);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var h; handlers) {
|
||||
if( hasmember(h, "init") ) {
|
||||
h.init();
|
||||
}
|
||||
}
|
||||
# reload data
|
||||
mission_root = getprop("/sim/mission/current_mission/path");
|
||||
print("mission root: " ~ mission_root);
|
||||
|
||||
foreach(var c; mission_node.getChildren("object")) {
|
||||
foreach(var obj; objects) {
|
||||
if (c.getValue("type") == obj.type) {
|
||||
append(mission_objects, obj.new(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
mission_node.removeAllChildren();
|
||||
io.read_properties(mission_root ~ "/mission.xml", mission_node);
|
||||
|
||||
foreach(var obj; mission_objects) {
|
||||
if( hasmember(obj, "init") ) {
|
||||
obj.init();
|
||||
}
|
||||
}
|
||||
preferences_load();
|
||||
extensions_load();
|
||||
extensions_models_init();
|
||||
|
||||
mission_started = 1;
|
||||
}
|
||||
|
||||
var splash_screen = func {
|
||||
var s = getprop("sim/startup/splash-alpha");
|
||||
if (s == nil) s = 1;
|
||||
return s > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
var stop_mission = func {
|
||||
if (!mission_started) {
|
||||
return;
|
||||
@ -94,17 +76,9 @@ var stop_mission = func {
|
||||
foreach(var obj; mission_objects) {
|
||||
obj.del();
|
||||
}
|
||||
|
||||
setsize(mission_objects, 0);
|
||||
setsize(objects, 0);
|
||||
|
||||
foreach (var h; handlers) {
|
||||
if (hasmember(h, "stop")) {
|
||||
h.stop();
|
||||
}
|
||||
}
|
||||
setsize(handlers, 0);
|
||||
|
||||
extensions_clear();
|
||||
delete(globals, "__mission");
|
||||
|
||||
mission_started = 0;
|
||||
@ -127,14 +101,12 @@ var activate_object = func(name, start = 1) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var activate_object_group = func(group, start = 1) {
|
||||
foreach(var ref; group.getChildren("object-reference")) {
|
||||
activate_object(ref.getValue(), start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var get_coord = func(n) {
|
||||
geo.Coord.new().set_latlon (
|
||||
var lat = n.getValue("latitude-deg") or 0,
|
||||
|
6
Nasal/utils.nas
Normal file
6
Nasal/utils.nas
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
var splash_screen = func {
|
||||
var s = getprop("sim/startup/splash-alpha");
|
||||
if (s == nil) s = 1;
|
||||
return s > 0 ? 1 : 0;
|
||||
}
|
9
TODO
9
TODO
@ -1,6 +1,15 @@
|
||||
bugs:
|
||||
- bug - presets does not work - reloading FG causes whole addon reload and lost of mission state
|
||||
|
||||
tasks:
|
||||
- actions documentation
|
||||
- fully working all example missions
|
||||
|
||||
features:
|
||||
- weather - set METAR weather in mission.xml
|
||||
- canvas map - dynamically extend layers with mission target layer
|
||||
- hoops - dynamic mission generator
|
||||
- tours - dynamic mission generator
|
||||
- skills - dynamic mission generator
|
||||
- mission browser - map for mission targets
|
||||
- ufo extension/mission for placing objects for new missions
|
||||
|
2
main.nas
2
main.nas
@ -12,7 +12,7 @@ var main = func( root ) {
|
||||
setprop("/sim/mission/root_path", root);
|
||||
|
||||
# load scripts
|
||||
foreach(var f; ['mission.nas', 'extensions.nas', 'persistence.nas', 'gui.nas'] ) {
|
||||
foreach(var f; ['mission.nas', 'extensions.nas', 'persistence.nas', 'gui.nas', 'utils.nas'] ) {
|
||||
io.load_nasal( root ~ "/Nasal/" ~ f, "mission" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user