示例#1
0
        static bool Prefix(ScribeSaver __instance)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            var writer = WriterField.GetValue(__instance);

            if (writer == null)
            {
                return(true);
            }

            var curPath = (string)CurPathField.GetValue(__instance);

            if (curPath.EndsWith("thing"))
            {
                // Reset thing index.
                ScribeSaver_EnterNode_Patch.ResetThingIndex();
            }

            var length = curPath.LastIndexOf('/');

            curPath = length <= 0 ? null : curPath.Substring(0, length);

            CurPathField.SetValue(__instance, curPath);

            return(true);
        }
        private void LoadWorld(string worldDir)
        {
            LongEventHandler.QueueLongEvent(delegate
            {
                normalClose = false;

                var previousGame = Current.Game;

                var persistentWorld       = new PersistentWorld();
                persistentWorld.LoadSaver = new PersistentWorldLoadSaver(persistentWorld, worldDir);

                // TODO: HMM
                PersistentWorldManager.GetInstance().PersistentWorld = persistentWorld;

                persistentWorld.LoadSaver.LoadWorld();

                Current.Game = previousGame;

                this.next = new Page_PersistentWorlds_LoadWorld_ColonySelection(persistentWorld)
                {
                    prev = this
                };
                this.DoNext();
            }, "FilUnderscore.PersistentRimWorlds.Loading.World", true, null);
        }
        private void OnNewWorld()
        {
            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            var nameWorldDialog = new Dialog_PersistentWorlds_NameWorld((name) =>
            {
                var worldDir = SaveFileUtils.Clone(persistentWorld.LoadSaver.GetWorldFolderPath(),
                                                   PersistentWorldLoadSaver.SaveDir + "/" + name);

                // Delete original world file.
                worldDir.GetFiles("*.pwf").Do(file => file.Delete());

                // Change original world name.
                persistentWorld.WorldData.Info.name = name;

                persistentWorld.LoadSaver =
                    new PersistentWorldLoadSaver(persistentWorld, worldDir.FullName);

                this.SaveWorld();

                this.LoadWorldsAsEntries();
            });

            Find.WindowStack.Add(nameWorldDialog);
        }
示例#4
0
        static void Prefix(Rect rect, List <ListableOption> optList)
        {
            if (!MainMenuMarker.drawing)
            {
                return;
            }

            if (Current.ProgramState != ProgramState.Playing ||
                !PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return;
            }

            int index;

            if ((index = optList.FindIndex(opt => opt.label == "Save".Translate())) == -1)
            {
                return;
            }

            optList.Insert(index,
                           new ListableOption("FilUnderscore.PersistentRimWorlds.Save.World".Translate(),
                                              () =>
            {
                Find.WindowStack.Add(new Dialog_PersistentWorlds_SaveWorld());
            }));
            optList.RemoveAt(index + 1);
        }
示例#5
0
        static bool Prefix(object obj, string label)
        {
            if (Scribe.mode != LoadSaveMode.Saving || !PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            // TODO: Please look at this spam.
            if (obj is Thing && !(obj is Pawn))
            {
                return(true);
            }

            if (obj == null || !(obj is ILoadReferenceable referenceable))
            {
                return(true);
            }

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;
            var loadSaver       = persistentWorld.LoadSaver;

            if (!loadSaver.ReferenceTable.ContainsReferenceWithLoadId(referenceable.GetUniqueLoadID()))
            {
                loadSaver.ReferenceTable.LoadReferenceIntoMemory(referenceable, label);
            }

            // Fix those warnings.
            var deepSaved = (HashSet <string>)deepSavedField.GetValue(Scribe.saver.loadIDsErrorsChecker);

            return(!deepSaved.Contains(referenceable.GetUniqueLoadID()));
        }
        private static void SortColonies(ref List <PersistentColony> colonies)
        {
            if (colonies == null || colonies.Count == 0)
            {
                return;
            }

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            if (Equals(colonies[0], persistentWorld.Colony))
            {
                return;
            }

            for (var i = 0; i < colonies.Count; i++)
            {
                var colony = colonies[i];

                if (i == 0 || !Equals(colony, persistentWorld.Colony))
                {
                    continue;
                }

                colonies.RemoveAt(i);
                colonies.Insert(0, colony);

                break;
            }
        }
        private static void SortColoniesOneTime(ref List <PersistentColony> colonies)
        {
            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            if (_sorted == persistentWorld.WorldData.ColonySortOption)
            {
                return;
            }

            persistentWorld.WorldData.ColonySortOption.Sort(ref colonies);

            colonies.Sort((x, y) =>
            {
                if (x.ColonyData.Favoured && !y.ColonyData.Favoured)
                {
                    return(-1);
                }
                else if (!x.ColonyData.Favoured && y.ColonyData.Favoured)
                {
                    return(1);
                }

                return(0);
            });

            _sorted = persistentWorld.WorldData.ColonySortOption;
        }
        private static void DrawSortingDropdown(Rect rect)
        {
            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;
            var sortingRect     = rect.RightPart(0.125f);

            Widgets.Dropdown(sortingRect, persistentWorld, world => world.WorldData.ColonySortOption, Button_GenerateMenu, persistentWorld.WorldData.ColonySortOption.Name);
        }
示例#9
0
        private void SaveWorld()
        {
            this.Close();

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            persistentWorld.SaveWorld();
        }
示例#10
0
        static bool Prefix()
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            return(Current.Game != null && Find.GameInfo != null && Find.World != null && Find.World.UI != null);
        }
        public override void PreOpen()
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                this.Close();
                return;
            }

            base.PreOpen();
        }
