예제 #1
0
 public static void Add(this Monocle.Atlas atlas, AtlasAddition additions)
 {
     foreach (KeyValuePair <string, Subtexture> addition in additions.SubTextures)
     {
         atlas.SubTextures[addition.Key] = addition.Value;
     }
 }
예제 #2
0
 public static void AddRange(this Monocle.Atlas atlas, IEnumerable <AtlasAddition> additions)
 {
     foreach (AtlasAddition addition in additions)
     {
         Add(atlas, addition);
     }
 }
예제 #3
0
 protected override void LoadContent()
 {
     base.LoadContent();
     Atlas = new Atlas(Path + @"Content/Atlas/atlas.xml", true);
     //SpriteData = new SpriteData(Path + @"Content/Atlas/SpriteData.xml", Atlas);
     Content.RootDirectory = Path + "Content";
     Font = Content.Load<SpriteFont>(@"Misc/pixel");
     Stats = GameStats.Init();
 }
예제 #4
0
        public SpriteData(string filename, Atlas atlas)
        {
            this.atlas = atlas;

            XmlDocument xml = Calc.LoadXML(filename);
            sprites = new Dictionary<string, XmlElement>();
            foreach (var e in xml["SpriteData"])
                if (e is XmlElement)
                    sprites.Add((e as XmlElement).Attr("id"), e as XmlElement);
        }
