Exemplo n.º 1
0
        private bool ReadMetadata(string filePath)
        {
            if (!System.IO.Directory.Exists(filePath))
            {
                return(false);
            }
            else
            {
                string[] metaFiles = System.IO.Directory.GetFiles(filePath, "*." + MetaData.Extension);

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

                string[] screenshots = System.IO.Directory.GetFiles(filePath, "*.png");

                if (screenshots.Length > 0)
                {
                    Screenshot = TextureManager.LoadInstanceTexture(screenshots[0], false);
                }

                return(true);
            }
        }
Exemplo n.º 2
0
        public bool ReadFile(string filePath, bool isCompressed, bool isBinary)
        {
            if (!isBinary)
            {
                OverworldFile file = FileUtils.LoadJson <OverworldFile>(filePath, isCompressed);

                if (file == null)
                {
                    return(false);
                }
                else
                {
                    CopyFrom(file);
                    return(true);
                }
            }
            else
            {
                OverworldFile file = FileUtils.LoadBinary <OverworldFile>(filePath);

                if (file == null)
                {
                    return(false);
                }
                else
                {
                    CopyFrom(file);
                    return(true);
                }
            }
        }
Exemplo n.º 3
0
        public bool ReadFile(string filePath, bool isCompressed, bool isBinary)
        {
            if (!isBinary)
            {
                ChunkFile chunkFile = FileUtils.LoadJson <ChunkFile>(filePath, isCompressed);

                if (chunkFile == null)
                {
                    return(false);
                }
                CopyFrom(chunkFile);
                return(true);
            }
            else
            {
                ChunkFile chunkFile = FileUtils.LoadBinary <ChunkFile>(filePath);

                if (chunkFile == null)
                {
                    return(false);
                }
                CopyFrom(chunkFile);
                return(true);
            }
        }
Exemplo n.º 4
0
        public  bool ReadFile(string filePath, bool isCompressed, WorldManager world)
        {
            if(!System.IO.Directory.Exists(filePath))
            {
                return false;
            }
            else
            {
                string[] screenshots = SaveData.GetFilesInDirectory(filePath, false, "png", "png");
                string[] metaFiles = SaveData.GetFilesInDirectory(filePath, isCompressed, "MetaData", GameFile.MetaData.CompressedExtension, GameFile.MetaData.Extension);
                string[] cameraFiles = SaveData.GetFilesInDirectory(filePath, false, "json", "json");

                if(metaFiles.Length > 0)
                {
                    Data.Metadata = new MetaData(metaFiles[0], isCompressed);
                    Data.GameID = Data.Metadata.GameID;
                }
                else
                {
                    return false;
                }

                if(cameraFiles.Length > 0)
                {
                    Data.Camera = FileUtils.LoadJson<OrbitCamera>(cameraFiles[0], false, world);
                }
                else
                {
                    return false;
                }

                string[] chunkDirs = System.IO.Directory.GetDirectories(filePath, "Chunks");

                if(chunkDirs.Length > 0)
                {
                    string chunkDir = chunkDirs[0];

                    string[] chunks = SaveData.GetFilesInDirectory(chunkDir, isCompressed, ChunkFile.CompressedExtension, ChunkFile.Extension);
                    Data.ChunkData = new List<ChunkFile>();
                    foreach(string chunk in chunks)
                    {
                        Data.ChunkData.Add(new ChunkFile(chunk, isCompressed, DwarfGame.COMPRESSED_BINARY_SAVES));
                    }
                }
                else
                {
                    return false;
                }

                if(screenshots.Length > 0)
                {
                    string screenshot = screenshots[0];
                    Data.Screenshot = TextureManager.LoadInstanceTexture(screenshot);
                }

                return true;
            }
        }
