public void LoadWorld()
        {
            this.ReferenceTable.ClearReferences();

            if (ScribeMultiLoader.Empty())
            {
                PreloadWorldColoniesMaps();
            }

            Status = PersistentWorldLoadStatus.Loading;

            this.SetCurrentFile(worldFilePath);

            Log.Message("Loading world " + worldFolderPath);

            // Select world to load XML node data for.
            ScribeMultiLoader.SetScribeCurXmlParentByFilePath(this.worldFilePath);

            // Required otherwise errors because of internal requirements.
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);

            // Load data.
            Scribe_Deep.Look <PersistentWorldData>(ref this.persistentWorld.WorldData, "data");

            //this.persistentWorld.ResetPlayerFaction(FactionDefOf.PlayerColony);

            Log.Message("Loaded world data...");
        }
        public IEnumerable <Map> LoadMaps(int[] mapTiles)
        {
            if (Scribe.mode != LoadSaveMode.LoadingVars || ScribeMultiLoader.Empty())
            {
                this.PreloadWorldColoniesMaps();
            }

            var mapFiles = new DirectoryInfo(this.mapsDirectory).GetFiles("*" + PersistentWorldMapFileExtension);

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

            var maps = new List <Map>();

            foreach (var mapFile in mapFiles)
            {
                this.SetCurrentFile(mapFile);

                if (!mapTiles.Any(tile => mapFile.FullName.Contains(tile.ToString())))
                {
                    continue;
                }

                if (this.Status != PersistentWorldLoadStatus.Ingame)
                {
                    ScribeMultiLoader.SetScribeCurXmlParentByFilePath(mapFile.FullName);
                }
                else
                {
                    // Reset scribe if not already reset.
                    ScribeVars.TrickScribe();

                    Scribe.loader.InitLoading(mapFile.FullName);
                }

                var map = new Map();

                Scribe_Deep.Look <Map>(ref map, "map");

                if (this.Status == PersistentWorldLoadStatus.Ingame)
                {
                    Scribe.loader.FinalizeLoading();
                }

                maps.Add(map);
            }

            if (this.Status != PersistentWorldLoadStatus.Ingame)
            {
                Scribe.loader.FinalizeLoading();
            }

            Status = PersistentWorldLoadStatus.Ingame;

            ScribeMultiLoader.Clear();

            Log.Message("Loaded map data...");

            return(maps);
        }
        /**
         * MISC
         */

        public void TransferToPlayScene()
        {
            LongEventHandler.QueueLongEvent(delegate
            {
                Status = PersistentWorldLoadStatus.Finalizing;

                Current.Game = new Game {
                    InitData = new GameInitData {
                        gameToLoad = "PersistentWorld"
                    }
                };                                                                                      // Just to get the SavedGameLoaderNow.LoadGameFromSaveFileNow() patch to load.
            }, "Play", "LoadingLongEvent", true, null);
        }
        /**
         * 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;
        }
        /**
         * SAVING
         */

        public void SaveWorld()
        {
            // Clear references
            this.ReferenceTable.ClearReferences();

            this.CreateDirectoriesIfNotExistent();

            Status = PersistentWorldLoadStatus.Saving;

            this.persistentWorld.ConvertCurrentGameWorldObjects();

            this.SaveWorldData();
            this.SaveColony(ref this.persistentWorld.Colony);
            this.SaveMapData();

            // ScribeSaver.FinalizeSaving() stops this from calling when Persistent World is present.
            Scribe.saver.loadIDsErrorsChecker.CheckForErrorsAndClear();

            this.persistentWorld.ConvertToCurrentGameWorldObjects();
        }