예제 #1
0
        public bool ReadFile(string filePath)
        {
            var metaFilePath = filePath + global::System.IO.Path.DirectorySeparatorChar + "meta.txt";

            MetaData = FileUtils.LoadJsonFromAbsolutePath <OverworldMetaData>(metaFilePath);
            MetaData.Overworld.ColonyCells.InitializeCellMap();

            foreach (var resource in MetaData.Resources)
            {
                if (!Library.DoesResourceTypeExist(resource.Name))
                {
                    Library.AddResourceType(resource);
                }
            }

            var worldFilePath = filePath + global::System.IO.Path.DirectorySeparatorChar + "world.png";
            var worldTexture  = AssetManager.LoadUnbuiltTextureFromAbsolutePath(worldFilePath);

            if (worldTexture != null)
            {
                var worldData = LoadFromTexture(worldTexture);
                MetaData.Overworld.Map = new OverworldMap(worldData);
            }
            else
            {
                Console.Out.WriteLine("Failed to load overworld texture.");
                return(false);
            }

            return(true);
        }
예제 #2
0
        private bool ReadMetadata()
        {
            if (!Directory.Exists(Path))
            {
                return(false);
            }

            var metaFiles = Directory.GetFiles(Path, "*." + MetaData.Extension);

            if (metaFiles.Length > 0)
            {
                Metadata = FileUtils.LoadJsonFromAbsolutePath <MetaData>(metaFiles[0]);
            }
            else
            {
                Console.Error.WriteLine("Can't load file {0}, no metadata found", Path);
                return(false);
            }

            var screenshots = Directory.GetFiles(Path, "*.png");

            if (screenshots.Length > 0)
            {
                Screenshot = AssetManager.LoadUnbuiltTextureFromAbsolutePath(screenshots[0]);
            }

            return(true);
        }
예제 #3
0
        public bool ReadChunks()
        {
            if (Metadata == null)
            {
                throw new InvalidProgramException("MetaData must be loaded before chunk data.");
            }

            ChunkData = new List <ChunkFile>();

            var chunkDirs = System.IO.Directory.GetDirectories(Path, "Chunks");

            if (chunkDirs.Length > 0)
            {
                foreach (string chunk in Directory.GetFiles(chunkDirs[0], "*." + ChunkFile.Extension))
                {
                    ChunkData.Add(FileUtils.LoadJsonFromAbsolutePath <ChunkFile>(chunk));
                }
            }
            else
            {
                Console.Error.WriteLine("Can't load chunks {0}, no chunks found", Path);
                return(false);
            }

            return(true);
        }
예제 #4
0
 public static string GetOverworldName(string filePath)
 {
     try
     {
         var metaFilePath = filePath + Path.DirectorySeparatorChar + "meta.txt";
         return(FileUtils.LoadJsonFromAbsolutePath <OverworldMetaData>(metaFilePath).Overworld.Name);
     }
     catch (Exception)
     {
         return("?");
     }
 }
