1
0
Fork 0
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-02-11 16:39:41 +00:00
parent 5638ad8377
commit f66013f0b1

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

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