diff --git a/A320-main.xml b/A320-main.xml index e71fd2dd..16b337cc 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -1926,6 +1926,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..5f875208 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(save.default, getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); + } spinning.stop(); }); +setlistener("/sim/signals/exit", func { + save.save(save.default, getprop("/sim/fg-home") ~ "/Export/" ~ getprop("/sim/aircraft") ~ "-save.xml"); +}); + 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 diff --git a/Nasal/Systems/save.nas b/Nasal/Systems/save.nas new file mode 100644 index 00000000..f91cf4f2 --- /dev/null +++ b/Nasal/Systems/save.nas @@ -0,0 +1,74 @@ +# 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 to autosave, just add them here. +var default = [ + # 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", + # 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 (saved_props, file) { + 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 (saved_props, file) { + 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"); +}