Exemplo n.º 5
0
 public static bool CheckCompatibility(string filePath)
 {
     try
     {
         var metaFilePath = filePath + System.IO.Path.DirectorySeparatorChar + "meta.txt";
         return(FileUtils.LoadJson <OverworldData>(metaFilePath, false).Version == Program.Version);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 6
0
 public static void Load(string file)
 {
     try
     {
         Mappings = FileUtils.LoadJson <KeyMappings>(file, false);
     }
     catch (FileNotFoundException)
     {
         Mappings = new KeyMappings();
         Save();
     }
 }
Exemplo n.º 7
0
 public static void Load(string file)
 {
     try
     {
         Default = FileUtils.LoadJson <Settings>(file, false);
     }
     catch (FileNotFoundException fileLoad)
     {
         Default = new Settings();
         Save();
     }
 }
Exemplo n.º 8
0
        public bool LoadComponents(string filePath, WorldManager world)
        {
            string[] componentFiles = SaveData.GetFilesInDirectory(filePath, DwarfGame.COMPRESSED_BINARY_SAVES, "Components", GameFile.CompressedExtension, GameFile.Extension);
            if (componentFiles.Length > 0)
            {
                Data.Components = FileUtils.LoadJson<ComponentManager>(componentFiles[0], DwarfGame.COMPRESSED_BINARY_SAVES, world);
            }
            else
            {
                return false;
            }

            return true;
        }
Exemplo n.º 9
0
        public bool LoadComponents(string filePath)
        {
            string[] componentFiles = SaveData.GetFilesInDirectory(filePath, true, "zcomp", "zcomp");
            if (componentFiles.Length > 0)
            {
                Data.Components = FileUtils.LoadJson <ComponentManager>(componentFiles[0], true);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
0
            public  bool ReadFile(string filePath, bool isCompressed)
            {
                MetaData file = FileUtils.LoadJson<MetaData>(filePath, isCompressed);

                if(file == null)
                {
                    return false;
                }
                else
                {
                    CopyFrom(file);
                    return true;
                }
            }
Exemplo n.º 11
0
        public static void InitializeDefaultLibrary()
        {
            TypeList  = FileUtils.LoadJson <List <DecalType> >(ContentPaths.decal_types, false);
            emptyType = TypeList[0];

            byte ID = 0;

            foreach (var type in TypeList)
            {
                type.ID = ID;
                ++ID;

                Types[type.Name] = type;
            }
        }
Exemplo n.º 12
0
        public bool LoadPlayData(string filePath, WorldManager world)
        {
            string[] worldFiles = System.IO.Directory.GetFiles(filePath, "*." + PlayData.Extension);

            if (worldFiles.Length > 0)
            {
                PlayData = FileUtils.LoadJson <PlayData>(worldFiles[0], DwarfGame.COMPRESSED_BINARY_SAVES,
                                                         world);
            }
            else
            {
                Console.Error.WriteLine("Can't load world from {0}, no data file found.", filePath);
                return(false);
            }
            return(true);
        }
Exemplo n.º 13
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.LoadJson <OverworldData>(metaFilePath, false);

            var worldTexture = TextureManager.LoadInstanceTexture(worldFilePath, false);

            if (worldTexture != null)
            {
                Data.LoadFromTexture(worldTexture);
            }
            else
            {
                Console.Out.WriteLine("Failed to load overworld texture.");
                return(false);
            }
            return(true);
        }
Exemplo n.º 14
0
        public static void InitializeDefaultLibrary()
        {
            TypeList  = FileUtils.LoadJson <List <GrassType> >(ContentPaths.grass_types, false);
            emptyType = TypeList[0];

            byte ID = 0;

            foreach (var type in TypeList)
            {
                type.ID = ID;
                ++ID;

                Types[type.Name] = type;

                if (type.FringeTiles != null)
                {
                    type.FringeTransitionUVs = CreateFringeUVs(type.FringeTiles);
                }
            }
        }
Exemplo n.º 15
0
 public static void Load(string file)
 {
     try
     {
         Default = FileUtils.LoadJson <Settings>(file, false);
     }
     catch (FileNotFoundException)
     {
         Console.Error.WriteLine("Settings file does not exist. Using default settings.");
         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();
     }
 }
Exemplo n.º 16
0
        public static void InitializeDefaultLibrary(GraphicsDevice graphics, Texture2D cubeTexture)
        {
            TypeList  = FileUtils.LoadJson <List <VoxelType> >(ContentPaths.voxel_types, false);
            emptyType = TypeList[0];

            short ID = 0;

            foreach (VoxelType type in TypeList)
            {
                type.ID = ID;
                ++ID;

                Types[type.Name]   = type;
                PrimitiveMap[type] = type.ID == 0 ? null : CreatePrimitive(graphics, cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides);

                if (type.HasTransitionTextures)
                {
                    type.TransitionTextures = CreateTransitionUVs(graphics, cubeTexture, 32, 32, type.TransitionTiles, type.Transitions);
                }

                type.ExplosionSound = SoundSource.Create(type.ExplosionSoundResource);
                type.HitSound       = SoundSource.Create(type.HitSoundResources);
            }
        }
Exemplo n.º 17
0
        public static void LoadDefaultSounds()
        {
            try
            {
                string[] defaultSounds =
                {
                    ContentPaths.Audio.pick,
                    ContentPaths.Audio.hit,
                    ContentPaths.Audio.jump,
                    ContentPaths.Audio.ouch,
                    ContentPaths.Audio.gravel,
                    ContentPaths.Audio.river
                };

                foreach (string name in defaultSounds)
                {
                    SoundEffect effect = Content.Load <SoundEffect>(name);
                    EffectLibrary[name] = effect;
                }
                try
                {
                    Mixer = FileUtils.LoadJson <SFXMixer>(ContentPaths.mixer, false);
                }
                catch (FileNotFoundException exception)
                {
                    Console.Out.WriteLine("Mixer file didn't exist. Creating a new mixer.");
                    Mixer = new SFXMixer()
                    {
                        Gains = new Dictionary <string, SFXMixer.Levels>()
                    };
                }
                SoundEffect.DistanceScale = 0.1f;
                //SoundEffect.DopplerScale = 0.1f;
                AudioEngine = new AudioEngine("Content\\Audio\\XACT\\Win\\Sounds.xgs");
                SoundBank   = new SoundBank(AudioEngine, "Content\\Audio\\XACT\\Win\\SoundBank.xsb");
                WaveBank    = new WaveBank(AudioEngine, "Content\\Audio\\XACT\\Win\\WaveBank.xwb");

                CurrentMusic = new FancyMusic();
                CurrentMusic.AddTrack("main_theme_day", new MusicTrack(SoundBank)
                {
                    Intro             = "music_1_intro",
                    Loop              = "music_1_loop",
                    PlayLoopOverIntro = false
                });
                CurrentMusic.AddTrack("main_theme_night", new MusicTrack(SoundBank)
                {
                    Intro             = "music_1_night_intro",
                    Loop              = "music_1_night",
                    PlayLoopOverIntro = true
                });
                CurrentMusic.AddTrack("menu_music", new MusicTrack(SoundBank)
                {
                    Loop = "music_menu",
                    PlayLoopOverIntro = true
                });
                CurrentMusic.AddTrack("molemen", new MusicTrack(SoundBank)
                {
                    Loop = "molemen",
                    PlayLoopOverIntro = true
                });
                CurrentMusic.AddTrack("elf", new MusicTrack(SoundBank)
                {
                    Loop = "elf",
                    PlayLoopOverIntro = true
                });
                CurrentMusic.AddTrack("undead", new MusicTrack(SoundBank)
                {
                    Loop = "undead",
                    PlayLoopOverIntro = true
                });
                CurrentMusic.AddTrack("goblin", new MusicTrack(SoundBank)
                {
                    Loop = "goblin",
                    PlayLoopOverIntro = true
                });

                foreach (var cue in ActiveCues)
                {
                    cue.Value.Stop(AudioStopOptions.Immediate);
                }
                ActiveCues.Clear();
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine(exception);
                HasAudioDevice = false;
                AudioError     = exception.Message;
            }
        }