public static bool LoadFromFile(PrepareCarefully loadout, Page_ConfigureStartingPawnsCarefully charMakerPage, string colonistName) { string version = ""; bool result = false; try { Scribe.InitLoading(ColonistFiles.FilePathForSavedColonist(colonistName)); Scribe_Values.LookValue <string>(ref version, "version", "unknown", false); } catch (Exception e) { Log.Error("Failed to load preset file"); throw e; } finally { Scribe.mode = LoadSaveMode.Inactive; } if ("2".Equals(version)) { Messages.Message("EdB.PrepareCarefully.SavedColonistVersionNotSupported".Translate(), MessageSound.SeriousAlert); return(false); } else if ("3".Equals(version)) { result = new ColonistLoaderVersion3().Load(loadout, charMakerPage, colonistName); } else { throw new Exception("Invalid preset version"); } return(result); }
public bool Load(PrepareCarefully loadout, Page_ConfigureStartingPawnsCarefully charMakerPage, string colonistName) { SaveRecordPawnV3 pawnRecord = new SaveRecordPawnV3(); string modString = ""; string version = ""; try { Scribe.InitLoading(ColonistFiles.FilePathForSavedColonist(colonistName)); Scribe_Values.LookValue <string>(ref version, "version", "unknown", false); Scribe_Values.LookValue <string>(ref modString, "mods", "", false); try { Scribe_Deep.LookDeep <SaveRecordPawnV3>(ref pawnRecord, "colonist", null); } catch (Exception e) { Messages.Message(modString, MessageSound.Silent); Messages.Message("EdB.ColonistLoadFailed".Translate(), MessageSound.RejectInput); Log.Warning(e.ToString()); Log.Warning("Colonist was created with the following mods: " + modString); return(false); } } catch (Exception e) { Log.Error("Failed to load preset file"); throw e; } finally { Scribe.mode = LoadSaveMode.Inactive; } PresetLoaderVersion3 loader = new PresetLoaderVersion3(); charMakerPage.AddColonist(loader.LoadPawn(pawnRecord)); if (loader.Failed) { Messages.Message(loader.ModString, MessageSound.Silent); Messages.Message("EdB.ColonistThingDefFailed".Translate(), MessageSound.SeriousAlert); Log.Warning("Preset was created with the following mods: " + modString); return(false); } return(true); }
// // 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; } }
public override void PostClose() { Page_ConfigureStartingPawnsCarefully charPage = Find.WindowStack.WindowOfType <Page_ConfigureStartingPawnsCarefully>(); if (charPage != null) { charPage.Show(); } else { Page_Equipment equipmentPage = Find.WindowStack.WindowOfType <Page_Equipment>(); if (equipmentPage != null) { equipmentPage.Show(); } else { Find.WindowStack.Add(new Page_ConfigureStartingPawnsCarefully()); } } GUI.FocusControl(null); }