Ejemplo n.º 1
0
 public override void PostExposeData()
 {
     Scribe.EnterNode(nameof(CompStatBattery));
     base.PostExposeData();
     Scribe_Values.Look(ref ticksToExplode, "ticksToExplode");
     Scribe.ExitNode();
 }
 public static void Look(ref BodyPartRecord part, string label, BodyPartRecord defaultValue = null)
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         if (part == defaultValue || !Scribe.EnterNode(label))
         {
             return;
         }
         try
         {
             if (part == null)
             {
                 Scribe.saver.WriteAttribute("IsNull", "True");
                 return;
             }
             string value = part.body.defName;
             Scribe_Values.Look(ref value, "body");
             int value2 = part.Index;
             Scribe_Values.Look(ref value2, "index", 0, forceSave: true);
         }
         finally
         {
             Scribe.ExitNode();
         }
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         part = ScribeExtractor.BodyPartFromNode(Scribe.loader.curXmlParent[label], label, defaultValue);
     }
 }
        /// <summary>
        /// Loads some colony information for loading screens.
        /// </summary>
        public void LoadColonies()
        {
            if (Scribe.mode != LoadSaveMode.LoadingVars || ScribeMultiLoader.Empty())
            {
                this.PreloadWorldColoniesMaps();
            }

            var colonyFiles = new DirectoryInfo(this.coloniesDirectory).GetFiles("*" + PersistentWorldColonyFileExtension);

            Log.Message("Loading colonies...");

            foreach (var colonyFile in colonyFiles)
            {
                this.SetCurrentFile(colonyFile);

                ScribeMultiLoader.SetScribeCurXmlParentByFilePath(colonyFile.FullName);

                var colony = new PersistentColony()
                {
                    FileInfo = colonyFile
                };

                if (Scribe.EnterNode("colony"))
                {
                    Scribe_Deep.Look(ref colony.ColonyData, "data");

                    Scribe.ExitNode();
                }

                this.persistentWorld.Colonies.Add(colony);
            }

            Log.Message("Loaded colony data...");
        }
Ejemplo n.º 4
0
        public static PathDataLog LoadFromFile(string filename)
        {
            var pathData = new PathDataLog();

            try
            {
                Scribe.InitLoading(filename);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("PathData");
                pathData.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            return(pathData);
        }
Ejemplo n.º 5
0
        public static void ExposeCompatibilityList()
        {
            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                isLoadedGame = true;

                saveModIDsHash = ScribeMetaHeaderUtility.loadedModIdsList.Select(s => s.StripModID()).Where(m => ModUtil.IsActive(m)).ToHashSet();
            }

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                PrepareForSaving();
            }

            if (Scribe.EnterNode("modBackCompatibility"))
            {
                try
                {
                    Scribe_Collections.Look(ref compatibilityEntries, "installed", LookMode.Deep);
                }
                finally
                {
                    Scribe.ExitNode();
                }
            }
            else if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                compatibilityEntries.Clear();
            }
        }
 public override void PostExposeData()
 {
     base.PostExposeData();
     Scribe.EnterNode("CompUpgrade_" + Props.upgradeTypeName);
     Scribe_Values.Look(ref complete, "complete", false, false);
     if (!complete)
     {
         Scribe_Values.Look(ref workAccum, "workAccum", 0f, false);
         Scribe_Values.Look(ref beginUpgrade, "beginUpgrade", false, false);
         Scribe_Deep.Look(ref this.ingredients, "ingredients");
     }
     if (ingredients == null)
     {
         ingredients = new ThingOwner <Thing>(this);
     }
     if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         //Use this to apply update in save-loading
         //so that compdetection does not need to save any data
         if (complete)
         {
             PostUpgrade(true);
         }
     }
     Scribe.ExitNode();
 }
