Example #1
0
        public Stylesheet Load(AssetLoaderContext context, string assetName)
        {
            var xml = context.Load <string>(assetName);

            var xDoc = XDocument.Parse(xml);
            var attr = xDoc.Root.Attribute("TextureRegionAtlas");

            if (attr == null)
            {
                throw new Exception("Mandatory attribute 'TextureRegionAtlas' doesnt exist");
            }

            var textureRegionAtlas = context.Load <TextureRegionAtlas>(attr.Value);

            // Load fonts
            var fonts     = new Dictionary <string, SpriteFont>();
            var fontsNode = xDoc.Root.Element("Fonts");

            foreach (var el in fontsNode.Elements())
            {
                var font = el.Attribute("File").Value;
                fonts[el.Attribute(BaseContext.IdName).Value] = context.Load <SpriteFont>(font);
            }

            return(Stylesheet.LoadFromSource(xml,
                                             name => textureRegionAtlas[name],
                                             name => fonts[name]));
        }
Example #2
0
        public Stylesheet Load(AssetLoaderContext context, string assetName)
        {
            var xml = context.Load <string>(assetName);

            var xDoc = XDocument.Parse(xml);
            var attr = xDoc.Root.Attribute("TextureRegionAtlas");

            if (attr == null)
            {
                throw new Exception("Mandatory attribute 'TextureRegionAtlas' doesnt exist");
            }

            var textureRegionAtlas = context.Load <TextureRegionAtlas>(attr.Value);

            // Load fonts
            var fonts     = new Dictionary <string, SpriteFontBase>();
            var fontsNode = xDoc.Root.Element("Fonts");

            foreach (var el in fontsNode.Elements())
            {
                SpriteFontBase font = null;

                var fontFile = el.Attribute("File").Value;
                if (fontFile.EndsWith(".ttf"))
                {
                    var parts = new List <string>();
                    parts.Add(fontFile);

                    var typeAttribute = el.Attribute("Type");
                    if (typeAttribute != null)
                    {
                        parts.Add(typeAttribute.Value);

                        var amountAttribute = el.Attribute("Amount");
                        parts.Add(amountAttribute.Value);
                    }

                    parts.Add(el.Attribute("Size").Value);
                    font = context.Load <DynamicSpriteFont>(string.Join(":", parts));
                }
                else if (fontFile.EndsWith(".fnt"))
                {
                    font = context.Load <StaticSpriteFont>(fontFile);
                }
                else
                {
                    throw new Exception(string.Format("Font '{0}' isn't supported", fontFile));
                }

                fonts[el.Attribute(BaseContext.IdName).Value] = font;
            }

            return(Stylesheet.LoadFromSource(xml, textureRegionAtlas, fonts));
        }
Example #3
0
        public TextureRegion Load(AssetLoaderContext context, string assetName)
        {
            if (assetName.Contains(":"))
            {
                // First part is texture region atlas name
                // Second part is texture region name
                var parts = assetName.Split(':');
                var textureRegionAtlas = context.Load <TextureRegionAtlas>(parts[0]);
                return(textureRegionAtlas[parts[1]]);
            }

            // Ordinary texture
            var texture = context.Load <Texture2D>(assetName);

            return(new TextureRegion(texture));
        }
Example #4
0
        public Stylesheet Load(AssetLoaderContext context, string assetName)
        {
            var xml = context.Load <string>(assetName);

            var xDoc = XDocument.Parse(xml);
            var attr = xDoc.Root.Attribute("TextureRegionAtlas");

            if (attr == null)
            {
                throw new Exception("Mandatory attribute 'TextureRegionAtlas' doesnt exist");
            }

            var textureRegionAtlas = context.Load <TextureRegionAtlas>(attr.Value);

            // Load fonts
            var fonts     = new Dictionary <string, SpriteFont>();
            var fontsNode = xDoc.Root.Element("Fonts");

            foreach (var el in fontsNode.Elements())
            {
                var font = el.Attribute("File").Value;
                fonts[el.Attribute(BaseContext.IdName).Value] = context.Load <SpriteFont>(font);
            }

            return(Stylesheet.LoadFromSource(xml,
                                             name =>
            {
                TextureRegion region;

                if (!textureRegionAtlas.Regions.TryGetValue(name, out region))
                {
                    var color = ColorStorage.FromName(name);
                    if (color != null)
                    {
                        return new SolidBrush(color.Value);
                    }
                }
                else
                {
                    return region;
                }

                throw new Exception(string.Format("Could not find parse IBrush '{0}'", name));
            },
                                             name => fonts[name]));
        }
Example #5
0
        public UserProfile Load(AssetLoaderContext context, string assetName)
        {
            var data = context.Load <string>(assetName);

            var xDoc = XDocument.Parse(data);

            var result = new UserProfile
            {
                Name  = xDoc.Root.Element("Name").Value,
                Score = int.Parse(xDoc.Root.Element("Score").Value)
            };

            return(result);
        }
Example #6
0
        public TextureRegionAtlas Load(AssetLoaderContext context, string assetName)
        {
            var xml = context.Load <string>(assetName);

            return(TextureRegionAtlas.FromXml(xml, name => context.Load <Texture2D>(name)));
        }
Example #7
0
        public TextureRegionAtlas Load(AssetLoaderContext context, string assetName)
        {
            var data = context.Load <string>(assetName);

            return(TextureRegionAtlas.Load(data, name => context.Load <Texture2D>(name)));
        }