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 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 _); } } } }
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; } 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]; } } }