/// <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 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);
        }
        /**
         * LOADING
         */

        private void PreloadWorldColoniesMaps()
        {
            var files = new List <string> {
                this.worldFilePath
            };

            new DirectoryInfo(this.coloniesDirectory).GetFiles("*" + PersistentWorldColonyFileExtension).Do(colonyFile => files.Add(colonyFile.FullName));
            new DirectoryInfo(this.mapsDirectory).GetFiles("*" + PersistentWorldMapFileExtension).Do(mapFile => files.Add(mapFile.FullName));

            ScribeMultiLoader.InitLoading(files.ToArray());

            Log.Message("Preloaded World, Colonies, and Maps.");
        }
        /// <summary>
        /// Loads all colony data for a specific colony. Fully loads the referenced colony.
        /// </summary>
        /// <param name="colony"></param>
        public void LoadColony(ref PersistentColony colony)
        {
            if (Scribe.mode != LoadSaveMode.LoadingVars || ScribeMultiLoader.Empty())
            {
                this.PreloadWorldColoniesMaps();
            }

            var file = colony.FileInfo ?? new FileInfo(GetColonySaveFilePath(colony));

            SetCurrentFile(file);

            Log.Message("Loading colony... " + Path.GetFileNameWithoutExtension(file.FullName));

            ScribeMultiLoader.SetScribeCurXmlParentByFilePath(file.FullName);

            Scribe_Deep.Look(ref colony, "colony");

            this.persistentWorld.Colony = colony;
            colony.FileInfo             = file;

            Log.Message("Loaded colony.");
        }