예제 #5
0
        private bool HasFrames(Atlas atlas, string path, int[] frames = null)
        {
            if (frames == null || frames.Length <= 0)
            {
                return(atlas.GetAtlasSubtexturesAt(path, 0) != null);
            }
            else
            {
                for (int i = 0; i < frames.Length; i++)
                {
                    if (atlas.GetAtlasSubtexturesAt(path, frames[i]) == null)
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
예제 #6
0
        public static Atlas FromMultiAtlas(string rootPath, string filename, AtlasDataFormat format)
        {
            var atlas = new Atlas();

            atlas.Sources = new List <Texture2D>();

            var index = 0;

            while (true)
            {
                var dataPath = Path.Combine(rootPath, filename + index.ToString() + ".xml");

                if (!File.Exists(Path.Combine(Engine.ContentDirectory, dataPath)))
                {
                    break;
                }

                ReadAtlasData(atlas, dataPath, format);
                index++;
            }

            return(atlas);
        }
예제 #7
0
        public static Atlas FromDirectory(string path)
        {
            var atlas = new Atlas();

            atlas.Sources = new List <Texture2D>();

            var contentDirectory       = Engine.ContentDirectory;
            var contentDirectoryLength = contentDirectory.Length;
            var contentPath            = Path.Combine(contentDirectory, path);
            var contentPathLength      = contentPath.Length;

            foreach (var file in Directory.GetFiles(contentPath, "*", SearchOption.AllDirectories))
            {
                var ext = Path.GetExtension(file);
                if (ext != ".png" && ext != ".xnb")
                {
                    continue;
                }

                // get path and load
                var fileStream = new FileStream(file.Substring(contentDirectoryLength + 1), FileMode.Open, FileAccess.Read);
                var texture    = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                fileStream.Close();

                atlas.Sources.Add(texture);

                // make nice for dictionary
                var filepath = file.Substring(contentPathLength + 1);
                filepath = filepath.Substring(0, filepath.Length - 4);
                filepath = filepath.Replace('\\', '/');

                // load
                atlas.textures.Add(filepath, new MTexture(texture));
            }

            return(atlas);
        }
예제 #8
0
        public new PixelFontSize AddFontSize(string path, Atlas atlas = null, bool outline = false)
        {
            Logger.Log("PixelFont", $"Loading font: {path}");

            PixelFontSize loadedSize = null;

            // load the vanilla font if it exists.
            if (patch_Calc.orig_XMLExists(path))
            {
                Logger.Log("PixelFont", "=> vanilla font file");
                XmlElement data = patch_Calc.orig_LoadXML(path)["font"];
                loadedSize = AddFontSize(path, data, atlas, outline);
                Sizes.Remove(loadedSize);
            }

            // load custom fonts
            string modPath = FileProxy._Modize(path);

            foreach (ModAsset modAsset in Everest.Content.Mods
                     .Select(mod => mod.Map)
                     .Where(map => map.ContainsKey(modPath))
                     .Select(map => map[modPath]))
            {
                Logger.Log("PixelFont", $"=> mod font file from {modAsset.Source.Name}");
                XmlElement    data        = loadXMLFromModAsset(modAsset)["font"];
                PixelFontSize newFontSize = AddFontSize(path, data, atlas, outline);
                Sizes.Remove(newFontSize);
                loadedSize = mergeFonts(loadedSize, newFontSize);
            }

            // add the merged font into the list of existing fonts.
            Sizes.Add(loadedSize);
            Sizes.Sort((PixelFontSize a, PixelFontSize b) => Math.Sign(a.Size - b.Size));

            return(loadedSize);
        }
예제 #9
0
 public void ctor(Atlas atlas, string xmlPath)
 {
     XMLPath = xmlPath;
     orig_ctor(atlas, xmlPath);
 }
예제 #10
0
 public void ctor(Atlas atlas, XmlDocument xml)
 {
     orig_ctor(atlas, xml);
     Everest.Content.ProcessLoad(this, XMLPath);
 }
예제 #11
0
 public patch_SpriteBank(Atlas atlas, XmlDocument xml)
     : base(atlas, xml)
 {
     // no-op. MonoMod ignores this - we only need this to make the compiler shut up.
 }
예제 #12
0
 public static string GetDataMethod(this Atlas self)
 => ((patch_Atlas)self).DataMethod;
예제 #13
0
        public static void Ingest(this Atlas self, AssetMetadata asset)
        {
            // Crawl through all child assets.
            if (asset.AssetType == typeof(AssetTypeDirectory))
            {
                foreach (AssetMetadata child in asset.Children)
                {
                    self.Ingest(child);
                }
                return;
            }

            // Forcibly add the mod content to the atlas.
            if (asset.AssetType == typeof(Texture2D))
            {
                string parentPath = self.GetDataPath();
                if (parentPath.StartsWith(Everest.Content.PathContentOrig))
                {
                    parentPath = parentPath.Substring(Everest.Content.PathContentOrig.Length + 1);
                }
                parentPath = parentPath.Replace('\\', '/');

                string path = asset.PathRelative;
                if (!path.StartsWith(parentPath))
                {
                    return;
                }
                path = path.Substring(parentPath.Length + 1);

                VirtualTexture replacementV = VirtualContentExt.CreateTexture(asset);
                MTexture       replacement;
                MTextureMeta   meta = asset.GetMeta <MTextureMeta>();

                Dictionary <string, MTexture> textures = self.GetTextures();
                MTexture existing;
                if (textures.TryGetValue(path, out existing))
                {
                    // We're the currently active overlay.
                    if (existing.Texture.GetMetadata() == asset)
                    {
                        return;
                    }

                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        existing.AddOverlay(replacementV, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Keep width and height from existing instance.
                        existing.AddOverlay(replacementV, existing.DrawOffset, existing.Width, existing.Height);
                    }

                    replacement = existing;
                }
                else
                {
                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        replacement = new MTexture(replacementV, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Apply width and height from replacement texture.
                        replacement = new MTexture(replacementV);
                    }
                    // TODO: What's with the AtlasPath? Seems to stem from an atlas metadata property...
                }

                self[path] = replacement;
                return;
            }
        }
예제 #14
0
        private static void ReadAtlasData(Atlas atlas, string path, AtlasDataFormat format)
        {
            switch (format)
            {
            case AtlasDataFormat.TexturePacker_Sparrow:
            {
                XmlDocument xml = Calc.LoadContentXML(path);
                XmlElement  at  = xml["TextureAtlas"];

                var texturePath = at.Attr("imagePath", "");
                var fileStream  = new FileStream(Path.Combine(Path.GetDirectoryName(path), texturePath), FileMode.Open, FileAccess.Read);
                var texture     = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                fileStream.Close();

                var mTexture = new MTexture(texture);
                atlas.Sources.Add(texture);

                var subtextures = at.GetElementsByTagName("SubTexture");

                foreach (XmlElement sub in subtextures)
                {
                    var name     = sub.Attr("name");
                    var clipRect = sub.Rect();
                    if (sub.HasAttr("frameX"))
                    {
                        atlas.textures[name] = new MTexture(mTexture, name, clipRect, new Vector2(-sub.AttrInt("frameX"), -sub.AttrInt("frameY")), sub.AttrInt("frameWidth"), sub.AttrInt("frameHeight"));
                    }
                    else
                    {
                        atlas.textures[name] = new MTexture(mTexture, name, clipRect);
                    }
                }
            }
            break;

            case AtlasDataFormat.CrunchXml:
            {
                XmlDocument xml = Calc.LoadContentXML(path);
                XmlElement  at  = xml["atlas"];

                foreach (XmlElement tex in at)
                {
                    var    texturePath = tex.Attr("n", "");
                    string fsloc       = Engine.ContentDirectory + "\\" + Path.GetDirectoryName(path) + texturePath + ".png";
                    var    fileStream  = new FileStream(fsloc, FileMode.Open, FileAccess.Read);
                    var    texture     = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                    fileStream.Close();

                    var mTexture = new MTexture(texture);
                    atlas.Sources.Add(texture);

                    foreach (XmlElement sub in tex)
                    {
                        var name     = sub.Attr("n");
                        var clipRect = new Rectangle(sub.AttrInt("x"), sub.AttrInt("y"), sub.AttrInt("w"), sub.AttrInt("h"));
                        if (sub.HasAttr("fx"))
                        {
                            atlas.textures[name] = new MTexture(mTexture, name, clipRect, new Vector2(-sub.AttrInt("fx"), -sub.AttrInt("fy")), sub.AttrInt("fw"), sub.AttrInt("fh"));
                        }
                        else
                        {
                            atlas.textures[name] = new MTexture(mTexture, name, clipRect);
                        }
                    }
                }
            }
            break;

            case AtlasDataFormat.CrunchBinary:
                using (var stream = File.OpenRead(Path.Combine(Engine.ContentDirectory, path)))
                {
                    var reader   = new BinaryReader(stream);
                    var textures = reader.ReadInt16();

                    for (int i = 0; i < textures; i++)
                    {
                        var textureName = reader.ReadNullTerminatedString();
                        var texturePath = Path.Combine(Path.GetDirectoryName(path), textureName + ".png");
                        var fileStream  = new FileStream(texturePath, FileMode.Open, FileAccess.Read);
                        var texture     = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                        fileStream.Close();

                        atlas.Sources.Add(texture);

                        var mTexture    = new MTexture(texture);
                        var subtextures = reader.ReadInt16();
                        for (int j = 0; j < subtextures; j++)
                        {
                            var name = reader.ReadNullTerminatedString();
                            var x    = reader.ReadInt16();
                            var y    = reader.ReadInt16();
                            var w    = reader.ReadInt16();
                            var h    = reader.ReadInt16();
                            var fx   = reader.ReadInt16();
                            var fy   = reader.ReadInt16();
                            var fw   = reader.ReadInt16();
                            var fh   = reader.ReadInt16();

                            atlas.textures[name] = new MTexture(mTexture, name, new Rectangle(x, y, w, h), new Vector2(-fx, -fy), fw, fh);
                        }
                    }
                }
                break;

            case AtlasDataFormat.CrunchBinaryNoAtlas:
                using (var stream = File.OpenRead(Path.Combine(Engine.ContentDirectory, path + ".bin")))
                {
                    var reader  = new BinaryReader(stream);
                    var folders = reader.ReadInt16();

                    for (int i = 0; i < folders; i++)
                    {
                        var folderName = reader.ReadNullTerminatedString();
                        var folderPath = Path.Combine(Path.GetDirectoryName(path), folderName);

                        var subtextures = reader.ReadInt16();
                        for (int j = 0; j < subtextures; j++)
                        {
                            var name = reader.ReadNullTerminatedString();
                            var x    = reader.ReadInt16();
                            var y    = reader.ReadInt16();
                            var w    = reader.ReadInt16();
                            var h    = reader.ReadInt16();
                            var fx   = reader.ReadInt16();
                            var fy   = reader.ReadInt16();
                            var fw   = reader.ReadInt16();
                            var fh   = reader.ReadInt16();

                            var fileStream = new FileStream(Path.Combine(folderPath, name + ".png"), FileMode.Open, FileAccess.Read);
                            var texture    = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                            fileStream.Close();

                            atlas.Sources.Add(texture);
                            atlas.textures[name] = new MTexture(texture, new Vector2(-fx, -fy), fw, fh);
                        }
                    }
                }
                break;

            case AtlasDataFormat.Packer:

                using (var stream = File.OpenRead(Path.Combine(Engine.ContentDirectory, path + ".meta")))
                {
                    var reader = new BinaryReader(stream);
                    reader.ReadInt32();     // version
                    reader.ReadString();    // args
                    reader.ReadInt32();     // hash

                    var textures = reader.ReadInt16();
                    for (int i = 0; i < textures; i++)
                    {
                        var textureName = reader.ReadString();
                        var texturePath = Path.Combine(Path.GetDirectoryName(path), textureName + ".data");
                        var fileStream  = new FileStream(texturePath, FileMode.Open, FileAccess.Read);
                        var texture     = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                        fileStream.Close();

                        atlas.Sources.Add(texture);

                        var mTexture    = new MTexture(texture);
                        var subtextures = reader.ReadInt16();
                        for (int j = 0; j < subtextures; j++)
                        {
                            var name = reader.ReadString().Replace('\\', '/');
                            var x    = reader.ReadInt16();
                            var y    = reader.ReadInt16();
                            var w    = reader.ReadInt16();
                            var h    = reader.ReadInt16();
                            var fx   = reader.ReadInt16();
                            var fy   = reader.ReadInt16();
                            var fw   = reader.ReadInt16();
                            var fh   = reader.ReadInt16();

                            atlas.textures[name] = new MTexture(mTexture, name, new Rectangle(x, y, w, h), new Vector2(-fx, -fy), fw, fh);
                        }
                    }
                }

                break;

            case AtlasDataFormat.PackerNoAtlas:
                using (var stream = File.OpenRead(Path.Combine(Engine.ContentDirectory, path + ".meta")))
                {
                    var reader = new BinaryReader(stream);
                    reader.ReadInt32();     // version
                    reader.ReadString();    // args
                    reader.ReadInt32();     // hash

                    var folders = reader.ReadInt16();
                    for (int i = 0; i < folders; i++)
                    {
                        var folderName = reader.ReadString();
                        var folderPath = Path.Combine(Path.GetDirectoryName(path), folderName);

                        var subtextures = reader.ReadInt16();
                        for (int j = 0; j < subtextures; j++)
                        {
                            var name = reader.ReadString().Replace('\\', '/');
                            var x    = reader.ReadInt16();
                            var y    = reader.ReadInt16();
                            var w    = reader.ReadInt16();
                            var h    = reader.ReadInt16();
                            var fx   = reader.ReadInt16();
                            var fy   = reader.ReadInt16();
                            var fw   = reader.ReadInt16();
                            var fh   = reader.ReadInt16();

                            var fileStream = new FileStream(Path.Combine(folderPath, name + ".data"), FileMode.Open, FileAccess.Read);
                            var texture    = Texture2D.FromStream(Engine.Instance.GraphicsDevice, fileStream);
                            fileStream.Close();

                            atlas.Sources.Add(texture);
                            atlas.textures[name] = new MTexture(texture, new Vector2(-fx, -fy), fw, fh);
                        }
                    }
                }
                break;

            case AtlasDataFormat.CrunchXmlOrBinary:

                if (File.Exists(Path.Combine(Engine.ContentDirectory, path + ".bin")))
                {
                    ReadAtlasData(atlas, path + ".bin", AtlasDataFormat.CrunchBinary);
                }
                else
                {
                    ReadAtlasData(atlas, path + ".xml", AtlasDataFormat.CrunchXml);
                }

                break;


            default:
                throw new NotImplementedException();
            }
        }
예제 #15
0
 public patch_SpriteData(Atlas atlas)
     : base(atlas)
 {
     // no-op. MonoMod ignores this - we only need this to make the compiler shut up.
 }
예제 #16
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;
            }
        }
예제 #17
0
 public extern void orig_ctor(Atlas atlas, string xmlPath);
예제 #18
0
        /// <summary>
        /// Feed the given ModAsset into the atlas.
        /// </summary>
        public static void Ingest(this Atlas self, ModAsset asset)
        {
            // Crawl through all child assets.
            if (asset.Type == typeof(AssetTypeDirectory))
            {
                foreach (ModAsset child in asset.Children)
                {
                    self.Ingest(child);
                }
                return;
            }

            // Forcibly add the mod content to the atlas.
            if (asset.Type == typeof(Texture2D))
            {
                Logger.Log(LogLevel.Verbose, "Atlas.Ingest", $"{self.GetDataPath()} + {asset.PathVirtual}");

                string parentPath = self.GetDataPath();
                if (parentPath.StartsWith(Everest.Content.PathContentOrig))
                {
                    parentPath = parentPath.Substring(Everest.Content.PathContentOrig.Length + 1);
                }
                parentPath = parentPath.Replace('\\', '/');

                bool   lq   = false;
                string path = asset.PathVirtual;

                if (path.StartsWith(parentPath + "LQ/"))
                {
                    lq   = true;
                    path = path.Substring(parentPath.Length + 3);
                }
                else if (path.StartsWith(parentPath + "/"))
                {
                    path = path.Substring(parentPath.Length + 1);
                }
                else
                {
                    return;
                }

                VirtualTexture vtex = VirtualContentExt.CreateTexture(asset);
                MTexture       mtex;
                MTextureMeta   meta = asset.GetMeta <MTextureMeta>();
                if (meta != null)
                {
                    if (meta.Width == 0)
                    {
                        meta.Width = vtex.Width;
                    }
                    if (meta.Height == 0)
                    {
                        meta.Height = vtex.Height;
                    }
                }

                Dictionary <string, MTexture> textures = self.GetTextures();
                MTexture existing;
                if (textures.TryGetValue(path, out existing))
                {
                    if (lq && !CoreModule.Settings.LQAtlas)
                    {
                        return;
                    }

                    if (existing.Texture.GetMetadata() == asset)
                    {
                        return; // We're the currently active overlay.
                    }
                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        existing.AddOverride(vtex, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Keep width and height from existing instance.
                        existing.AddOverride(vtex, existing.DrawOffset, existing.Width, existing.Height);
                    }

                    mtex = existing;
                }
                else
                {
                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        mtex = new MTexture(vtex, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Apply width and height from replacement texture.
                        mtex = new MTexture(vtex);
                    }
                    mtex.SetAtlasPath(path);
                }

                VTextureToMTextureMap[vtex.Name] = mtex;
                self[path] = mtex;
                if (!self.Sources.Contains(vtex))
                {
                    self.Sources.Add(vtex);
                }
                return;
            }
        }
예제 #19
0
 // Patching constructors is ugly.
 public extern void orig_ctor_SpriteBank(Atlas atlas, XmlDocument xml);
예제 #20
0
 public void ctor_SpriteBank(Atlas atlas, XmlDocument xml)
 {
     orig_ctor_SpriteBank(atlas, xml);
     Everest.Content.Process(this, XMLPath);
 }
예제 #21
0
 public extern void orig_ctor_SpriteBank(Atlas atlas, string xmlPath);
예제 #22
0
 public static Atlas.AtlasDataFormat?GetDataFormat(this Atlas self)
 => ((patch_Atlas)self).DataFormat;
예제 #23
0
 public void ctor_SpriteBank(Atlas atlas, string xmlPath)
 {
     XMLPath = xmlPath;
     orig_ctor_SpriteBank(atlas, xmlPath);
 }
예제 #24
0
        // Mods can't access patch_ classes directly.
        // We thus expose any new members through extensions.

        public static Dictionary <string, MTexture> GetTextures(this Atlas self)
        => ((patch_Atlas)self).Textures;
예제 #25
0
        public PixelFontSize AddFontSize(string path, Atlas atlas = null, bool outline = false)
        {
            var data = Calc.LoadXML(path)["font"];

            return(AddFontSize(path, data, atlas, outline));
        }
예제 #26
0
 public static string[] GetDataPaths(this Atlas self)
 => ((patch_Atlas)self).DataPaths;
예제 #27
0
        public PixelFontSize AddFontSize(string path, XmlElement data, Atlas atlas = null, bool outline = false)
        {
            // check if size already exists
            var size = data["info"].AttrFloat("size");

            foreach (var fs in Sizes)
            {
                if (fs.Size == size)
                {
                    return(fs);
                }
            }

            // get textures
            Textures = new List <MTexture>();
            var pages = data["pages"];

            foreach (XmlElement page in pages)
            {
                var file      = page.Attr("file");
                var atlasPath = Path.GetFileNameWithoutExtension(file);

                if (atlas != null && atlas.Has(atlasPath))
                {
                    Textures.Add(atlas[atlasPath]);
                }
                else
                {
                    var dir = Path.GetDirectoryName(path);
                    dir = dir.Substring(Engine.ContentDirectory.Length + 1);
                    Textures.Add(MTexture.FromFile(Path.Combine(dir, file)));
                }
            }

            // create font size
            var fontSize = new PixelFontSize()
            {
                Textures   = Textures,
                Characters = new Dictionary <int, PixelFontCharacter>(),
                LineHeight = data["common"].AttrInt("lineHeight"),
                Size       = size,
                Outline    = outline
            };

            // get characters
            foreach (XmlElement character in data["chars"])
            {
                int id   = character.AttrInt("id");
                int page = character.AttrInt("page", 0);
                fontSize.Characters.Add(id, new PixelFontCharacter(id, Textures[page], character));
            }

            // get kerning
            if (data["kernings"] != null)
            {
                foreach (XmlElement kerning in data["kernings"])
                {
                    var from = kerning.AttrInt("first");
                    var to   = kerning.AttrInt("second");
                    var push = kerning.AttrInt("amount");

                    PixelFontCharacter c = null;
                    if (fontSize.Characters.TryGetValue(from, out c))
                    {
                        c.Kerning.Add(to, push);
                    }
                }
            }

            // add font size
            Sizes.Add(fontSize);
            Sizes.Sort((a, b) => { return(Math.Sign(a.Size - b.Size)); });

            return(fontSize);
        }
예제 #28
0
 public SpriteData(Atlas atlas)
 {
     Sprite = new Sprite(atlas, "");
     Atlas  = atlas;
 }
예제 #29
0
파일: Atlas.cs 프로젝트: szbrain/Everest
 public static void ResetCaches(this Atlas self)
 => ((patch_Atlas)self).ResetCaches();
예제 #30
0
 // Patching constructors is ugly.
 public extern void orig_ctor(Atlas atlas, XmlDocument xml);
예제 #31
0
파일: Atlas.cs 프로젝트: szbrain/Everest
 /// <summary>
 /// Feed the given ModAsset into the atlas.
 /// </summary>
 public static void Ingest(this Atlas self, ModAsset asset)
 => ((patch_Atlas)self).Ingest(asset);
예제 #32
0
 public void ctor(Atlas atlas, string xmlPath)
 {
     XMLPath = xmlPath;
     orig_ctor(atlas, LoadSpriteBank(xmlPath));
 }
예제 #33
0
 protected override void LoadContent()
 {
     base.LoadContent();
     Atlas = new Atlas("Content/Graphics/graphics_1.xml", true);
 }