예제 #1
0
        // Is called when this Addon is first loaded to initializes all values (eg registration of event-handlers and creation
        // of original-stats library).
        public void Awake()
        {
            try
            {
                FlightRecorder.Initialize();
                MissionController.Initialize();

                // Build dictionary of all parts for easier access:
                if (KSTS.partDictionary == null)
                {
                    KSTS.partDictionary = new Dictionary <string, AvailablePart>();
                    foreach (AvailablePart part in PartLoader.LoadedPartsList)
                    {
                        if (KSTS.partDictionary.ContainsKey(part.name.ToString()))
                        {
                            Debug.LogError("[KSTS] duplicate part-name '" + part.name.ToString() + "'");
                            continue;
                        }
                        KSTS.partDictionary.Add(part.name.ToString(), part);
                    }
                }

                // Build a dictionay of all resources for easier access:
                if (KSTS.resourceDictionary == null)
                {
                    KSTS.resourceDictionary = new Dictionary <string, PartResourceDefinition>();
                    foreach (PartResourceDefinition resourceDefinition in PartResourceLibrary.Instance.resourceDefinitions)
                    {
                        KSTS.resourceDictionary.Add(resourceDefinition.name.ToString(), resourceDefinition);
                    }
                }

                // Invoke the timer-function every second to run background-code:
                if (!IsInvoking("Timer"))
                {
                    InvokeRepeating("Timer", 1, 1);
                }



                parentDictionary = new Dictionary <string, string>();
                if (StageRecoveryAPI.StageRecoveryAvailable)
                {
                    StageRecoveryAPI.AddRecoverySuccessEvent((vessel, array, str) =>
                    {
                        if (StageRecoveryAPI.StageRecoveryEnabled)
                        {
                            StageRecovered?.Invoke(this, new StageRecoveredEventArgs {
                                Vessel = vessel, FundsRecovered = array[1]
                            });
                        }
                    });

                    GameEvents.onStageSeparation.Add(new EventData <EventReport> .OnEvent(this.onStageSeparation));
                    GameEvents.onVesselWasModified.Add(new EventData <Vessel> .OnEvent(this.onVesselModified));
                }

                // Execute the following code only once:
                if (KSTS.initialized)
                {
                    return;
                }
                DontDestroyOnLoad(this);
                KSTS.initialized = true;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSTS] Awake(): " + e.ToString());
            }
        }
예제 #2
0
        // Is called when this Addon is first loaded to initializes all values (eg registration of event-handlers and creation
        // of original-stats library).
        public void Awake()
        {
            try
            {
                FlightRecorder.Initialize();
                MissionController.Initialize();

                // Build dictionary of all parts for easier access:
                if (KSTS.partDictionary == null)
                {
                    KSTS.partDictionary = new Dictionary <string, AvailablePart>();
                    foreach (var part in PartLoader.LoadedPartsList)
                    {
                        if (KSTS.partDictionary.ContainsKey(part.name.ToString()))
                        {
                            Debug.LogError("duplicate part-name '" + part.name.ToString() + "'");
                            continue;
                        }
                        KSTS.partDictionary.Add(part.name.ToString(), part);
                    }
                }

                // Build a dictionay of all resources for easier access:
                if (KSTS.resourceDictionary == null)
                {
                    KSTS.resourceDictionary = new Dictionary <string, PartResourceDefinition>();
                    foreach (var resourceDefinition in PartResourceLibrary.Instance.resourceDefinitions)
                    {
                        KSTS.resourceDictionary.Add(resourceDefinition.name.ToString(), resourceDefinition);
                    }
                }

                // Invoke the timer-function every second to run background-code:
                if (!IsInvoking("Timer"))
                {
                    InvokeRepeating("Timer", 1, 1);
                }

                // In case the Stage Recovery Mod is installed, add lists and handlers to track the separation and recovery of stages:
                if (StageRecoveryAPI.StageRecoveryAvailable && KSTS.stageParentDictionary == null)
                {
                    Log.Warning("detected stage recovery mod");
                    stageParentDictionary = new Dictionary <string, string>();
                    StageRecoveryAPI.AddRecoverySuccessEvent((vessel, array, str) =>
                    {
                        if (StageRecoveryAPI.StageRecoveryEnabled)
                        {
                            FlightRecorder.OnStageRecovered(vessel.id.ToString(), array[1]);
                        }
                    });

                    GameEvents.onStageSeparation.Add(new EventData <EventReport> .OnEvent(this.onStageSeparation));
                    GameEvents.onVesselWasModified.Add(new EventData <Vessel> .OnEvent(this.onVesselModified));
                }

                // Execute the following code only once:
                if (KSTS.initialized)
                {
                    return;
                }
                DontDestroyOnLoad(this);
                KSTS.initialized = true;
            }
            catch (Exception e)
            {
                Debug.LogError("Awake(): " + e.ToString());
            }
        }