コード例 #1
0
        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);
            }
        }
コード例 #2
0
 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 _);
             }
         }
     }
 }
コード例 #3
0
        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];
                }
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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];
            }
        }
コード例 #6
0
        /// <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];
                }
            }
        }