1
0
Fork 0

Keep the same aircraft on sim reset

When user has installed more aircrafts with the same short ID, preserve
the selected dir, so we use the exact same aircraft.
This commit is contained in:
Roman Ludwicki 2023-10-24 20:11:19 +02:00 committed by James Turner
parent 857b163ee7
commit 2f0705bd49
2 changed files with 20 additions and 1 deletions

View file

@ -796,6 +796,13 @@ int fgInitAircraft(bool reinit, bool didUseLauncher)
SGSharedPtr<Root> pkgRoot(globals->packageRoot()); SGSharedPtr<Root> pkgRoot(globals->packageRoot());
SGPropertyNode* aircraftProp = fgGetNode("/sim/aircraft", true); SGPropertyNode* aircraftProp = fgGetNode("/sim/aircraft", true);
SGPropertyNode* aircraftDirProp = fgGetNode("/sim/aircraft-dir", true);
// ensure aircraft-dir survives reset, so we find the same aircraft
// after a reset as we did prior to it. Without this, aircraft
// can unintentionally change on a reset
aircraftDirProp->setAttribute(SGPropertyNode::PRESERVE, true);
const string fullyQualifiedAircraftId = fgGetString("/sim/aircraft-id"); const string fullyQualifiedAircraftId = fgGetString("/sim/aircraft-id");
string aircraftId = fullyQualifiedAircraftId.empty() ? aircraftProp->getStringValue() : fullyQualifiedAircraftId; string aircraftId = fullyQualifiedAircraftId.empty() ? aircraftProp->getStringValue() : fullyQualifiedAircraftId;
@ -1404,7 +1411,6 @@ void fgStartNewReset()
"Some errors restoring preserved state (read-only props?)" ); "Some errors restoring preserved state (read-only props?)" );
} }
fgGetNode("/sim")->removeChild("aircraft-dir");
fgInitAircraftPaths(true); fgInitAircraftPaths(true);
fgInitAircraft(true, false /* not from launcher */); fgInitAircraft(true, false /* not from launcher */);

View file

@ -101,6 +101,19 @@ static bool
do_switch_aircraft (const SGPropertyNode * arg, SGPropertyNode * root) do_switch_aircraft (const SGPropertyNode * arg, SGPropertyNode * root)
{ {
fgSetString("/sim/aircraft", arg->getStringValue("aircraft")); fgSetString("/sim/aircraft", arg->getStringValue("aircraft"));
// we could validate the new aircraft is find-able, and if not, bail out
// of the command at this point? Might give a better user experience?
// would need something like bool fgIsValidAircraft(name, dir);
// which could be cooked up by modifying FindAndCacheAircraft
// We assume that we are changing the aircraft, so we remove the aircraft path.
// this forces aircraft-dir to be recomputed by a full search as the user hopefully
// expects.
// We could allow pasing the dir as an optional argument to this command, if that
// is ever needed in the future.
fgGetNode("/sim")->removeChild("aircraft-dir");
// start a reset // start a reset
fgResetIdleState(); fgResetIdleState();
return true; return true;