예제 #1
0
        public static TexturePack GetPackTextures(string path, string[] files)
        {
            var pack = new TexturePack(path);

            foreach (string imgFile in files)
            {
                if (imgFile.Contains(TEXTURES))
                {
                    try {
                        TextureEntry entry;
                        using (var stream = OpenFile(imgFile)) {
                            // ignore exception if image data is invalid
                            entry = new TextureEntry(imgFile, LoadImageCached(stream));
                        }
                        string ani = imgFile + "." + ANI_EXT;
                        if (File.Exists(ani))
                        {
                            entry.AnimationData = File.ReadAllText(ani);
                        }
                        pack.Add(entry);
                    } catch (ArgumentException) { }
                }
            }
            pack.Sort();
            return(pack);
        }
예제 #2
0
        public static TexturePack GetModTextures(string path, ZipArchive file)
        {
            var mod = new TexturePack(path);
            // ani data needs to be held separately
            var aniData = new Dictionary <string, string>();

            foreach (var entry in file.Entries)
            {
                string name = entry.FullName;
                if (name.StartsWith(TextureEntry.ASSETS) && name.Contains(TEXTURES))
                {
                    if (name.EndsWith(TEXTURE_EXT))
                    {
                        try {
                            using (var stream = entry.Open()) {
                                // ignore exception if image data is invalid
                                mod.Add(new TextureEntry(name, LoadImageCached(stream)));
                            }
                        } catch (ArgumentException) { }
                    }
                    else if (name.EndsWith("." + ANI_EXT))
                    {
                        string pngName = name.Substring(0, name.Length - 1 - ANI_EXT.Length);
                        using (var reader = new StreamReader(entry.Open())) {
                            aniData.Add(pngName, reader.ReadToEnd());
                        }
                    }
                }
            }
            foreach (var texture in mod)
            {
                string animated;
                if (aniData.TryGetValue(texture.FullPath, out animated))
                {
                    texture.AnimationData = animated;
                }
            }
            mod.Sort();
            return(mod);
        }