Ejemplo n.º 7
0
        public static XmlDocument SaveGame()
        {
            SaveCompression.doSaveCompression = true;

            ScribeUtil.StartWritingToDoc();

            Scribe.EnterNode("savegame");
            ScribeMetaHeaderUtility.WriteMetaHeader();
            Scribe.EnterNode("game");
            int currentMapIndex = Current.Game.currentMapIndex;

            Scribe_Values.Look(ref currentMapIndex, "currentMapIndex", -1);
            Current.Game.ExposeSmallComponents();
            World world = Current.Game.World;

            Scribe_Deep.Look(ref world, "world");
            List <Map> maps = Find.Maps;

            Scribe_Collections.Look(ref maps, "maps", LookMode.Deep);
            Find.CameraDriver.Expose();
            Scribe.ExitNode();

            SaveCompression.doSaveCompression = false;

            return(ScribeUtil.FinishWritingToDoc());
        }
Ejemplo n.º 8
0
        public override void PostExposeData()
        {
            base.PostExposeData();
            if (!(parent is Pawn pawn))
            {
                return;
            }

            if (Scribe.EnterNode("animalGenetics"))
            {
                Scribe_Collections.Look(ref _geneRecords, "geneRecords", LookMode.Def, LookMode.Deep);
                Scribe.ExitNode();
            }

            // Backwards Compat Load
            if (Verse.Scribe.mode != LoadSaveMode.Saving)
            {
                if (_geneRecords == null)
                {
                    var animalGeneticsWorldComponent = Find.World.GetComponent <AnimalGenetics>();
                    if (animalGeneticsWorldComponent.BackwardsCompatData.ContainsKey(pawn))
                    {
                        _geneRecords = new Dictionary <StatDef, GeneRecord>(animalGeneticsWorldComponent.BackwardsCompatData[pawn].Data);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static bool PreFLoadGameFromSaveFile(string fileName)
        {
            string str = GenText.ToCommaList(from mod in LoadedModManager.RunningMods
                                             select mod.ToString(), true);

            Log.Message("Loading game from file " + fileName + " with mods " + str);
            DeepProfiler.Start("Loading game from file " + fileName);
            Current.Game = new Game();
            DeepProfiler.Start("InitLoading (read file)");
            Scribe.loader.InitLoading(GenFilePaths.FilePathForSavedGame(fileName));
            DeepProfiler.End();
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
            bool flag = !Scribe.EnterNode("Κgame");
            bool result;

            if (flag)
            {
                Log.Error("Could not find DTMG XML node.");
                Scribe.ForceStop();
                GenScene.GoToMainMenu();
                Messages.Message("Game MUST be created with 'Don't Tempt Me!' loaded. Please select a 'Don't Tempt Me!' save game file.", MessageTypeDefOf.RejectInput);
                result = false;
            }
            else
            {
                Current.Game = new Game();
                Current.Game.LoadGame();
                PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
                DeepProfiler.End();
                result = false;
            }
            return(result);
        }
Ejemplo n.º 10
0
 public static byte[] WriteExposable(IExposable element, string name = RootNode, bool indent = false, Action beforeElement = null)
 {
     StartWriting(indent);
     Scribe.EnterNode(RootNode);
     beforeElement?.Invoke();
     Scribe_Deep.Look(ref element, name);
     return(FinishWriting());
 }
Ejemplo n.º 11
0
 public static void ExposeDataPatch(object __instance)
 {
     if (Scribe.EnterNode("animalGenetics"))
     {
         GetDataOrCreate(__instance).ExposeData();
         Scribe.ExitNode();
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Exposes the data.
        /// Called with Scribe.mode = LoadingVars after Initialize()
        /// Called with Scribe.mode = SavingVars when the main MCM is closed
        /// </summary>
        public override void                ExposeData()
        {
            Scribe_Values.LookValue(ref MiniMap.MiniMapController.visible, "visible");

            #region Handle all MiniMaps and Overlays

            foreach (var minimap in Controller.Data.MiniMaps)
            {
                if (minimap.IsOrHasIConfigurable)
                {
                    #region Minimap Header
                    Scribe.EnterNode(minimap.SaveKey);
                    #endregion

                    #region Handle MiniMap IConfigurable
                    var iMinimap = minimap as IConfigurable;
                    if (iMinimap != null)
                    {
                        iMinimap.ExposeData();
                    }
                    #endregion

                    #region Handle all MiniMap Overlays
                    foreach (var overlay in minimap.overlayWorkers)
                    {
                        var iOverlay = overlay as IConfigurable;
                        if (iOverlay != null)
                        {
                            #region Overlay Header
                            var saveKey = overlay.SaveKey;
                            if (
                                (string.IsNullOrEmpty(saveKey)) ||
                                (!Scribe.EnterNode(saveKey))
                                )
                            {
                                continue;
                            }
                            #endregion

                            #region Handle Overlay IConfigurable
                            iOverlay.ExposeData();
                            #endregion

                            #region Finalize Overlay
                            Scribe.ExitNode();
                            #endregion
                        }
                    }
                    #endregion

                    #region Finalize Minimap
                    Scribe.ExitNode();
                    #endregion
                }
            }

            #endregion
        }
Ejemplo n.º 13
0
        private void                    ExposeDataLoad()
        {
            bool hidden = true; // Don't really need to set this but the compiler complains if we don't

            foreach (var minimap in Controller.Data.MiniMaps)
            {
                if (
                    (minimap.miniMapDef.dynamicOverlays) ||
                    (!Scribe.curParent.HasChildNode(minimap.miniMapDef.defName))
                    )
                {   // Dynamic minimap overlays or no saved data for this minimap
                    continue;
                }

                #region Minimap Header

                Scribe.EnterNode(minimap.miniMapDef.defName);

                #endregion

                Scribe_Values.LookValue(ref hidden, "hidden");
                minimap.Hidden = hidden;

                #region Handle all MiniMap Overlays

                foreach (var overlay in minimap.overlayWorkers)
                {
                    if (!Scribe.curParent.HasChildNode(overlay.overlayDef.defName))
                    {   // No saved data for this overlay
                        continue;
                    }

                    #region Overlay Header

                    Scribe.EnterNode(overlay.overlayDef.defName);

                    #endregion

                    Scribe_Values.LookValue(ref hidden, "hidden");
                    overlay.Hidden = hidden;

                    #region Finalize Overlay

                    Scribe.ExitNode();

                    #endregion
                }

                #endregion

                #region Finalize Minimap

                Scribe.ExitNode();

                #endregion
            }
        }
Ejemplo n.º 14
0
        public T Test <T>()
            where T : new()
        {
            Scribe.EnterNode(rootElementName);
            var thing = new T();

            Scribe_Deep.Look <T>(ref thing, "saveable", new object[0]);
            return(thing);
        }
Ejemplo n.º 15
0
        public override void CompExposeData()
        {
            base.CompExposeData();

            if (Scribe.EnterNode("animalGenetics"))
            {
                Scribe_References.Look(ref _geneticInformation, "fatherGeneRecords");
                Scribe.ExitNode();
            }
        }
Ejemplo n.º 16
0
        public override void ExposeData()
        {
            GeneticInformation.ExposeData();

            if (Scribe.EnterNode("settings"))
            {
                Settings.ExposeData();
                Scribe.ExitNode();
            }
        }
        private void                    ExposeDataLoad()
        {
            bool hidden = true; // Don't really need to set this but the compiler complains if we don't

            foreach (var minimap in Controller.Data.MiniMaps)
            {
                #region Minimap Header
                if (!Scribe.EnterNode(minimap.SaveKey))
                {   // No saved data for this minimap
                    continue;
                }
                #endregion

                Scribe_Values.LookValue(ref hidden, "hidden", minimap.miniMapDef.hiddenByDefault, true);
                minimap.Hidden = hidden;

                if (minimap.miniMapDef.dynamicOverlays)
                {   // Rebuild overlays for minimap
                    minimap.Reset();
                }

                #region Handle all MiniMap Overlays

                foreach (var overlay in minimap.overlayWorkers)
                {
                    #region Overlay Header
                    var saveKey = overlay.SaveKey;
                    if (
                        (string.IsNullOrEmpty(saveKey)) ||
                        (!Scribe.EnterNode(saveKey))
                        )
                    {   // No saved data for this overlay
                        continue;
                    }
                    #endregion

                    Scribe_Values.LookValue(ref hidden, "hidden", overlay.overlayDef.hiddenByDefault, true);
                    overlay.Hidden = hidden;

                    #region Finalize Overlay
                    Scribe.ExitNode();
                    #endregion
                }

                #endregion

                #region Finalize Minimap

                Scribe.ExitNode();

                #endregion
            }
        }
Ejemplo n.º 18
0
        public static void LookDictionary <K, V>(ref Dictionary <K, V> dict, string dictLabel, LookMode keyLookMode = LookMode.Undefined,
                                                 LookMode valueLookMode = LookMode.Undefined)
        {
            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                return;
            }

            Scribe.EnterNode(dictLabel);

            var list1 = new List <K>();
            var list2 = new List <V>();

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                if (dict == null)
                {
                    throw new ArgumentNullException("dict");
                }

                foreach (var v in dict)
                {
                    list1.Add(v.Key);
                    list2.Add(v.Value);
                }
            }

            Scribe_Collections.LookList(ref list1, "keys", keyLookMode);
            Scribe_Collections.LookList(ref list2, "values", valueLookMode);

            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                if (dict == null)
                {
                    dict = new Dictionary <K, V>();
                }
                else
                {
                    dict.Clear();
                }

                if (list1 != null && list2 != null)
                {
                    for (var index = 0; index < list1.Count; ++index)
                    {
                        dict.Add(list1[index], list2[index]);
                    }
                }
            }

            Scribe.ExitNode();
        }
        private void DoImport(SaveFileInfo file)
        {
            try
            {
                // load stuff
                Scribe.InitLoading(_folder + "/" + file.FileInfo.Name);
                Manager.LoadSaveMode = Manager.Modes.ImportExport;
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("JobStack");
                _jobStackIO.ExposeData();
                Scribe.ExitNode();
                Scribe.FinalizeLoading();

                // resolve crossreferences
                // these are registered during the loading stage, and cleared afterwards
                // will most definitely give errors/warnings on crossgame imports
                CrossRefResolver.ResolveAllCrossReferences();

                // replace the old jobstack
                Manager.For(manager).NewJobStack(_jobStackIO);

                // remove invalid jobs
                var invalid = 0;
                foreach (ManagerJob job in Manager.For(manager).JobStack.FullStack())
                {
                    if (!job.IsValid)
                    {
                        invalid++;
                        job.Delete(false);
                    }
                }

                // provide some feedback on failed import(s)
                // if debug is enabled the screen will also pop up with reference errors.
                if (invalid > 0)
                {
                    Messages.Message("FM.InvalidJobsDeleted".Translate(invalid), MessageSound.SeriousAlert);
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading jobstack: " + e);
            }
            finally
            {
                // done?
                Scribe.mode          = LoadSaveMode.Inactive;
                Manager.LoadSaveMode = Manager.Modes.Normal;
                Messages.Message("FM.JobsImported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
Ejemplo n.º 20
0
        private void                    ExposeDataSave()
        {
            bool hidden;

            foreach (var minimap in Controller.Data.MiniMaps)
            {
                // Note: Minimaps with dynamic overlays break scribing because they have
                // a machine generated defName which may not be the same after load.
                if (minimap.miniMapDef.dynamicOverlays)
                {
                    continue;
                }

                #region Minimap Header

                Scribe.EnterNode(minimap.miniMapDef.defName);

                #endregion

                hidden = minimap.Hidden;
                Scribe_Values.LookValue(ref hidden, "hidden");

                #region Handle all MiniMap Overlays

                foreach (var overlay in minimap.overlayWorkers)
                {
                    #region Overlay Header

                    Scribe.EnterNode(overlay.overlayDef.defName);

                    #endregion

                    hidden = overlay.Hidden;
                    Scribe_Values.LookValue(ref hidden, "hidden");

                    #region Finalize Overlay

                    Scribe.ExitNode();

                    #endregion
                }

                #endregion

                #region Finalize Minimap

                Scribe.ExitNode();

                #endregion
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Exposes the data.
        /// Called with Scribe.mode = LoadingVars after Initialize()
        /// Called with Scribe.mode = SavingVars when the main MCM is closed
        /// </summary>
        public override void                ExposeData()
        {
            Scribe_Values.LookValue(ref MiniMap.MiniMapController.visible, "visible");

            #region Handle all MiniMaps and Overlays

            foreach (var minimap in Controller.Data.MiniMaps)
            {
                if (minimap.IsOrHasIConfigurable)
                {
                    #region Minimap Header
                    Scribe.EnterNode(minimap.miniMapDef.defName);
                    #endregion

                    #region Handle MiniMap IConfigurable
                    var iMinimap = minimap as IConfigurable;
                    if (iMinimap != null)
                    {
                        iMinimap.ExposeData();
                    }
                    #endregion

                    #region Handle all MiniMap Overlays
                    foreach (var overlay in minimap.overlayWorkers)
                    {
                        var iOverlay = overlay as IConfigurable;
                        if (iOverlay != null)
                        {
                            #region Overlay Header
                            Scribe.EnterNode(overlay.overlayDef.defName);
                            #endregion

                            #region Handle Overlay IConfigurable
                            iOverlay.ExposeData();
                            #endregion

                            #region Finalize Overlay
                            Scribe.ExitNode();
                            #endregion
                        }
                    }
                    #endregion

                    #region Finalize Minimap
                    Scribe.ExitNode();
                    #endregion
                }
            }

            #endregion
        }
Ejemplo n.º 22
0
 public static void Look <T>(ref T value, string label, T defaultValue = default(T), bool forceSave = false)
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         if (typeof(T) == typeof(TargetInfo))
         {
             Log.Error("Saving a TargetInfo " + label + " with Scribe_Values. TargetInfos must be saved with Scribe_TargetInfo.");
         }
         else if (typeof(Thing).IsAssignableFrom(typeof(T)))
         {
             Log.Error("Using Scribe_Values with a Thing reference " + label + ". Use Scribe_References or Scribe_Deep instead.");
         }
         else if (typeof(IExposable).IsAssignableFrom(typeof(T)))
         {
             Log.Error("Using Scribe_Values with a IExposable reference " + label + ". Use Scribe_References or Scribe_Deep instead.");
         }
         else if (typeof(Def).IsAssignableFrom(typeof(T)))
         {
             Log.Error("Using Scribe_Values with a Def " + label + ". Use Scribe_Defs instead.");
         }
         else
         {
             if (!forceSave && (value != null || defaultValue == null) && (value == null || value.Equals(defaultValue)))
             {
                 return;
             }
             if (value == null)
             {
                 if (Scribe.EnterNode(label))
                 {
                     try
                     {
                         Scribe.saver.WriteAttribute("IsNull", "True");
                     }
                     finally
                     {
                         Scribe.ExitNode();
                     }
                 }
             }
             else
             {
                 Scribe.saver.WriteElement(label, value.ToString());
             }
         }
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         value = ScribeExtractor.ValueFromNode(Scribe.loader.curXmlParent[label], defaultValue);
     }
 }
Ejemplo n.º 23
0
 public static void ScribeCustomList <T>(ref List <T> list, string label, Action <T> saver, Func <T> loader, IExposable caller)
 {
     Scribe.EnterNode("events");
     try
     {
         if (Scribe.mode == LoadSaveMode.Saving)
         {
             foreach (T e in list)
             {
                 Scribe.EnterNode("li");
                 try
                 {
                     saver.Invoke(e);
                 }
                 finally
                 {
                     Scribe.ExitNode();
                 }
             }
         }
         else if (Scribe.mode == LoadSaveMode.LoadingVars)
         {
             XmlNode curXmlParent = Scribe.loader.curXmlParent;
             list = new List <T>();
             foreach (object obj in curXmlParent.ChildNodes)
             {
                 XmlNode    subNode            = (XmlNode)obj;
                 XmlNode    oldXmlParent       = Scribe.loader.curXmlParent;
                 IExposable oldParent          = Scribe.loader.curParent;
                 string     oldPathRelToParent = Scribe.loader.curPathRelToParent;
                 Scribe.loader.curPathRelToParent = null;
                 Scribe.loader.curParent          = caller;
                 Scribe.loader.curXmlParent       = subNode;
                 try
                 {
                     list.Add(loader.Invoke());
                 }
                 finally
                 {
                     Scribe.loader.curXmlParent       = oldXmlParent;
                     Scribe.loader.curParent          = oldParent;
                     Scribe.loader.curPathRelToParent = oldPathRelToParent;
                 }
             }
         }
     }
     finally
     {
         Scribe.ExitNode();
     }
 }
Ejemplo n.º 24
0
        public static void Look <T>(ref T[] list, string label, params object[] ctorArgs) where T : IExposable
        {
            if (Scribe.EnterNode(label) == false)
            {
                return;
            }

            try
            {
                if (Scribe.mode == LoadSaveMode.Saving)
                {
                    if (list == null)
                    {
                        Scribe.saver.WriteAttribute("IsNull", "True");
                    }
                    else
                    {
                        foreach (var current in list)
                        {
                            var t2 = current;
                            Scribe_Deep.Look <T>(ref t2, false, "li", ctorArgs);
                        }
                    }
                }
                else if (Scribe.mode == LoadSaveMode.LoadingVars)
                {
                    var curXmlParent = Scribe.loader.curXmlParent;
                    var xmlAttribute = curXmlParent.Attributes["IsNull"];
                    if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
                    {
                        list = null;
                    }
                    else
                    {
                        list = new T[curXmlParent.ChildNodes.Count];
                        var i = 0;
                        foreach (var subNode2 in curXmlParent.ChildNodes)
                        {
                            list[i++] = ScribeExtractor.SaveableFromNode <T>((XmlNode)subNode2, ctorArgs);
                        }
                    }
                }
            }
            finally
            {
                Scribe.ExitNode();
            }
        }
        private void                    ExposeDataSave()
        {
            bool hidden;

            foreach (var minimap in Controller.Data.MiniMaps)
            {
                #region Minimap Header
                if (!Scribe.EnterNode(minimap.SaveKey))
                {
                    continue;
                }
                #endregion

                hidden = minimap.Hidden;
                Scribe_Values.LookValue(ref hidden, "hidden", minimap.miniMapDef.hiddenByDefault, true);

                #region Handle all MiniMap Overlays

                foreach (var overlay in minimap.overlayWorkers)
                {
                    #region Overlay Header
                    var saveKey = overlay.SaveKey;
                    if (
                        (string.IsNullOrEmpty(saveKey)) ||
                        (!Scribe.EnterNode(overlay.SaveKey))
                        )
                    {
                        continue;
                    }
                    #endregion

                    hidden = overlay.Hidden;
                    Scribe_Values.LookValue(ref hidden, "hidden", overlay.overlayDef.hiddenByDefault, true);

                    #region Finalize Overlay
                    Scribe.ExitNode();
                    #endregion
                }

                #endregion

                #region Finalize Minimap
                Scribe.ExitNode();
                #endregion
            }
        }
Ejemplo n.º 26
0
 public override void PostExposeData()
 {
     base.PostExposeData();
     Scribe.EnterNode("CompUpgrade_" + Props.referenceId);
     Scribe_Values.Look(ref complete, "complete");
     if (!(Scribe.mode == LoadSaveMode.Saving && complete))
     {
         Scribe_Values.Look(ref workDone, "workDone");
         Scribe_Values.Look(ref wantsWork, "wantsWork");
         Scribe_Deep.Look(ref ingredients, "ingredients", this);
     }
     if (ingredients == null)
     {
         ingredients = new ThingOwner <Thing>(this);
     }
     Scribe.ExitNode();
 }
Ejemplo n.º 27
0
        static bool Prefix()
        {
            if (gameToLoad == null)
            {
                return(true);
            }

            SaveCompression.doSaveCompression = true;

            try
            {
                ScribeUtil.StartLoading(gameToLoad.SaveData);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("game");
                Current.Game = new Game();
                Current.Game.LoadGame(); // calls Scribe.loader.FinalizeLoading()
                SemiPersistent.ReadSemiPersistent(gameToLoad.SemiPersistent);
            }
            finally
            {
                SaveCompression.doSaveCompression = false;
                gameToLoad = null;
            }

            Log.Message("Game loaded");

            if (Multiplayer.Client != null)
            {
                LongEventHandler.ExecuteWhenFinished(() =>
                {
                    // Inits all caches
                    foreach (ITickable tickable in TickPatch.AllTickables.Where(t => !(t is ConstantTicker)))
                    {
                        tickable.Tick();
                    }

                    if (!Current.Game.Maps.Any())
                    {
                        MemoryUtility.UnloadUnusedUnityAssets();
                        Find.World.renderer.RegenerateAllLayersNow();
                    }
                });
            }

            return(false);
        }
Ejemplo n.º 28
0
        //
        // Static Methods
        //
        public static void SaveToFile(PrepareCarefully data, string presetName)
        {
            try {
                Scribe.InitWriting(PresetFiles.FilePathForSavedPreset(presetName), "preset");
                string versionStringFull = "3";
                Scribe_Values.LookValue <string>(ref versionStringFull, "version", null, false);
                bool usePoints      = data.Config.pointsEnabled;
                int  startingPoints = PrepareCarefully.Instance.StartingPoints;
                Scribe_Values.LookValue <bool>(ref usePoints, "usePoints", false, true);
                Scribe_Values.LookValue <int>(ref startingPoints, "startingPoints", 0, true);
                string modString = GenText.ToCommaList(Enumerable.Select <ModContentPack, string>(LoadedModManager.RunningMods, (Func <ModContentPack, string>)(mod => mod.Name)), true);
                Scribe_Values.LookValue <string>(ref modString, "mods", null, false);
                Scribe.EnterNode("colonists");
                foreach (CustomPawn customPawn in data.Pawns)
                {
                    SaveRecordPawnV3 pawn = new SaveRecordPawnV3(customPawn);
                    Scribe_Deep.LookDeep <SaveRecordPawnV3>(ref pawn, "colonist");
                }
                Scribe.ExitNode();

                Scribe.EnterNode("relationships");
                foreach (var r in data.RelationshipManager.ExplicitRelationships)
                {
                    SaveRecordRelationshipV3 s = new SaveRecordRelationshipV3(r);
                    Scribe_Deep.LookDeep <SaveRecordRelationshipV3>(ref s, "relationship");
                }
                Scribe.ExitNode();

                Scribe.EnterNode("equipment");
                foreach (var e in data.Equipment)
                {
                    SelectedEquipment customPawn = e;
                    Scribe_Deep.LookDeep <SelectedEquipment>(ref customPawn, "equipment");
                }
                Scribe.ExitNode();
            }
            catch (Exception e) {
                Log.Error("Failed to save preset file");
                throw e;
            }
            finally {
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
Ejemplo n.º 29
0
        public override void PostExposeData()
        {
            base.PostExposeData();

            if (Scribe.EnterNode("animalGenetics"))
            {
                Scribe_References.Look(ref GeneticInformation, "geneticInformation");

                GenesRecord legacyGenesRecord = null;
                Scribe_Collections.Look(ref legacyGenesRecord, "geneRecords");
                if (legacyGenesRecord != null)
                {
                    LegacyGenesRecords[this] = legacyGenesRecord;
                }

                if (Scribe.mode == LoadSaveMode.PostLoadInit)
                {
                    if (GeneticInformation == null)
                    {
                        if (LegacyGenesRecords.ContainsKey(this))
                        {
                            Log.Message("Migrating Legacy Genetic Information for " + parent.ToString());
                            GeneticInformation = new GeneticInformation(LegacyGenesRecords[this]);
                            LegacyGenesRecords.Remove(this);
                        }
                        else
                        {
                            Log.Message("Generating Genetic Information for " + parent.ToString());
                            GeneticInformation = new GeneticInformation(null);
                        }
                        GeneticCalculator.EnsureAllGenesExist(GeneticInformation.GeneRecords, null, null);
                    }
                    else
                    {
                        GeneticCalculator.EnsureAllGenesExist(GeneticInformation.GeneRecords, GeneticInformation.Mother, GeneticInformation.Father);
                    }
                }

                Scribe.ExitNode();
            }
        }
Ejemplo n.º 30
0
        public T FromXml <T>(string dataXML)
            where T : new()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(dataXML);
            Scribe.loader.curXmlParent = xmlDocument.DocumentElement;
            Scribe.mode = LoadSaveMode.LoadingVars;
            try
            {
                Scribe.EnterNode(rootElementName);
                var thing = new T();
                Scribe_Deep.Look <T>(ref thing, "saveable", new object[0]);
                return(thing);
            }
            finally
            {
                //Finish()
                Scribe.loader.FinalizeLoading();
            }
        }