Ejemplo n.º 1
0
        public static void SaveHostData(MCMHost host)
        {
            var filePath = HostFilePath(host);

            // Open it for writing
            try
            {
                Scribe.InitWriting(filePath, "ModConfigurationData");
                if (Scribe.mode == LoadSaveMode.Saving)
                {
                    // Write this library version as the one saved with
                    string version = Version.Current.ToString();
                    Scribe_Values.LookValue <string>(ref version, "ccl_version");

                    // Call the worker scribe
                    Scribe_Deep.LookDeep <MCMHost>(ref host, host.key);
                }
            }
            catch (Exception e)
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()),
                    "Mod Configuration Menu");
            }
            finally
            {
                // Finish
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
                Messages.Message("ModConfigurationSaved".Translate(host.Label), MessageSound.Standard);
            }
            host.OpenedThisSession = false;
        }
Ejemplo n.º 2
0
        public static void SaveToXML(Blueprint blueprint)
        {
            try
            {
                try
                {
                    Scribe.InitWriting(FullSaveLocation(blueprint.name), "Blueprint");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("ProblemSavingFile".Translate(ex.ToString()));
                    throw;
                }
                ScribeMetaHeaderUtility.WriteMetaHeader();

                Scribe_Deep.LookDeep(ref blueprint, "Blueprint");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving blueprint: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
            }

            // set exported flag.
            blueprint.exported = true;
        }
        private void DoExport(string name)
        {
            try
            {
                try
                {
                    Scribe.InitWriting(FilePath(name), "ManagerJobs");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("ProblemSavingFile".Translate(ex.ToString()));
                    throw;
                }

                ScribeMetaHeaderUtility.WriteMetaHeader();

                _jobStackIO = Manager.For(manager).JobStack;
                Scribe_Deep.LookDeep(ref _jobStackIO, "JobStack");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving jobstack: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
                Messages.Message("FM.JobsExported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
Ejemplo n.º 4
0
        public static void save(List <Thing> thingsToSave, string fileLocation, Thing source)
        {
            Log.Message("Saving to: " + fileLocation);
            Scribe.InitWriting(fileLocation, "Stargate");

            //Log.Message("Starting Save");
            //Save Pawn

            //Scribe_Collections.LookList<Thing>(ref thingsToSave, "things", LookMode.Deep, (object)null);

            //Scribe.EnterNode("map");
            //Scribe.EnterNode("things");
            //source.ExposeData();
            Scribe_Collections.LookList <Thing>(ref thingsToSave, "things", LookMode.Deep, (object)null);
            //Scribe.ExitNode();

            //Scribe.ExitNode();

            /*
             * for (int i = 0; i < thingsToSave.Count; i++)
             * {
             *  Scribe_Deep.LookDeep<Thing>(ref thingsToSave[i], thingsToSave[i].ThingID);
             * }*/

            Scribe.FinalizeWriting();
            Scribe.mode = LoadSaveMode.Inactive;
            //Log.Message("End Save");
        }
Ejemplo n.º 5
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.º 6
0
 public static void SaveToFile(ref Blueprint bp, string fileName)
 {
     try
     {
         Scribe.InitWriting(BlueprintFiles.FilePathForSavedBlueprint(fileName), "blueprint");
         bp.BpName = fileName;
         Scribe_Deep.LookDeep(ref bp, "Blueprint");
     }
     catch (Exception e)
     {
         Log.Error("Failed to save blueprint");
         throw e;
     }
     finally
     {
         Scribe.FinalizeWriting();
         Scribe.mode = LoadSaveMode.Inactive;
     }
 }
        //
        // Static Methods
        //
        public static void SaveToFile(PrepareCarefully loadout, Page_ConfigureStartingPawnsCarefully page, string colonistName)
        {
            try {
                Scribe.InitWriting(ColonistFiles.FilePathForSavedColonist(colonistName), "colonist");
                string versionStringFull = "3";
                Scribe_Values.LookValue <string>(ref versionStringFull, "version", null, false);
                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);

                SaveRecordPawnV3 pawn = new SaveRecordPawnV3(page.SelectedPawn);
                Scribe_Deep.LookDeep <SaveRecordPawnV3>(ref pawn, "colonist");
            }
            catch (Exception e) {
                Log.Error("Failed to save preset file");
                throw e;
            }
            finally {
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
Ejemplo n.º 8
0
        public static void SaveFromPathCall(Map map, IntVec3 startVec, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode)
        {
            CellRect destinationRect;

            if (dest.HasThing && peMode != PathEndMode.OnCell)
            {
                destinationRect = dest.Thing.OccupiedRect();
            }
            else
            {
                destinationRect = CellRect.SingleCell(dest.Cell);
            }

            var dumper = new PathDataLog
            {
                mapSize         = map.Size,
                start           = startVec,
                dest            = destinationRect,
                peMode          = peMode,
                tpMode          = traverseParms.mode,
                tpMaxDanger     = traverseParms.maxDanger,
                tpCanBash       = traverseParms.canBash,
                tpMoveCardinal  = traverseParms.pawn?.TicksPerMoveCardinal ?? -1,
                tpMoveDiagonal  = traverseParms.pawn?.TicksPerMoveDiagonal ?? -1,
                pathGrid        = map.pathGrid.pathGrid,
                fakeEdificeGrid = new ByteGrid(map),
                avoidGrid       = traverseParms.pawn?.GetAvoidGrid(),
                allowedArea     = traverseParms.pawn?.playerSettings?.AreaRestrictionInPawnCurrentMap
            };

            foreach (var cell in map.AllCells)
            {
                var rb    = cell.GetRegionBarrier(map);
                int value = Edifice_None;
                if (rb != null)
                {
                    var door = rb as Building_Door;
                    if (door != null)
                    {
                        switch (traverseParms.mode)
                        {
                        case TraverseMode.ByPawn:
                            if (!traverseParms.canBash && door.IsForbiddenToPass(traverseParms.pawn))
                            {
                                value = Edifice_NonTraversableDoor;
                            }
                            else if (!door.FreePassage)
                            {
                                value = door.PawnCanOpen(traverseParms.pawn) ? door.TicksToOpenNow : Edifice_NonTraversableDoor;
                            }
                            else
                            {
                                value = 0;
                            }
                            break;

                        case TraverseMode.NoPassClosedDoors:
                            value = !door.FreePassage ? Edifice_NonTraversableDoor : 0;
                            break;
                        }
                    }
                    else if ((rb as Building)?.PathFindCostFor(traverseParms.pawn) > 0)
                    {
                        value = Edifice_KnownArmedTrap;
                    }
                    else
                    {
                        value = Edifice_Impassible;
                    }
                }
                dumper.fakeEdificeGrid[cell] = (byte)value;
            }

            var savePath = Path.Combine(GenFilePaths.DevOutputFolderPath, $"{traverseParms.pawn} - {Find.TickManager.TicksAbs}");

            if (File.Exists(savePath + ".xml"))
            {
                savePath = savePath + " ";
                int saveNum = 1;
                while (File.Exists(savePath + saveNum + ".xml"))
                {
                    saveNum++;
                }
                savePath = savePath + saveNum;
            }
            try
            {
                SaveGame(savePath);
                try
                {
                    Scribe.InitWriting(savePath + ".xml", "PathDataLog");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("Stuff went wrong " + ex);
                    throw;
                }
                ScribeMetaHeaderUtility.WriteMetaHeader();

                Scribe_Deep.LookDeep(ref dumper, "PathData");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
            }
        }