示例#12
0
        static void Postfix()
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || !PersistentWorldManager.GetInstance()
                .PersistentWorldNotNullAndLoadStatusIsNot(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame))
            {
                return;
            }

            PersistentWorldManager.GetInstance().PersistentWorld.UpdateWorld();
        }
        static bool Prefix()
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            return(PersistentWorldManager.GetInstance().PersistentWorldNotNull() && PersistentWorldManager.GetInstance()
                   .PersistentWorldNotNullAndLoadStatusIs(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Converting));
        }
        static bool Prefix(Game __instance, Map map)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || !PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIs(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame))
            {
                return(true);
            }

            // TODO: Patch. Can use map.isPlayerHome()

            return(true);
        }
        // Hope that no other mods use this method, otherwise we'll need to transpile for compatibility.
        static bool Prefix(Rect inRect)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            Widgets.Label(inRect, "FilUnderscore.PersistentRimWorlds.Warning.AdvancedCreationUnavailable".Translate());

            return(false);
        }
        static bool Prefix(LoadedObjectDirectory __instance, ILoadReferenceable reffable)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            var allObjectsByLoadID = (Dictionary <string, ILoadReferenceable>)AllObjectsByLoadIdField.GetValue(__instance);

            return(!allObjectsByLoadID.ContainsKey(reffable.GetUniqueLoadID()));
        }
        private void NewColony()
        {
            normalClose = false;

            PersistentWorldManager.GetInstance().PersistentWorld = this.persistentWorld;

            this.next = new Page_SelectScenario {
                prev = this
            };
            this.DoNext();
        }
示例#18
0
        static bool Prefix(string fileName)
        {
            // Is Persistent World being loaded??
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIsNot(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Finalizing))
            {
                return(true);
            }

            PersistentWorldManager.GetInstance().PersistentWorld.LoadWorld();

            return(false);
        }
示例#19
0
        static bool Prefix(Map __instance)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || !PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIsNot(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame))
            {
                return(true);
            }

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;
            var colony          = persistentWorld.Colony;

            return(colony == null || colony.ColonyData.ActiveWorldTiles.Contains(__instance.Tile));
        }
        public override void PostClose()
        {
            ColonyUI.Reset();

            if (!normalClose)
            {
                return;
            }

            this.DoBack();
            PersistentWorldManager.GetInstance().Clear();
        }
示例#21
0
        // TODO: Disallow saving through normal save menu.
        static bool Prefix(string fileName)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIs(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Converting))
            {
                return(true);
            }

            PersistentWorldManager.GetInstance().PersistentWorld.LoadSaver.SaveWorld();
            PersistentWorldManager.GetInstance().PersistentWorld.LoadSaver.Status = PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame;

            return(false);
        }
        static bool Prefix(ScribeLoader __instance)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || !PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIs(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Loading))
            {
                return(true);
            }

            ScribeVars.Set();

            ScribeVars.TrickScribe();

            return(false);
        }
示例#23
0
        static bool Prefix()
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || !PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIsNot(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Converting))
            {
                return(true);
            }

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            persistentWorld.ConstructGameWorldComponentsAndExposeComponents();

            return(false);
        }
        /**
         * CONVERT
         */

        public void Convert(Game game)
        {
            this.ConfigurePaths(SaveDir + "/" + game.World.info.name);
            this.CreateDirectoriesIfNotExistent();

            PersistentWorldManager.GetInstance().PersistentWorld.Convert(game);

            this.SaveWorld();

            GenScene.GoToMainMenu();

            this.Status = PersistentWorldLoadStatus.Uninitialized;
        }
        private void Load(int index)
        {
            this.Close();

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;
            var colony          = persistentWorld.Colonies[index];

            persistentWorld.Game.World.renderer.wantedMode = WorldRenderMode.None;

            var previousColony = persistentWorld.Colony;

            LongEventHandler.QueueLongEvent(delegate
            {
                persistentWorld.SaveColony();
            }, "FilUnderscore.PersistentRimWorlds.Saving.Colony", false, null);

            LongEventHandler.QueueLongEvent(delegate
            {
                persistentWorld.ConvertCurrentGameWorldObjects();

                persistentWorld.LoadSaver.SaveWorldData(true);
            }, "FilUnderscore.PersistentRimWorlds.Saving.World", false, null);

            LongEventHandler.QueueLongEvent(delegate
            {
                persistentWorld.LoadSaver.LoadColony(ref colony);
                persistentWorld.Colonies[index] = colony;

                colony.GameData.SetGame();
            }, "FilUnderscore.PersistentRimWorlds.Loading.Colony", true, null);

            LongEventHandler.QueueLongEvent(delegate
            {
                // TODO: Figure out how to load asynchronously to not lock up game.
                var maps = DynamicMapLoader.LoadColonyMaps(colony);

                Current.Game.CurrentMap = Current.Game.FindMap(maps.First().Tile);

                persistentWorld.UnloadColony(previousColony);

                persistentWorld.ConvertToCurrentGameWorldObjects();

                persistentWorld.SetPlayerFactionVarsToColonyFaction();
                persistentWorld.CheckAndSetColonyData();

                Find.CameraDriver.SetRootPosAndSize(colony.GameData.CamRootPos, colony.GameData.DesiredSize);

                persistentWorld.SchedulePause();
            }, "FilUnderscore.PersistentRimWorlds.Loading.Maps", false, null);
        }