예제 #5
0
        public static bool CheckCompatibility(string filePath)
        {
            try
            {
                var metaFilePath = filePath + global::System.IO.Path.DirectorySeparatorChar + "meta.txt";
                var metadata     = FileUtils.LoadJsonFromAbsolutePath <OverworldMetaData>(metaFilePath);

                return(Program.CompatibleVersions.Contains(metadata.Version));
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #6
0
        public bool LoadPlayData(string filePath, WorldManager world)
        {
            // Todo: Use actual set path
            string[] worldFiles = Directory.GetFiles(filePath, "*." + PlayData.Extension);

            if (worldFiles.Length > 0)
            {
                PlayData = FileUtils.LoadJsonFromAbsolutePath <PlayData>(worldFiles[0], world);
            }
            else
            {
                Console.Error.WriteLine("Can't load world from {0}, no data file found.", filePath);
                return(false);
            }
            return(true);
        }
예제 #7
0
 public static void Load(string file)
 {
     try
     {
         Mappings = FileUtils.LoadJsonFromAbsolutePath <KeyMappings>(file);
     }
     catch (DirectoryNotFoundException)
     {
         Mappings = new KeyMappings();
         Save();
     }
     catch (FileNotFoundException)
     {
         Mappings = new KeyMappings();
         Save();
     }
 }
예제 #8
0
        public static void Load(string file)
        {
            try
            {
                Default = FileUtils.LoadJsonFromAbsolutePath <Settings>(file);

                foreach (var member in Default.GetType().GetFields())
                {
                    foreach (var attribute in member.GetCustomAttributes(false))
                    {
                        if (attribute is AutoResetFloatAttribute resetFloat)
                        {
                            member.SetValue(Default, resetFloat.Value);
                            Console.Out.WriteLine("Auto Reset Float Setting: {0} to {1}", member.Name, resetFloat.Value);
                        }

                        if (attribute is AutoResetBoolAttribute resetBool)
                        {
                            member.SetValue(Default, resetBool.Value);
                            Console.Out.WriteLine("Auto Reset Bool Setting: {0} to {1}", member.Name, resetBool.Value);
                        }
                    }
                }

                Console.Out.WriteLine("Loaded settings {0}", file);
            }
            catch (FileNotFoundException)
            {
                Console.Error.WriteLine("Settings file {0} does not exist. Using default settings.", file);
                Default = new Settings();
                Save();
            }
            catch (Exception otherException)
            {
                Console.Error.WriteLine("Failed to load settings file {0} : {1}", file, otherException.ToString());
                if (otherException.InnerException != null)
                {
                    Console.Error.WriteLine("Inner exception: {0}", otherException.InnerException.ToString());
                }
                Default = new Settings();
                Save();
            }
            // mklingen (I have made it impossible to disable fog of war for performance reasons).
            Default.FogofWar = true; // Todo: Check on this - autoreset?
        }
예제 #9
0
        public ChunkFile(string fileName, bool binary)
        {
            ChunkFile chunkFile = null;

            if (!binary)
            {
                chunkFile = FileUtils.LoadJsonFromAbsolutePath <ChunkFile>(fileName);
            }
            else
            {
                chunkFile = FileUtils.LoadBinary <ChunkFile>(fileName);
            }

            if (chunkFile != null)
            {
                CopyFrom(chunkFile);
            }
        }
예제 #10
0
        public static void Load(string file)
        {
            try
            {
                Current = FileUtils.LoadJsonFromAbsolutePath <Settings>(file);

                foreach (var member in Current.GetType().GetFields())
                {
                    foreach (var attribute in member.GetCustomAttributes(false))
                    {
                        if (attribute is AutoResetFloatAttribute resetFloat)
                        {
                            member.SetValue(Current, resetFloat.Value);
                            Console.Out.WriteLine("Auto Reset Float Setting: {0} to {1}", member.Name, resetFloat.Value);
                        }

                        if (attribute is AutoResetBoolAttribute resetBool)
                        {
                            member.SetValue(Current, resetBool.Value);
                            Console.Out.WriteLine("Auto Reset Bool Setting: {0} to {1}", member.Name, resetBool.Value);
                        }
                    }
                }

                Console.Out.WriteLine("Loaded settings {0}", file);
            }
            catch (FileNotFoundException)
            {
                Console.Error.WriteLine("Settings file {0} does not exist. Using default settings.", file);
                Current = new Settings();
                Save();
            }
            catch (Exception otherException)
            {
                Console.Error.WriteLine("Failed to load settings file {0} : {1}", file, otherException.ToString());
                if (otherException.InnerException != null)
                {
                    Console.Error.WriteLine("Inner exception: {0}", otherException.InnerException.ToString());
                }
                Current = new Settings();
                Save();
            }
        }
예제 #11
0
        public bool ReadFile(string filePath)
        {
            var worldFilePath = filePath + System.IO.Path.DirectorySeparatorChar + "world.png";
            var metaFilePath  = filePath + System.IO.Path.DirectorySeparatorChar + "meta.txt";

            Data = FileUtils.LoadJsonFromAbsolutePath <OverworldData>(metaFilePath);

            var worldTexture = AssetManager.LoadUnbuiltTextureFromAbsolutePath(worldFilePath);

            if (worldTexture != null)
            {
                Data.LoadFromTexture(worldTexture);
            }
            else
            {
                Console.Out.WriteLine("Failed to load overworld texture.");
                return(false);
            }
            return(true);
        }
        private static ModMetaData GetMod(string dir, ModSource Source)
        {
            try
            {
                var metaDataPath = dir + Path.DirectorySeparatorChar + "meta.json";
                var metaData     = FileUtils.LoadJsonFromAbsolutePath <ModMetaData>(metaDataPath);
                metaData.Directory = dir;
                metaData.Source    = Source;

                if (dir.StartsWith(GameSettings.Current.SteamModDirectory))
                {
                    metaData.SteamID = ulong.Parse(global::System.IO.Path.GetFileName(dir));
                }
                return(metaData);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid mod: {0} {1}", dir, e.Message);
                return(null);
            }
        }
예제 #13
0
 public static void Load(string file)
 {
     try
     {
         Mappings = FileUtils.LoadJsonFromAbsolutePath <KeyMappings>(file);
     }
     catch (DirectoryNotFoundException)
     {
         Mappings = new KeyMappings();
         Save();
     }
     catch (FileNotFoundException)
     {
         Mappings = new KeyMappings();
         Save();
     }
     catch (Exception)
     {
         Mappings = new KeyMappings();
         // Don't save in this case because who the f**k knows what went wrong.
     }
 }
예제 #14
0
        public bool LoadPlayData(string filePath, WorldManager world)
        {
            string[] worldFiles = System.IO.Directory.GetFiles(filePath, "*." + PlayData.Extension);

            if (worldFiles.Length > 0)
            {
                if (DwarfGame.COMPRESSED_BINARY_SAVES)
                {
                    PlayData = FileUtils.LoadCompressedJsonFromAbsolutePath <PlayData>(worldFiles[0], world);
                }
                else
                {
                    PlayData = FileUtils.LoadJsonFromAbsolutePath <PlayData>(worldFiles[0], world);
                }
            }
            else
            {
                Console.Error.WriteLine("Can't load world from {0}, no data file found.", filePath);
                return(false);
            }
            return(true);
        }
예제 #15
0
        // Todo: Goal here is to not have to load all chunks at once.
        public List <ChunkFile> LoadChunks()
        {
            if (Metadata == null)
            {
                throw new InvalidProgramException("MetaData must be loaded before chunk data.");
            }

            var chunkDirectory = System.IO.Path.Combine(Path, "Chunks");

            if (!Directory.Exists(chunkDirectory))
            {
                throw new InvalidOperationException("No chunk directory found.");
            }

            var r = new List <ChunkFile>();

            foreach (string chunkFileName in Directory.GetFiles(chunkDirectory, "*." + ChunkFile.Extension))
            {
                r.Add(FileUtils.LoadJsonFromAbsolutePath <ChunkFile>(chunkFileName));
            }

            return(r);
        }
예제 #16
0
 public static void Load(string file)
 {
     try
     {
         Default = FileUtils.LoadJsonFromAbsolutePath <Settings>(file);
         Console.Out.WriteLine("Loaded settings {1} \n {0}", file, Default.ToString());
     }
     catch (FileNotFoundException)
     {
         Console.Error.WriteLine("Settings file {0} does not exist. Using default settings.", file);
         Default = new Settings();
         Save();
     }
     catch (Exception otherException)
     {
         Console.Error.WriteLine("Failed to load settings file {0} : {1}", file, otherException.ToString());
         if (otherException.InnerException != null)
         {
             Console.Error.WriteLine("Inner exception: {0}", otherException.InnerException.ToString());
         }
         Default = new Settings();
         Save();
     }
 }
예제 #17
0
        public bool ReadChunks(string filePath)
        {
            if (Metadata == null)
            {
                throw new InvalidProgramException("MetaData must be loaded before chunk data.");
            }

            ChunkData = new List <ChunkFile>();

            var chunkDirs = System.IO.Directory.GetDirectories(filePath, "Chunks");

            if (chunkDirs.Length > 0)
            {
                foreach (string chunk in Directory.GetFiles(chunkDirs[0], "*." + (DwarfGame.COMPRESSED_BINARY_SAVES ? ChunkFile.CompressedExtension : ChunkFile.Extension)))
                {
                    if (DwarfGame.COMPRESSED_BINARY_SAVES)
                    {
                        ChunkData.Add(FileUtils.LoadBinary <ChunkFile>(chunk));
                    }
                    else
                    {
                        ChunkData.Add(FileUtils.LoadJsonFromAbsolutePath <ChunkFile>(chunk));
                    }
                }
            }
            else
            {
                Console.Error.WriteLine("Can't load chunks {0}, no chunks found", filePath);
                return(false);
            }

            // Remap the saved voxel ids to the ids of the currently loaded voxels.
            if (Metadata.VoxelTypeMap != null)
            {
                // First build a replacement mapping.

                var newVoxelMap   = VoxelLibrary.GetVoxelTypeMap();
                var newReverseMap = new Dictionary <String, int>();
                foreach (var mapping in newVoxelMap)
                {
                    newReverseMap.Add(mapping.Value, mapping.Key);
                }

                var replacementMap = new Dictionary <int, int>();
                foreach (var mapping in Metadata.VoxelTypeMap)
                {
                    if (newReverseMap.ContainsKey(mapping.Value))
                    {
                        var newId = newReverseMap[mapping.Value];
                        if (mapping.Key != newId)
                        {
                            replacementMap.Add(mapping.Key, newId);
                        }
                    }
                }

                // If there are no changes, skip the expensive iteration.
                if (replacementMap.Count != 0)
                {
                    foreach (var chunk in ChunkData)
                    {
                        for (var i = 0; i < chunk.Types.Length; ++i)
                        {
                            if (replacementMap.ContainsKey(chunk.Types[i]))
                            {
                                chunk.Types[i] = (byte)replacementMap[chunk.Types[i]];
                            }
                        }
                    }
                }
            }

            return(true);
        }