예제 #1
0
        private bool HasFrames(patch_Atlas atlas, string path, int[] frames = null)
        {
            atlas.PushFallback(null);
            bool rv = orig_HasFrames(atlas, path, frames);

            atlas.PopFallback();
            return(rv);
        }
예제 #2
0
        public static new Atlas FromDirectory(string path)
        {
            patch_Atlas atlas = (patch_Atlas)orig_FromDirectory(path);

            atlas.DataMethod = "FromDirectory";
            atlas.DataPath   = path;
            Everest.Content.Process(atlas, atlas.DataPath);
            return(atlas);
        }
예제 #3
0
        public static new Atlas FromAtlas(string path, AtlasDataFormat format)
        {
            patch_Atlas atlas = (patch_Atlas)orig_FromAtlas(path, format);

            atlas.DataMethod = "FromAtlas";
            atlas.DataPath   = path;
            atlas.DataFormat = format;
            Everest.Content.Process(atlas, atlas.DataPath);
            return(atlas);
        }
예제 #4
0
        public static new Atlas FromMultiAtlas(string rootPath, string filename, AtlasDataFormat format)
        {
            patch_Atlas atlas = (patch_Atlas)orig_FromMultiAtlas(rootPath, filename, format);

            atlas.DataMethod = "FromMultiAtlas";
            atlas.DataPath   = rootPath;
            atlas.DataPaths  = new string[] { filename };
            atlas.DataFormat = format;
            Everest.Content.Process(atlas, atlas.DataPath);
            return(atlas);
        }
예제 #5
0
        public static new Atlas FromMultiAtlas(string rootPath, string[] dataPath, AtlasDataFormat format)
        {
            patch_Atlas atlas = (patch_Atlas)orig_FromMultiAtlas(rootPath, dataPath, format);

            atlas.DataMethod = "FromMultiAtlas";
            atlas.DataPath   = rootPath;
            atlas.DataPaths  = dataPath;
            atlas.DataFormat = format;
            Everest.Content.Process(atlas.DataPath, atlas);
            Everest.Events.Atlas.Load(atlas);
            return(atlas);
        }