示例#26
0
 static void Postfix(Game __instance)
 {
     if (PersistentWorldManager.GetInstance()
         .PersistentWorldNotNullAndLoadStatusIs(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Converting))
     {
         PersistentWorldManager.GetInstance().PersistentWorld.LoadSaver.Convert(__instance);
     }
     else
     {
         // Toggle colonies tab.
         DefDatabase <MainButtonDef> .GetNamed("Colonies").buttonVisible =
             PersistentWorldManager.GetInstance().PersistentWorldNotNull();
     }
 }
示例#27
0
        // Called when Game Over Abandon Colony Button is pressed.
        private static void PressAbandonColonyButton()
        {
            if (!PersistentWorldManager.GetInstance()
                .PersistentWorldNotNullAndLoadStatusIs(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame))
            {
                throw new InvalidOperationException($"{nameof(PressAbandonColonyButton)}: 'Game Over Colony Abandon' button cannot be pressed while not currently in a Persistent World.");
            }

            // TODO: Enter world view without tabs and ask player to choose a different colony.

            // Delete current colony, "abandoning" it.
            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            persistentWorld.DeleteColony(persistentWorld.Colony);
        }
        static bool Prefix(ScenPart_PlayerFaction __instance)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull())
            {
                return(true);
            }

            // In order to prevent cloned factions :/
            PersistentWorldManager.GetInstance().PersistentWorld
            .SetPlayerFactionVarsToNewGeneratedFaction((FactionDef)FactionDefField.GetValue(__instance));

            Find.GameInitData.playerFaction = PersistentWorldManager.GetInstance().PersistentWorld.WorldData.FactionManager.OfPlayer;
            FactionGenerator.EnsureRequiredEnemies(Find.GameInitData.playerFaction);

            return(false);
        }
        public Page_PersistentWorlds_LoadWorld_FileList()
        {
            // TODO: HMM
            PersistentWorldManager.GetInstance().Clear();

            this.LoadWorldsAsEntries();

            // Multi thread to decrease loading times.
            new Thread(this.LoadPossibleConversions).Start();

            this.doCloseButton           = true;
            this.doCloseX                = true;
            this.forcePause              = true;
            this.absorbInputAroundWindow = true;
            this.closeOnAccept           = false;
        }
        static bool Prefix(ref ILoadReferenceable refee, string label, bool saveDestroyedThings)
        {
            if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull() || !PersistentWorldManager.GetInstance().PersistentWorldNotNullAndLoadStatusIsNot(PersistentWorldLoadSaver.PersistentWorldLoadStatus.Converting))
            {
                return(true);
            }

            var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld;

            switch (Scribe.mode)
            {
            case LoadSaveMode.Saving:
                if (refee == null)
                {
                    Scribe.saver.WriteElement(label, "null");
                    break;
                }

                if (refee is Thing thing &&
                    Scribe_References.CheckSaveReferenceToDestroyedThing(thing, label, saveDestroyedThings))
                {
                    break;
                }

                Scribe.saver.WriteElement(label, refee.GetUniqueLoadID());
                Scribe.saver.loadIDsErrorsChecker.RegisterReferenced(refee, label);
                break;

            case LoadSaveMode.LoadingVars:
                var xmlNode      = (XmlNode)Scribe.loader.curXmlParent[label];
                var targetLoadID = xmlNode?.InnerText;

                persistentWorld.LoadSaver.ReferenceTable.RequestReference(label, targetLoadID);

                if (refee != null)
                {
                    Scribe.loader.crossRefs.loadIDs.RegisterLoadIDReadFromXml(targetLoadID, refee.GetType(), label);
                }
                break;

            case LoadSaveMode.ResolvingCrossRefs:
                refee = persistentWorld.LoadSaver.ReferenceTable.ResolveReference(label);
                break;
            }

            return(false);
        }