1
0
Fork 0

Merge pull request #70 from legoboyvdlp/save

Implementing state save between sessions
This commit is contained in:
merspieler 2020-03-15 06:27:26 +11:00 committed by GitHub
commit 1bd38663e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 0 deletions

View file

@ -1926,6 +1926,9 @@
<file>Aircraft/A320-family/gui/dialogs/refuel.nas</file>
<file>Aircraft/A320-family/gui/dialogs/rmp.nas</file>
</Dialogs>
<save>
<file>Aircraft/A320-family/Nasal/Systems/save.nas</file>
</save>
</nasal>
</PropertyList>

View file

@ -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"));

View file

@ -426,6 +426,27 @@
</binding>
<live>true</live>
</checkbox>
<checkbox>
<!-- TODO there might be a better way to formulate this. -->
<label>Save states between sessions</label>
<halign>left</halign>
<property>/systems/acconfig/options/save-state</property>
<binding>
<command>property-toggle</command>
<property>/options/system/save-state</property>
</binding>
<binding>
<command>dialog-apply</command>
</binding>
<binding>
<command>nasal</command>
<script>
acconfig.writeSettings();
</script>
</binding>
<live>true</live>
</checkbox>
<group>
<layout>hbox</layout>

74
Nasal/Systems/save.nas Normal file
View file

@ -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");
}