Database persistent across sessions
This commit is contained in:
parent
f01fc6bc6a
commit
cfcb77e3cf
5 changed files with 76 additions and 8 deletions
|
@ -784,7 +784,6 @@ var canvas_MCDU_base = {
|
|||
me["Simple_R6S"].setText("SOFTWARE ");
|
||||
me["Simple_R4S"].setText("PILOT STORED ");
|
||||
me["Simple_R4"].setText("00RTES 00RWYS ");
|
||||
me["Simple_R5"].setText("DELETE ALL ");
|
||||
|
||||
pageSwitch[i].setBoolValue(1);
|
||||
}
|
||||
|
@ -809,6 +808,14 @@ var canvas_MCDU_base = {
|
|||
me["arrow5R"].hide();
|
||||
}
|
||||
|
||||
if (fmgc.WaypointDatabase.confirm) {
|
||||
me["Simple_R5"].setText("CONFIRM DELETE ALL ");
|
||||
me["Simple_R5"].setColor(getprop("/MCDUC/colors/amb/r"),getprop("/MCDUC/colors/amb/g"),getprop("/MCDUC/colors/amb/b"));
|
||||
} else {
|
||||
me["Simple_R5"].setText("DELETE ALL ");
|
||||
me["Simple_R5"].setColor(getprop("/MCDUC/colors/blu/r"),getprop("/MCDUC/colors/blu/g"),getprop("/MCDUC/colors/blu/b"));
|
||||
}
|
||||
|
||||
if (getprop("/FMGC/status/phase") == 0 or getprop("/FMGC/status/phase") == 7) {
|
||||
me["Simple_L5"].show();
|
||||
me["Simple_L5S"].show();
|
||||
|
|
|
@ -119,7 +119,7 @@ setprop("gear/gear[0]/wow-fmgc", 1);
|
|||
|
||||
var FMGCinit = func {
|
||||
setprop("/FMGC/status/to-state", 0);
|
||||
setprop("/FMGC/status/phase", "0"); # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done
|
||||
setprop("/FMGC/status/phase", 0); # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done
|
||||
setprop("/FMGC/internal/maxspeed", 338);
|
||||
setprop("/FMGC/internal/mng-spd", 157);
|
||||
setprop("/FMGC/internal/mng-spd-cmd", 157);
|
||||
|
@ -519,7 +519,7 @@ var masterFMGC = maketimer(0.2, func {
|
|||
});
|
||||
|
||||
var reset_FMGC = func {
|
||||
setprop("/FMGC/status/phase", "0");
|
||||
setprop("/FMGC/status/phase", 0);
|
||||
fd1 = getprop("/it-autoflight/input/fd1");
|
||||
fd2 = getprop("/it-autoflight/input/fd2");
|
||||
spd = getprop("/it-autoflight/input/spd-kts");
|
||||
|
|
|
@ -9,6 +9,7 @@ var nilTree = {
|
|||
|
||||
var WaypointDatabase = {
|
||||
waypointsVec: [],
|
||||
confirm: 0,
|
||||
# addWP - adds pilot waypoint to waypoints vector
|
||||
# arg: wpObj - passed pilot waypoint object
|
||||
# return:
|
||||
|
@ -40,6 +41,8 @@ var WaypointDatabase = {
|
|||
append(me.waypointsVec, wpObj);
|
||||
return 2;
|
||||
}
|
||||
|
||||
me.write();
|
||||
},
|
||||
# delete - empties waypoints vector
|
||||
delete: func() {
|
||||
|
@ -96,9 +99,9 @@ var WaypointDatabase = {
|
|||
}
|
||||
return nil;
|
||||
},
|
||||
# write - write to file, as a delimited string
|
||||
# write - write to file, as a hash structure
|
||||
write: func() {
|
||||
var path = getprop("/sim/fg-home") ~ "/Export/savedWaypoints.xml";
|
||||
var path = getprop("/sim/fg-home") ~ "/Export/A320SavedWaypoints.xml";
|
||||
var tree = {
|
||||
waypoints: {
|
||||
|
||||
|
@ -108,13 +111,48 @@ var WaypointDatabase = {
|
|||
for (var i = 0; i < me.getSize(); i = i + 1) {
|
||||
if (me.waypointsVec[i] != nil) {
|
||||
tree.waypoints["waypoint" ~ i] = me.waypointsVec[i].tree;
|
||||
} else {
|
||||
tree.waypoints["waypoint" ~ i] = nilTree;
|
||||
}
|
||||
}
|
||||
|
||||
io.writexml(path, props.Node.new(tree)); # write the data
|
||||
},
|
||||
# read - read from a file, extract using props interface
|
||||
read: func() {
|
||||
me.delete();
|
||||
var path = getprop("/sim/fg-home") ~ "/Export/A320SavedWaypoints.xml";
|
||||
var data = io.readxml(path).getChild("waypoints");
|
||||
var pilotWP = nil;
|
||||
for (var i = 0; i < 20; i = i + 1) {
|
||||
pilotWP = nil;
|
||||
var childNode = data.getChild("waypoint" ~ i);
|
||||
if (childNode == nil) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var wpt = createWP({lat: num(childNode.getChild("latitude").getValue()), lon: num(childNode.getChild("longitude").getValue())},childNode.getChild("ident").getValue());
|
||||
|
||||
if (left(childNode.getChild("ident").getValue(), 3) == "PBD") {
|
||||
pilotWP = pilotWaypoint.newAtPosition(wpt, "PBD", right(childNode.getChild("ident").getValue(), 1));
|
||||
} else {
|
||||
pilotWP = pilotWaypoint.newAtPosition(wpt, "LL", right(childNode.getChild("ident").getValue(), 1));
|
||||
}
|
||||
me.addWPToPos(pilotWP, right(childNode.getChild("ident").getValue(), 1));
|
||||
}
|
||||
},
|
||||
# addWPToPos - helper for reading - inserts at specific index
|
||||
# will create nil for intermediates
|
||||
addWPToPos: func(wpObj, position) {
|
||||
if (me.getSize() >= position) {
|
||||
me.waypointsVec[position - 1] = wpObj;
|
||||
} else {
|
||||
var numToIns = position - me.getSize();
|
||||
while (numToIns >= 1) {
|
||||
append(me.waypointsVec, nil);
|
||||
numToIns -= 1;
|
||||
}
|
||||
me.waypointsVec[position - 1] = wpObj;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var pilotWaypoint = {
|
||||
|
@ -145,6 +183,23 @@ var pilotWaypoint = {
|
|||
|
||||
return pilotWp;
|
||||
},
|
||||
newAtPosition: func(positioned, typeStr, position) {
|
||||
var pilotWp = { parents:[pilotWaypoint] };
|
||||
|
||||
pilotWp.setId(typeStr ~ sprintf("%s", position));
|
||||
pilotWp.index = position - 1;
|
||||
|
||||
# set ghost to created waypoint
|
||||
pilotWp.wpGhost = positioned;
|
||||
|
||||
pilotWp.tree = {
|
||||
"latitude": pilotWp.wpGhost.wp_lat,
|
||||
"longitude": pilotWp.wpGhost.wp_lon,
|
||||
"ident": pilotWp.id,
|
||||
};
|
||||
|
||||
return pilotWp;
|
||||
},
|
||||
setId: func(id) {
|
||||
if (typeof(id) == "scalar") { me.id = id; }
|
||||
},
|
||||
|
|
|
@ -227,6 +227,7 @@ var systemsInit = func {
|
|||
setlistener("/sim/signals/fdm-initialized", func {
|
||||
systemsInit();
|
||||
fmgc.flightPlanTimer.start();
|
||||
fmgc.WaypointDatabase.read();
|
||||
});
|
||||
|
||||
var systemsLoop = maketimer(0.1, func {
|
||||
|
|
|
@ -6,6 +6,11 @@ var statusInput = func(key, i) {
|
|||
if (key == "L3") {
|
||||
fmgc.switchDatabase();
|
||||
} elsif (key == "R5") {
|
||||
if (fmgc.WaypointDatabase.confirm) {
|
||||
fmgc.WaypointDatabase.delete();
|
||||
fmgc.WaypointDatabase.confirm = 0;
|
||||
} else {
|
||||
fmgc.WaypointDatabase.confirm = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue