예제 #1
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();
            }
        }
예제 #2
0
        public static void FinalizeLoading()
        {
            if (!loading)
            {
                Log.Error("Called FinalizeLoading() but we aren't loading");
                return;
            }

            ScribeLoader loader = Scribe.loader;

            try
            {
                Scribe.ExitNode();

                loader.curXmlParent       = null;
                loader.curParent          = null;
                loader.curPathRelToParent = null;
                loader.crossRefs.ResolveAllCrossReferences();
                loader.initer.DoAllPostLoadInits();
            }
            catch (Exception e)
            {
                Log.Error("Exception in FinalizeLoading(): " + e);
                loader.ForceStop();
                throw;
            }
            finally
            {
                loading = false;
            }
        }
 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);
     }
 }
예제 #4
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);
                    }
                }
            }
        }
예제 #5
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);
        }
예제 #6
0
 public override void PostExposeData()
 {
     Scribe.EnterNode(nameof(CompStatBattery));
     base.PostExposeData();
     Scribe_Values.Look(ref ticksToExplode, "ticksToExplode");
     Scribe.ExitNode();
 }
        public void ExposeData()
        {
            Scribe_Values.Look(ref UniqueId, "uniqueID", -1);
            Scribe_Values.Look(ref Color, "color", Color.white);

            switch (Scribe.mode)
            {
            case LoadSaveMode.LoadingVars when Scribe.EnterNode("faction"):
                this.ColonyFaction = new Faction();

                this.ColonyFaction.ExposeData();
                Scribe.ExitNode();
                break;

            case LoadSaveMode.LoadingVars:
                Log.Error("No faction for colony found. Corrupt colony save?");
                break;

            case LoadSaveMode.Saving:
                Scribe_Deep.Look <Faction>(ref ColonyFaction, "faction");
                break;
            }

            Scribe_Deep.Look(ref Leader, "leader");

            Scribe_Collections.Look(ref ActiveWorldTiles, "activeWorldTiles");
        }
        /// <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...");
        }
 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();
 }
예제 #10
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());
        }
예제 #11
0
 public static void ExposeDataPatch(object __instance)
 {
     if (Scribe.EnterNode("animalGenetics"))
     {
         GetDataOrCreate(__instance).ExposeData();
         Scribe.ExitNode();
     }
 }
예제 #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
        }
예제 #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
            }
        }
예제 #14
0
        public override void CompExposeData()
        {
            base.CompExposeData();

            if (Scribe.EnterNode("animalGenetics"))
            {
                Scribe_References.Look(ref _geneticInformation, "fatherGeneRecords");
                Scribe.ExitNode();
            }
        }
예제 #15
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
            }
        }
예제 #17
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();
            }
        }
예제 #19
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
            }
        }
예제 #20
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
        }
예제 #21
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);
     }
 }
예제 #22
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();
     }
 }
예제 #23
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
            }
        }
예제 #25
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();
 }
예제 #26
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;
            }
        }
예제 #27
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();
            }
        }
예제 #28
0
        public override void ExposeData()
        {
            if (Verse.Scribe.mode == LoadSaveMode.Saving)
            {
                BackwardsCompatData = new Dictionary <Thing, StatGroup>();
                _Things             = new List <Thing>();
                _StatGroups         = new List <StatGroup>();
                System.GC.Collect();
                foreach (GeneticInformation gi in GeneticInformation.Instances)
                {
                    BackwardsCompatData[gi.parent] = new StatGroup(gi);
                }
            }

            Scribe_Collections.Look(ref BackwardsCompatData, "data", LookMode.Reference, LookMode.Deep, ref _Things, ref _StatGroups);

            if (Scribe.EnterNode("settings"))
            {
                Settings.ExposeData();
                Scribe.ExitNode();
            }
        }
예제 #29
0
        internal static Blueprint LoadFromXML(SaveFileInfo file)
        {
            // set up empty blueprint
            Blueprint blueprint = new Blueprint();

#if DEBUG
            Log.Message("Attempting to load from: " + file.FileInfo.FullName);
#endif

            // load stuff
            try
            {
                Scribe.InitLoading(BlueprintSaveLocation + "/" + file.FileInfo.Name);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
                Scribe.EnterNode("Blueprint");
                blueprint.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading blueprint: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            // if a def used in the blueprint doesn't exist, exposeData will throw an error,
            // which is fine. in addition, it'll set the field to null - which may result in problems down the road.
            // Make sure each item in the blueprint has a def set, if not - remove it.
            // This check itself will throw another error, which is also fine. User will have to resolve the issue manually.
            blueprint.contents = blueprint.contents.Where(item => item.BuildableDef != null).ToList();

            // return blueprint.
            return(blueprint);
        }
예제 #30
0
 public static void FinalizeLoading()
 {
     if (Scribe.mode != LoadSaveMode.LoadingVars)
     {
         Log.Error("Called FinalizeLoading() but current mode is " + Scribe.mode, false);
         return;
     }
     try {
         Scribe.ExitNode();
         Scribe.loader.curXmlParent       = null;
         Scribe.loader.curParent          = null;
         Scribe.loader.curPathRelToParent = null;
         Scribe.mode = LoadSaveMode.Inactive;
         ResolveAllCrossReferences();
         //Scribe.loader.crossRefs.ResolveAllCrossReferences();
         Scribe.loader.initer.DoAllPostLoadInits();
     }
     catch (Exception arg) {
         Log.Error("Exception in FinalizeLoading(): " + arg, false);
         Scribe.loader.ForceStop();
         throw;
     }
 }