From 5638ad837717debfe1dd68738016df74e5f4fff4 Mon Sep 17 00:00:00 2001 From: fly Date: Tue, 11 Feb 2020 16:20:05 +0000 Subject: [PATCH 1/5] Implementing state save between sessions Signed-off-by: fly --- A320-main.xml | 3 +++ AircraftConfig/acconfig.nas | 11 +++++++++++ AircraftConfig/main.xml | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/A320-main.xml b/A320-main.xml index 29e4e1cd..417846ff 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -1949,6 +1949,9 @@ Aircraft/A320-family/gui/dialogs/refuel.nas Aircraft/A320-family/gui/dialogs/rmp.nas + + Aircraft/A320-family/Nasal/Systems/save.nas + diff --git a/AircraftConfig/acconfig.nas b/AircraftConfig/acconfig.nas index ca215827..94860a6f 100644 --- a/AircraftConfig/acconfig.nas +++ b/AircraftConfig/acconfig.nas @@ -96,6 +96,7 @@ setprop("systems/acconfig/options/weight-kgs", 0); setprop("systems/acconfig/options/adirs-skip", 0); setprop("systems/acconfig/options/welcome-skip", 0); setprop("systems/acconfig/options/no-rendering-warn", 0); +setprop("systems/acconfig/options/save-state", 0); setprop("systems/acconfig/options/pfd-rate", 1); setprop("systems/acconfig/options/nd-rate", 1); setprop("systems/acconfig/options/uecam-rate", 1); @@ -187,9 +188,17 @@ setlistener("/sim/signals/fdm-initialized", func { } setprop("systems/acconfig/options/revision", current_revision); writeSettings(); + if (getprop("options/system/save-state") == 1) + { + save.restore(); + } spinning.stop(); }); +setlistener("/sim/signals/exit", func { + save.save(); +}); + var renderingSettings = { check: func() { var rembrandt = getprop("sim/rendering/rembrandt/enabled"); @@ -223,6 +232,7 @@ var readSettings = func { io.read_properties(getprop("sim/fg-home") ~ "/Export/A320-family-config.xml", "/systems/acconfig/options"); setprop("options/system/keyboard-mode", getprop("systems/acconfig/options/keyboard-mode")); setprop("options/system/weight-kgs", getprop("systems/acconfig/options/weight-kgs")); + setprop("options/system/save-state", getprop("systems/acconfig/options/save-state")); setprop("controls/adirs/skip", getprop("systems/acconfig/options/adirs-skip")); setprop("sim/model/autopush/route/show", getprop("systems/acconfig/options/autopush/show-route")); setprop("sim/model/autopush/route/show-wingtip", getprop("systems/acconfig/options/autopush/show-wingtip")); @@ -232,6 +242,7 @@ var readSettings = func { var writeSettings = func { setprop("systems/acconfig/options/keyboard-mode", getprop("options/system/keyboard-mode")); setprop("systems/acconfig/options/weight-kgs", getprop("options/system/weight-kgs")); + setprop("systems/acconfig/options/save-state", getprop("options/system/save-state")); setprop("systems/acconfig/options/adirs-skip", getprop("controls/adirs/skip")); setprop("systems/acconfig/options/autopush/show-route", getprop("sim/model/autopush/route/show")); setprop("systems/acconfig/options/autopush/show-wingtip", getprop("sim/model/autopush/route/show-wingtip")); diff --git a/AircraftConfig/main.xml b/AircraftConfig/main.xml index 84620273..f3e266a1 100644 --- a/AircraftConfig/main.xml +++ b/AircraftConfig/main.xml @@ -426,6 +426,27 @@ true + + + + + left + /systems/acconfig/options/save-state + + property-toggle + /options/system/save-state + + + dialog-apply + + + nasal + + + true + hbox From f66013f0b1dc805ead3b1a6338c981f5352432e9 Mon Sep 17 00:00:00 2001 From: fly Date: Tue, 11 Feb 2020 16:39:41 +0000 Subject: [PATCH 2/5] save.nas Signed-off-by: fly --- Nasal/Systems/save.nas | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Nasal/Systems/save.nas diff --git a/Nasal/Systems/save.nas b/Nasal/Systems/save.nas new file mode 100644 index 00000000..927ab4cc --- /dev/null +++ b/Nasal/Systems/save.nas @@ -0,0 +1,57 @@ +# Copyright (C) 2020 Merspieler, merspieler _at_ airmail.cc +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Save and restore properties between sessions + +# To add more properties, just add them here: +var saved_props = [ + "/consumables/fuel/tank[0]/level-lbs", + "/consumables/fuel/tank[1]/level-lbs", + "/consumables/fuel/tank[2]/level-lbs", + "/consumables/fuel/tank[3]/level-lbs", + "/consumables/fuel/tank[4]/level-lbs" +]; +var file = getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"; + +var save = func { + print("Saving state..."); + for (var i = 0; i < size(saved_props); i += 1) + { + setprop("/save" ~ saved_props[i], getprop(saved_props[i])); + } + + var saveNode = props.globals.getNode("/save", 0); + + io.write_properties(file, saveNode); + print("State saved"); +} + +var restore = func { + print("Loading saved state..."); + var readNode = props.globals.initNode("/save", ); + + io.read_properties(file, readNode); + + for (var i = 0; i < size(saved_props); i += 1) + { + var val = getprop("/save" ~ saved_props[i]); + if (val != nil) + { + setprop(saved_props[i], val); + } + } + print("Saved state loaded"); +} From c16c0c2875fbe544f52b74aac6c907fafd0dfe6f Mon Sep 17 00:00:00 2001 From: fly Date: Sat, 29 Feb 2020 18:11:57 +0000 Subject: [PATCH 3/5] Accept parameter for save file Signed-off-by: fly --- AircraftConfig/acconfig.nas | 4 ++-- Nasal/Systems/save.nas | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/AircraftConfig/acconfig.nas b/AircraftConfig/acconfig.nas index 94860a6f..871a822c 100644 --- a/AircraftConfig/acconfig.nas +++ b/AircraftConfig/acconfig.nas @@ -190,13 +190,13 @@ setlistener("/sim/signals/fdm-initialized", func { writeSettings(); if (getprop("options/system/save-state") == 1) { - save.restore(); + save.restore(getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); } spinning.stop(); }); setlistener("/sim/signals/exit", func { - save.save(); + save.save(getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); }); var renderingSettings = { diff --git a/Nasal/Systems/save.nas b/Nasal/Systems/save.nas index 927ab4cc..88cc37a8 100644 --- a/Nasal/Systems/save.nas +++ b/Nasal/Systems/save.nas @@ -24,9 +24,8 @@ var saved_props = [ "/consumables/fuel/tank[3]/level-lbs", "/consumables/fuel/tank[4]/level-lbs" ]; -var file = getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"; -var save = func { +var save = func (file) { print("Saving state..."); for (var i = 0; i < size(saved_props); i += 1) { @@ -39,7 +38,7 @@ var save = func { print("State saved"); } -var restore = func { +var restore = func (file) { print("Loading saved state..."); var readNode = props.globals.initNode("/save", ); From a7c87dc428cd2269e44b2190965b1c71b517cc8e Mon Sep 17 00:00:00 2001 From: fly Date: Sat, 29 Feb 2020 18:38:32 +0000 Subject: [PATCH 4/5] Added a few more common controls to be saved Signed-off-by: fly --- Nasal/Systems/save.nas | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Nasal/Systems/save.nas b/Nasal/Systems/save.nas index 88cc37a8..04aefea8 100644 --- a/Nasal/Systems/save.nas +++ b/Nasal/Systems/save.nas @@ -18,11 +18,29 @@ # To add more properties, just add them here: var saved_props = [ + # CONSUMABLES + # Fuel "/consumables/fuel/tank[0]/level-lbs", "/consumables/fuel/tank[1]/level-lbs", "/consumables/fuel/tank[2]/level-lbs", "/consumables/fuel/tank[3]/level-lbs", - "/consumables/fuel/tank[4]/level-lbs" + "/consumables/fuel/tank[4]/level-lbs", + # CONTROLS + # rmp + "/controls/radio/rmp[0]/on", + "/controls/radio/rmp[1]/on", + "/controls/radio/rmp[2]/on", + # efis + "/instrumentation/efis[0]/inputs/range-nm", + "/instrumentation/efis[0]/nd/display-mode", + "/instrumentation/efis[0]/input/lh-vor-adf", + "/instrumentation/efis[0]/input/rh-vor-adf", + "/instrumentation/efis[1]/inputs/range-nm", + "/instrumentation/efis[1]/nd/display-mode", + "/instrumentation/efis[1]/input/lh-vor-adf", + "/instrumentation/efis[1]/input/rh-vor-adf", + # parking brake + "/controls/gear/brake-parking" ]; var save = func (file) { From 75b1d4c4f2eac8168a186b348dde0cd7b3ea3983 Mon Sep 17 00:00:00 2001 From: fly Date: Tue, 10 Mar 2020 02:18:24 +0000 Subject: [PATCH 5/5] Add option to define saved props Signed-off-by: fly --- AircraftConfig/acconfig.nas | 4 ++-- Nasal/Systems/save.nas | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AircraftConfig/acconfig.nas b/AircraftConfig/acconfig.nas index 871a822c..5f875208 100644 --- a/AircraftConfig/acconfig.nas +++ b/AircraftConfig/acconfig.nas @@ -190,13 +190,13 @@ setlistener("/sim/signals/fdm-initialized", func { writeSettings(); if (getprop("options/system/save-state") == 1) { - save.restore(getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); + save.restore(save.default, getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); } spinning.stop(); }); setlistener("/sim/signals/exit", func { - save.save(getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); + save.save(save.default, getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); }); var renderingSettings = { diff --git a/Nasal/Systems/save.nas b/Nasal/Systems/save.nas index 04aefea8..f91cf4f2 100644 --- a/Nasal/Systems/save.nas +++ b/Nasal/Systems/save.nas @@ -16,8 +16,8 @@ # Save and restore properties between sessions -# To add more properties, just add them here: -var saved_props = [ +# To add more properties to autosave, just add them here. +var default = [ # CONSUMABLES # Fuel "/consumables/fuel/tank[0]/level-lbs", @@ -43,7 +43,7 @@ var saved_props = [ "/controls/gear/brake-parking" ]; -var save = func (file) { +var save = func (saved_props, file) { print("Saving state..."); for (var i = 0; i < size(saved_props); i += 1) { @@ -56,7 +56,7 @@ var save = func (file) { print("State saved"); } -var restore = func (file) { +var restore = func (saved_props, file) { print("Loading saved state..."); var readNode = props.globals.initNode("/save", );