예제 #6
0
        private static void ReadAtlasData(Atlas _atlas, string path, AtlasDataFormat format)
        {
            if (VTextureToMTextureMap == null)
            {
                VTextureToMTextureMap = new Dictionary <string, MTexture>();
            }

            patch_Atlas atlas = (patch_Atlas)_atlas;

            string pathFull = Path.Combine(Engine.ContentDirectory, path);

            XmlDocument    xmlDoc;
            VirtualTexture texV;
            MTexture       texM;

            switch (format)
            {
            case AtlasDataFormat.TexturePacker_Sparrow:
                xmlDoc = Calc.LoadContentXML(path);
                XmlElement xmlTextureAtlas = xmlDoc["TextureAtlas"];
                if (xmlTextureAtlas == null)
                {
                    break;
                }

                texV = VirtualContent.CreateTexture(Path.Combine(Path.GetDirectoryName(path), xmlTextureAtlas.Attr("imagePath", "")));
                texM = new MTexture(texV);
                VTextureToMTextureMap[texV.Name] = texM;
                atlas.Sources.Add(texV);

                XmlNodeList xmlSubs = xmlTextureAtlas.GetElementsByTagName("SubTexture");
                foreach (XmlElement xmlSub in xmlSubs)
                {
                    string    name     = xmlSub.Attr("name");
                    Rectangle clipRect = xmlSub.Rect();
                    if (xmlSub.HasAttr("frameX"))
                    {
                        atlas.textures[name] = new MTexture(
                            texM, name, clipRect,
                            new Vector2(-xmlSub.AttrInt("frameX"), -xmlSub.AttrInt("frameY")),
                            xmlSub.AttrInt("frameWidth"), xmlSub.AttrInt("frameHeight")
                            );
                    }
                    else
                    {
                        atlas.textures[name] = new MTexture(texM, name, clipRect);
                    }
                }
                break;

            case AtlasDataFormat.CrunchXml:
                if (!File.Exists(pathFull))
                {
                    break;
                }

                xmlDoc = Calc.LoadContentXML(path);
                XmlElement xmlAtlas = xmlDoc["atlas"];

                foreach (XmlElement xmlAtlasSource in xmlAtlas)
                {
                    texV = VirtualContent.CreateTexture(Path.Combine(Path.GetDirectoryName(path), xmlAtlasSource.Attr("n", "") + ".png"));
                    texM = new MTexture(texV);
                    VTextureToMTextureMap[texV.Name] = texM;
                    atlas.Sources.Add(texV);
                    foreach (XmlElement xmlSub in xmlAtlasSource)
                    {
                        string    name     = xmlSub.Attr("n");
                        Rectangle clipRect = new Rectangle(xmlSub.AttrInt("x"), xmlSub.AttrInt("y"), xmlSub.AttrInt("w"), xmlSub.AttrInt("h"));
                        if (xmlSub.HasAttr("fx"))
                        {
                            atlas.textures[name] = new MTexture(
                                texM, name, clipRect,
                                new Vector2(-xmlSub.AttrInt("fx"), -xmlSub.AttrInt("fy")),
                                xmlSub.AttrInt("fw"), xmlSub.AttrInt("fh")
                                );
                        }
                        else
                        {
                            atlas.textures[name] = new MTexture(texM, name, clipRect);
                        }
                    }
                }
                break;

            case AtlasDataFormat.CrunchBinary:
                if (!File.Exists(pathFull))
                {
                    break;
                }

                using (FileStream stream = File.OpenRead(pathFull))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        short sources = reader.ReadInt16();
                        for (int i = 0; i < sources; i++)
                        {
                            texV = VirtualContent.CreateTexture(Path.Combine(Path.GetDirectoryName(path), reader.ReadNullTerminatedString() + ".png"));
                            texM = new MTexture(texV);
                            VTextureToMTextureMap[texV.Name] = texM;
                            atlas.Sources.Add(texV);
                            short subs = reader.ReadInt16();
                            for (int j = 0; j < subs; j++)
                            {
                                string name       = reader.ReadNullTerminatedString();
                                short  clipX      = reader.ReadInt16();
                                short  clipY      = reader.ReadInt16();
                                short  clipWidth  = reader.ReadInt16();
                                short  clipHeight = reader.ReadInt16();
                                short  offsX      = reader.ReadInt16();
                                short  offsY      = reader.ReadInt16();
                                short  width      = reader.ReadInt16();
                                short  height     = reader.ReadInt16();
                                atlas.textures[name] = new MTexture(
                                    texM, name, new Rectangle(clipX, clipY, clipWidth, clipHeight),
                                    new Vector2(-offsX, -offsY),
                                    width, height
                                    );
                            }
                        }
                    }
                break;

            case AtlasDataFormat.CrunchXmlOrBinary:
                if (File.Exists(pathFull + ".bin"))
                {
                    ReadAtlasData(atlas, path + ".bin", AtlasDataFormat.CrunchBinary);
                }
                else if (File.Exists(pathFull + ".xml"))
                {
                    ReadAtlasData(atlas, path + ".xml", AtlasDataFormat.CrunchXml);
                }
                return;

            case AtlasDataFormat.CrunchBinaryNoAtlas:
                if (!File.Exists(pathFull + ".bin"))
                {
                    break;
                }

                using (FileStream stream = File.OpenRead(pathFull + ".bin"))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        short sources = reader.ReadInt16();
                        for (int i = 0; i < sources; i++)
                        {
                            string sourcePath = Path.Combine(Path.GetDirectoryName(path), reader.ReadNullTerminatedString());
                            short  subs       = reader.ReadInt16();
                            for (int j = 0; j < subs; j++)
                            {
                                string name     = reader.ReadNullTerminatedString();
                                short  unknownA = reader.ReadInt16();
                                short  unknownB = reader.ReadInt16();
                                short  unknownC = reader.ReadInt16();
                                short  unknownD = reader.ReadInt16();
                                short  offsX    = reader.ReadInt16();
                                short  offsY    = reader.ReadInt16();
                                short  width    = reader.ReadInt16();
                                short  height   = reader.ReadInt16();
                                texV = VirtualContent.CreateTexture(Path.Combine(sourcePath, name + ".png"));
                                atlas.textures[name] = VTextureToMTextureMap[texV.Name] = new MTexture(texV, new Vector2(-offsX, -offsY), width, height);
                                atlas.Sources.Add(texV);
                            }
                        }
                    }
                break;

            case AtlasDataFormat.Packer:
                if (!File.Exists(pathFull + ".meta"))
                {
                    break;
                }

                using (FileStream stream = File.OpenRead(pathFull + ".meta"))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        reader.ReadInt32();  // ???
                        reader.ReadString(); // ???
                        reader.ReadInt32();  // ???
                        short sources = reader.ReadInt16();
                        for (int i = 0; i < sources; i++)
                        {
                            texV = VirtualContent.CreateTexture(Path.Combine(Path.GetDirectoryName(path), reader.ReadString() + ".data"));
                            texM = new MTexture(texV);
                            VTextureToMTextureMap[texV.Name] = texM;
                            atlas.Sources.Add(texV);
                            short subs = reader.ReadInt16();
                            for (int j = 0; j < subs; j++)
                            {
                                string name       = reader.ReadString().Replace('\\', '/');
                                short  clipX      = reader.ReadInt16();
                                short  clipY      = reader.ReadInt16();
                                short  clipWidth  = reader.ReadInt16();
                                short  clipHeight = reader.ReadInt16();
                                short  offsX      = reader.ReadInt16();
                                short  offsY      = reader.ReadInt16();
                                short  width      = reader.ReadInt16();
                                short  height     = reader.ReadInt16();
                                atlas.textures[name] = new MTexture(
                                    texM, name, new Rectangle(clipX, clipY, clipWidth, clipHeight),
                                    new Vector2(-offsX, -offsY),
                                    width, height
                                    );
                            }
                        }
                    }
                break;

            case AtlasDataFormat.PackerNoAtlas:
                if (!File.Exists(pathFull + ".meta"))
                {
                    break;
                }

                using (FileStream stream = File.OpenRead(pathFull + ".meta"))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        reader.ReadInt32();
                        reader.ReadString();
                        reader.ReadInt32();
                        short sources = reader.ReadInt16();
                        for (int i = 0; i < sources; i++)
                        {
                            string sourcePath = Path.Combine(Path.GetDirectoryName(path), reader.ReadString());
                            short  subs       = reader.ReadInt16();
                            for (int j = 0; j < subs; j++)
                            {
                                string name     = reader.ReadString().Replace('\\', '/');
                                short  unknownA = reader.ReadInt16();
                                short  unknownB = reader.ReadInt16();
                                short  unknownC = reader.ReadInt16();
                                short  unknownD = reader.ReadInt16();
                                short  offsX    = reader.ReadInt16();
                                short  offsY    = reader.ReadInt16();
                                short  width    = reader.ReadInt16();
                                short  height   = reader.ReadInt16();
                                texV = VirtualContent.CreateTexture(Path.Combine(sourcePath, name + ".data"));
                                atlas.textures[name] = VTextureToMTextureMap[texV.Name] = new MTexture(texV, new Vector2(-offsX, -offsY), width, height);
                                atlas.Sources.Add(texV);
                            }
                        }
                    }
                break;

            default:
                break;
            }
        }
예제 #7
0
 private extern bool orig_HasFrames(patch_Atlas atlas, string path, int[] frames = null);