Exemple #1
0
        public override void OnLoad(ConfigNode node)
        {
            // deserialize data
            DB.Load(node);

            Communications.NetworkInitialized  = false;
            Communications.NetworkInitializing = false;

            // initialize everything just once
            if (!initialized)
            {
                // add supply resources to pods
                Profile.SetupPods();

                // initialize subsystems
                Cache.Init();
                ResourceCache.Init();
                Radiation.Init();
                Science.Init();
                LineRenderer.Init();
                ParticleRenderer.Init();
                Highlighter.Init();
                UI.Init();

#if !KSP170 && !KSP16 && !KSP15 && !KSP14
                Serenity.Init();
#endif

                // prepare storm data
                foreach (CelestialBody body in FlightGlobals.Bodies)
                {
                    if (Storm.Skip_body(body))
                    {
                        continue;
                    }
                    Storm_data sd = new Storm_data
                    {
                        body = body
                    };
                    storm_bodies.Add(sd);
                }

                // various tweaks to the part icons in the editor
                Misc.TweakPartIcons();

                // setup callbacks
                callbacks = new Callbacks();

                // everything was initialized
                initialized = true;
            }

            // detect if this is a different savegame
            if (DB.uid != savegame_uid)
            {
                // clear caches
                Cache.Clear();
                ResourceCache.Clear();
                Message.all_logs.Clear();

                // sync main window pos from db
                UI.Sync();

                // remember savegame id
                savegame_uid = DB.uid;
            }

            Science.ClearDeferred();
        }
Exemple #2
0
        public override void OnLoad(ConfigNode node)
        {
            // everything in there will be called only one time : the first time a game is loaded from the main menu
            if (!IsCoreGameInitDone)
            {
                try
                {
                    // core game systems
                    Sim.Init();                             // find suns (Kopernicus support)
                    Radiation.Init();                       // create the radiation fields
                    ScienceDB.Init();                       // build the science database (needs Sim.Init() and Radiation.Init() first)
                    Science.Init();                         // register the science hijacker

                    // static graphic components
                    LineRenderer.Init();
                    ParticleRenderer.Init();
                    Highlighter.Init();

                    // UI
                    Textures.Init();                                          // set up the icon textures
                    UI.Init();                                                // message system, main gui, launcher
                    KsmGui.KsmGuiMasterController.Init();                     // setup the new gui framework

                    // part prefabs hacks
                    Profile.SetupPods();                     // add supply resources to pods
                    Misc.PartPrefabsTweaks();                // part prefabs tweaks, must be called after ScienceDB.Init()

                    // Create KsmGui windows
                    new ScienceArchiveWindow();

                    // GameEvents callbacks
                    Callbacks = new Callbacks();
                }
                catch (Exception e)
                {
                    string fatalError = "FATAL ERROR : Kerbalism core init has failed :" + "\n" + e.ToString();
                    Lib.Log(fatalError, Lib.LogLevel.Error);
                    LoadFailedPopup(fatalError);
                }

                IsCoreGameInitDone = true;
            }

            // everything in there will be called every time a savegame (or a new game) is loaded from the main menu
            if (!IsSaveGameInitDone)
            {
                try
                {
                    Cache.Init();
                    ResourceCache.Init();

                    // prepare storm data
                    foreach (CelestialBody body in FlightGlobals.Bodies)
                    {
                        if (Storm.Skip_body(body))
                        {
                            continue;
                        }
                        Storm_data sd = new Storm_data {
                            body = body
                        };
                        storm_bodies.Add(sd);
                    }
                }
                catch (Exception e)
                {
                    string fatalError = "FATAL ERROR : Kerbalism save game init has failed :" + "\n" + e.ToString();
                    Lib.Log(fatalError, Lib.LogLevel.Error);
                    LoadFailedPopup(fatalError);
                }

                IsSaveGameInitDone = true;
            }

            // eveything else will be called on every OnLoad() call :
            // - save/load
            // - every scene change
            // - in various semi-random situations (thanks KSP)

            // Fix for background IMGUI textures being dropped on scene changes since KSP 1.8
            Styles.ReloadBackgroundStyles();

            // always clear the caches
            Cache.Clear();
            ResourceCache.Clear();

            // deserialize our database
            try
            {
                UnityEngine.Profiling.Profiler.BeginSample("Kerbalism.DB.Load");
                DB.Load(node);
                UnityEngine.Profiling.Profiler.EndSample();
            }
            catch (Exception e)
            {
                string fatalError = "FATAL ERROR : Kerbalism save game load has failed :" + "\n" + e.ToString();
                Lib.Log(fatalError, Lib.LogLevel.Error);
                LoadFailedPopup(fatalError);
            }

            // I'm smelling the hacky mess in here.
            Communications.NetworkInitialized  = false;
            Communications.NetworkInitializing = false;

            // detect if this is a different savegame
            if (DB.uid != savegame_uid)
            {
                // clear caches
                Message.all_logs.Clear();

                // sync main window pos from db
                UI.Sync();

                // remember savegame id
                savegame_uid = DB.uid;
            }

            Kerbalism.gameLoadTime = Time.time;
        }