private IEnumerator AddUnPackedVesselsToDictionary() { var seconds = new WaitForSeconds(DictionaryUpdateSInterval); while (true) { if (!Enabled) { break; } if (FlightStateSystemReady) { var vesselsToAdd = FlightGlobals.Vessels .Where(v => !v.packed && v.id != FlightGlobals.ActiveVessel.id && !FlyByWireDictionary.Keys.Contains(v.id)) .ToArray(); foreach (var vesselToAdd in vesselsToAdd) { FlightStatesDictionary.Add(vesselToAdd.id, vesselToAdd.ctrlState); FlyByWireDictionary.Add(vesselToAdd.id, st => OnVesselFlyByWire(vesselToAdd.id, st)); vesselToAdd.OnFlyByWire += FlyByWireDictionary[vesselToAdd.id]; } } yield return(seconds); } }
private void TryRemoveCallback(Vessel vesselToRemove) { if (FlyByWireDictionary.ContainsKey(vesselToRemove.id) && vesselToRemove.OnFlyByWire.GetInvocationList().All(d => d.Method.Name != nameof(LunaOnVesselFlyByWire))) { vesselToRemove.OnFlyByWire -= FlyByWireDictionary[vesselToRemove.id]; } }
private void AddRemoveActiveVesselFromDictionary() { if (Enabled && FlightStateSystemReady) { if (VesselCommon.IsSpectating) { if (!FlyByWireDictionary.ContainsKey(FlightGlobals.ActiveVessel.id) && !FlightStatesDictionary.ContainsKey(FlightGlobals.ActiveVessel.id)) { FlightStatesDictionary.TryAdd(FlightGlobals.ActiveVessel.id, FlightGlobals.ActiveVessel.ctrlState); FlyByWireDictionary.Add(FlightGlobals.ActiveVessel.id, st => OnVesselFlyByWire(FlightGlobals.ActiveVessel.id, st)); FlightGlobals.ActiveVessel.OnFlyByWire += FlyByWireDictionary[FlightGlobals.ActiveVessel.id]; } } else { if (FlyByWireDictionary.ContainsKey(FlightGlobals.ActiveVessel.id) && FlightStatesDictionary.ContainsKey(FlightGlobals.ActiveVessel.id)) { try { FlightGlobals.ActiveVessel.OnFlyByWire -= FlyByWireDictionary[FlightGlobals.ActiveVessel.id]; } catch (Exception) { // ignored } FlyByWireDictionary.Remove(FlightGlobals.ActiveVessel.id); FlightStatesDictionary.TryRemove(FlightGlobals.ActiveVessel.id, out _); } } } }
/// <summary> /// Removes the vessel from the dictionaries /// </summary> public void RemoveVessel(Vessel vesselToRemove) { if (vesselToRemove == null) { return; } TryRemoveCallback(vesselToRemove); FlyByWireDictionary.TryRemove(vesselToRemove.id, out _); CurrentFlightState.TryRemove(vesselToRemove.id, out _); TargetFlightStateQueue.TryRemove(vesselToRemove.id, out _); }
/// <summary> /// Removes the vessel from the dictionaries /// </summary> public void RemoveVessel(Guid vesselId) { FlyByWireDictionary.TryRemove(vesselId, out _); CurrentFlightState.TryRemove(vesselId, out _); TargetFlightStateQueue.TryRemove(vesselId, out _); var vessel = FlightGlobals.FindVessel(vesselId); if (vessel != null) { TryRemoveCallback(vessel); } }
/// <summary> /// Removes the vessel from the dictionaries /// </summary> private void RemoveVesselFromSystem(Vessel vesselToRemove) { try { vesselToRemove.OnFlyByWire -= FlyByWireDictionary[vesselToRemove.id]; } catch (Exception) { // ignored } FlyByWireDictionary.Remove(vesselToRemove.id); FlightStatesDictionary.TryRemove(vesselToRemove.id, out _); }
private void AddLoadedVesselsToDictionary() { if (Enabled && FlightStateSystemReady) { var vesselsToAdd = FlightGlobals.VesselsLoaded .Where(v => v.id != FlightGlobals.ActiveVessel.id && !FlyByWireDictionary.Keys.Contains(v.id)) .ToArray(); foreach (var vesselToAdd in vesselsToAdd) { FlightStatesDictionary.TryAdd(vesselToAdd.id, vesselToAdd.ctrlState); FlyByWireDictionary.Add(vesselToAdd.id, st => OnVesselFlyByWire(vesselToAdd.id, st)); vesselToAdd.OnFlyByWire += FlyByWireDictionary[vesselToAdd.id]; } } }
private IEnumerator AddRemoveActiveVesselFromDictionary() { var seconds = new WaitForSeconds(DictionaryUpdateSInterval); while (true) { if (!Enabled) { break; } if (FlightStateSystemReady) { if (VesselCommon.IsSpectating) { if (!FlyByWireDictionary.ContainsKey(FlightGlobals.ActiveVessel.id) && !FlightStatesDictionary.ContainsKey(FlightGlobals.ActiveVessel.id)) { FlightStatesDictionary.Add(FlightGlobals.ActiveVessel.id, FlightGlobals.ActiveVessel.ctrlState); FlyByWireDictionary.Add(FlightGlobals.ActiveVessel.id, st => OnVesselFlyByWire(FlightGlobals.ActiveVessel.id, st)); FlightGlobals.ActiveVessel.OnFlyByWire += FlyByWireDictionary[FlightGlobals.ActiveVessel.id]; } } else { if (FlyByWireDictionary.ContainsKey(FlightGlobals.ActiveVessel.id) && FlightStatesDictionary.ContainsKey(FlightGlobals.ActiveVessel.id)) { try { FlightGlobals.ActiveVessel.OnFlyByWire -= FlyByWireDictionary[FlightGlobals.ActiveVessel.id]; } catch (Exception) { // ignored } FlyByWireDictionary.Remove(FlightGlobals.ActiveVessel.id); FlightStatesDictionary.Remove(FlightGlobals.ActiveVessel.id); } } } yield return(seconds); } }
public void AddVesselToSystem(Vessel vessel) { if (vessel == null || vessel.isEVA) { return; } //We must never have our own active and controlled vessel in the dictionary if (!VesselCommon.IsSpectating && FlightGlobals.ActiveVessel == vessel) { return; } FlyByWireDictionary.TryAdd(vessel.id, st => LunaOnVesselFlyByWire(vessel.id, st)); if (vessel.OnFlyByWire.GetInvocationList().All(d => d.Method.Name != nameof(LunaOnVesselFlyByWire))) { vessel.OnFlyByWire += FlyByWireDictionary[vessel.id]; } }
/// <summary> /// Clear the delegates and the dictionaries /// </summary> public void ClearSystem() { foreach (var keyVal in FlyByWireDictionary) { var vessel = FlightGlobals.FindVessel(keyVal.Key); if (vessel != null) { try { vessel.OnFlyByWire -= FlyByWireDictionary[keyVal.Key]; } catch (Exception) { // ignored } } } FlyByWireDictionary.Clear(); FlightStatesDictionary.Clear(); }
public void AddVesselToSystem(Vessel vessel) { if (vessel == null || vessel.isEVA) { return; } if (!FlyByWireDictionary.ContainsKey(vessel.id)) { //We must never have our own active and controlled vessel in the dictionary if (!VesselCommon.IsSpectating && FlightGlobals.ActiveVessel?.id == vessel.id) { return; } FlightStatesDictionary.TryAdd(vessel.id, new VesselFlightStateUpdate()); FlyByWireDictionary.Add(vessel.id, st => LunaOnVesselFlyByWire(vessel.id, st)); vessel.OnFlyByWire += FlyByWireDictionary[vessel.id]; } }
/// <summary> /// Adds the loaded and unpacked vessels to the dictionary /// </summary> private void AddLoadedUnpackedVesselsToDictionary() { if (Enabled && FlightStateSystemReady) { var vesselsToAdd = FlightGlobals.VesselsLoaded .Where(v => !v.isEVA && !v.packed && !FlyByWireDictionary.Keys.Contains(v.id)); foreach (var vesselToAdd in vesselsToAdd) { //We must never have our own active and controlled vessel in the dictionary if (!VesselCommon.IsSpectating && FlightGlobals.ActiveVessel?.id == vesselToAdd.id) { continue; } FlightStatesDictionary.TryAdd(vesselToAdd.id, new VesselFlightStateUpdate()); FlyByWireDictionary.Add(vesselToAdd.id, st => LunaOnVesselFlyByWire(vesselToAdd.id, st)); vesselToAdd.OnFlyByWire += FlyByWireDictionary[vesselToAdd.id]; } } }
/// <summary> /// Removes the vessel from the dictionaries /// </summary> public void RemoveVesselFromSystem(Vessel vesselToRemove) { if (vesselToRemove == null) { return; } try { vesselToRemove.OnFlyByWire -= FlyByWireDictionary[vesselToRemove.id]; } catch (Exception) { // ignored } if (FlyByWireDictionary.ContainsKey(vesselToRemove.id)) { FlyByWireDictionary.Remove(vesselToRemove.id); } FlightStatesDictionary.TryRemove(vesselToRemove.id, out _); }
private IEnumerator RemovePackedVesselsFromDictionary() { var seconds = new WaitForSeconds(DictionaryUpdateSInterval); while (true) { if (!Enabled) { break; } if (FlightStateSystemReady) { var vesselsToRemove = FlightGlobals.Vessels.Where(v => v.packed) .Where(v => FlyByWireDictionary.Keys.Contains(v.id)) .ToList(); foreach (var vesselToRemove in vesselsToRemove) { try { vesselToRemove.OnFlyByWire -= FlyByWireDictionary[vesselToRemove.id]; } catch (Exception) { // ignored } FlyByWireDictionary.Remove(vesselToRemove.id); FlightStatesDictionary.Remove(vesselToRemove.id); } } yield return(seconds); } }
private void RemoveUnloadedVesselsFromDictionary() { if (Enabled && FlightStateSystemReady) { var vesselsToRemove = FlightGlobals.VesselsUnloaded .Where(v => FlyByWireDictionary.Keys.Contains(v.id)) .ToList(); foreach (var vesselToRemove in vesselsToRemove) { try { vesselToRemove.OnFlyByWire -= FlyByWireDictionary[vesselToRemove.id]; } catch (Exception) { // ignored } FlyByWireDictionary.Remove(vesselToRemove.id); FlightStatesDictionary.TryRemove(vesselToRemove.id, out _); } } }
public override void OnDisabled() { base.OnDisabled(); FlyByWireDictionary.Clear(); FlightStatesDictionary.Clear(); }