Skip to content

Commit

Permalink
Improve flight start detection
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jan 21, 2024
1 parent 72c3ea0 commit 5b88289
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion TestFlightCore/TestFlightCore/TestFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,19 @@ private void OnEngineActiveChange(ModuleEngines data)
OnFlightStart();
}

private void OnVesselSituationChange(GameEvents.HostedFromToAction<Vessel, Vessel.Situations> ev)
{
if (ev.from == Vessel.Situations.PRELAUNCH && ev.host == FlightGlobals.ActiveVessel)
{
OnFlightStart();
}
}

private void OnFlightStart()
{
GameEvents.onStageActivate.Remove(OnStageActivate);
GameEvents.onEngineActiveChange.Remove(OnEngineActiveChange);
GameEvents.onVesselSituationChange.Remove(OnVesselSituationChange);
firstStaged = true;
missionStartTime = Planetarium.GetUniversalTime();
}
Expand Down Expand Up @@ -856,10 +865,17 @@ public override void Start()
GameEvents.onCrewTransferred.Add(OnCrewChange);
_OnCrewChange();
firstStaged = vessel.situation != Vessel.Situations.PRELAUNCH;
if (vessel.situation == Vessel.Situations.PRELAUNCH)

if (!firstStaged && part.isEngine())
{
firstStaged = part.FindModulesImplementing<ModuleEngines>().Find(e => e.staged) != null;
}

if (!firstStaged)
{
GameEvents.onStageActivate.Add(OnStageActivate);
GameEvents.onEngineActiveChange.Add(OnEngineActiveChange);
GameEvents.onVesselSituationChange.Add(OnVesselSituationChange);
}
else
missionStartTime = Planetarium.GetUniversalTime();
Expand All @@ -872,6 +888,7 @@ public override void OnDestroy()
GameEvents.onCrewTransferred.Remove(OnCrewChange);
GameEvents.onStageActivate.Remove(OnStageActivate);
GameEvents.onEngineActiveChange.Remove(OnEngineActiveChange);
GameEvents.onVesselSituationChange.Remove(OnVesselSituationChange);
}

public override void OnAwake()
Expand Down

0 comments on commit 5b88289

Please sign in to comment.