Exemplo n.º 1
0
            public ICssValue Convert(StringSource source)
            {
                var color = default(ICssValue);
                var width = default(ICssValue);
                var style = default(ICssValue);
                var pos   = 0;

                do
                {
                    pos = source.Index;

                    if (color == null)
                    {
                        color = ColorParser.ParseColor(source);
                        source.SkipSpacesAndComments();
                    }

                    if (width == null)
                    {
                        width = source.ParseLineWidth();
                        source.SkipSpacesAndComments();
                    }

                    if (style == null)
                    {
                        style = source.ParseConstant(Map.LineStyles);
                        source.SkipSpacesAndComments();
                    }
                }while (pos != source.Index);

                return(new CssTupleValue(new[] { color, width, style }));
            }
Exemplo n.º 2
0
        public static void Load(string path, AssetStore <string> assets)
        {
            foreach (PropertyBag raceProp in PropertyBag.FromFile(path))
            {
                string name   = raceProp.Name;
                int    speed  = raceProp.GetOrDefault("speed", Energy.NormalSpeed);
                int    health = raceProp.GetOrDefault("health", 1);

                Animation animation = assets.GetAsset <Animation>(raceProp["animation"].Value);

                Color color = ColorParser.ParseColor(raceProp["color"].Value);

                Race race = new Race(name, animation, color, speed, health);
                assets.AddAsset(name, race);
            }
        }
Exemplo n.º 3
0
        public static void Load(string path, AssetStore <string> assets)
        {
            foreach (PropertyBag tileProp in PropertyBag.FromFile(path))
            {
                string name          = tileProp.Name;
                bool   isSolid       = tileProp.GetOrDefault("solid", false);
                bool   isTransparent = tileProp.GetOrDefault("transparent", true);
                byte   id            = _nextId++;

                string animation = tileProp.GetOrDefault("animation", null);
                Sprite sprite    = null;

                if (string.IsNullOrWhiteSpace(animation))
                {
                    string spriteName = tileProp.GetOrDefault("sprite", name);
                    sprite = assets.GetAsset <Sprite>(spriteName);
                }

                Color color = ColorParser.ParseColor(tileProp["color"].Value.ToLower().Trim());

                Tile tile = new Tile(id, sprite, color, isSolid, isTransparent, animation);
                assets.AddAsset(name, tile);
            }
        }
            public ICssValue Convert(StringSource source)
            {
                var layers = new List <BackgroundLayer>();
                var color  = default(ICssValue);
                var pos    = 0;
                var c      = source.SkipSpacesAndComments();

                while (!source.IsDone && color == null)
                {
                    var layer = new BackgroundLayer();

                    if (layers.Count > 0)
                    {
                        if (c != Symbols.Comma)
                        {
                            return(null);
                        }

                        c = source.SkipCurrentAndSpaces();
                    }

                    do
                    {
                        pos = source.Index;

                        if (layer.Source == null)
                        {
                            layer.Source = source.ParseImageSource();
                            c            = source.SkipSpacesAndComments();
                        }

                        if (layer.Position == null)
                        {
                            layer.Position = source.ParsePoint();
                            c = source.SkipSpacesAndComments();

                            if (c == Symbols.Solidus && layer.Size == null)
                            {
                                c          = source.SkipSpacesAndComments();
                                layer.Size = source.ParseSize();
                                c          = source.SkipSpacesAndComments();
                            }
                        }

                        if (layer.Repeat == null)
                        {
                            layer.Repeat = source.ParseBackgroundRepeat();
                            c            = source.SkipSpacesAndComments();
                        }

                        if (layer.Attachment == null)
                        {
                            layer.Attachment = source.ParseConstant(Map.BackgroundAttachments);
                            c = source.SkipSpacesAndComments();
                        }

                        if (layer.Origin == null)
                        {
                            layer.Origin = source.ParseConstant(Map.BoxModels);
                            c            = source.SkipSpacesAndComments();
                        }

                        if (layer.Clip == null)
                        {
                            layer.Clip = source.ParseConstant(Map.BoxModels);
                            c          = source.SkipSpacesAndComments();
                        }

                        if (color == null)
                        {
                            color = ColorParser.ParseColor(source);
                            c     = source.SkipSpacesAndComments();
                        }
                    }while (pos != source.Index);

                    layers.Add(layer);
                }

                return(new Background(new CssListValue(layers.OfType <ICssValue>().ToArray()), color));
            }
Exemplo n.º 5
0
            public ICssValue Convert(StringSource source)
            {
                var layers = new List <CssBackgroundLayerValue>();
                var color  = default(ICssValue);
                var pos    = 0;
                var c      = source.SkipSpacesAndComments();

                while (!source.IsDone && color == null)
                {
                    if (layers.Count > 0)
                    {
                        if (c != Symbols.Comma)
                        {
                            return(null);
                        }

                        c = source.SkipCurrentAndSpaces();
                    }

                    var image      = default(ICssImageValue);
                    var position   = default(Point?);
                    var size       = default(CssBackgroundSizeValue);
                    var repeat     = default(CssImageRepeatsValue);
                    var attachment = default(ICssValue);
                    var origin     = default(ICssValue);
                    var clip       = default(ICssValue);

                    do
                    {
                        pos = source.Index;

                        if (image == null)
                        {
                            image = source.ParseImageSource();
                            c     = source.SkipSpacesAndComments();
                        }

                        if (position == null)
                        {
                            position = source.ParsePoint();
                            c        = source.SkipSpacesAndComments();

                            if (c == Symbols.Solidus && size == null)
                            {
                                c    = source.SkipSpacesAndComments();
                                size = source.ParseSize();
                                c    = source.SkipSpacesAndComments();
                            }
                        }

                        if (repeat == null)
                        {
                            repeat = source.ParseBackgroundRepeat();
                            c      = source.SkipSpacesAndComments();
                        }

                        if (attachment == null)
                        {
                            attachment = source.ParseConstant(Map.BackgroundAttachments);
                            c          = source.SkipSpacesAndComments();
                        }

                        if (origin == null)
                        {
                            origin = source.ParseConstant(Map.BoxModels);
                            c      = source.SkipSpacesAndComments();
                        }

                        if (clip == null)
                        {
                            clip = source.ParseConstant(Map.BoxModels);
                            c    = source.SkipSpacesAndComments();
                        }

                        if (color == null)
                        {
                            color = ColorParser.ParseColor(source);
                            c     = source.SkipSpacesAndComments();
                        }
                    }while (pos != source.Index);

                    layers.Add(new CssBackgroundLayerValue(
                                   image,
                                   position,
                                   size,
                                   repeat,
                                   attachment,
                                   origin,
                                   clip));
                }

                return(new CssBackgroundValue(new CssListValue(layers.OfType <ICssValue>().ToArray()), color ?? new CssInitialValue(InitialValues.BackgroundColorDecl)));
            }
            public ICssValue Convert(StringSource source)
            {
                // [ <bg-layer> , ]* <final-bg-layer>
                // where:
                //   <bg-layer> = <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box> || <box>
                //   <final-bg-layer> = <'background-color'> || <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box> || <box>
                // where:
                //   <bg-image> = none | <image>
                //   <bg-position> = [ [ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ] ]
                //   <bg-size> = [ <length-percentage> | auto ]{1,2} | cover | contain
                //   <repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}
                //   <attachment> = scroll | fixed | local
                //   <box> = border-box | padding-box | content-box
                //   <image> = <url> | <image()> | <image-set()> | <element()> | <paint()> | <cross-fade()> | <gradient>
                //   <length-percentage> = <length> | <percentage>
                //   <image()> = image( <image-tags>? [ <image-src>? , <color>? ]! )
                //   <image-set()> = image-set( <image-set-option># )
                //   <element()> = element( <id-selector> )
                //   <paint()> = paint( <ident>, <declaration-value>? )
                //   <cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? )
                //   <gradient> = <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> | <conic-gradient()>
                //   <image-tags> = ltr | rtl
                //   <image-src> = <url> | <string>
                //   <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>
                //   <image-set-option> = [ <image> | <string> ] <resolution>
                //   <id-selector> = <hash-token>
                //   <cf-mixing-image> = <percentage>? && <image>
                //   <cf-final-image> = <image> | <color>
                //   <linear-gradient()> = linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
                //   <repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
                //   <radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
                //   <repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
                //   <conic-gradient()> = conic-gradient( [ from <angle> ]? [ at <position> ]?, <angular-color-stop-list> )
                //   <rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
                //   <rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
                //   <hsl()> = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )
                //   <hsla()> = hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )
                //   <side-or-corner> = [ left | right ] || [ top | bottom ]
                //   <color-stop-list> = [ <linear-color-stop> [, <linear-color-hint>]? ]# , <linear-color-stop>
                //   <ending-shape> = circle | ellipse
                //   <size> = closest-side | farthest-side | closest-corner | farthest-corner | <length> | <length-percentage>{2}
                //   <position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]
                //   <angular-color-stop-list> = [ <angular-color-stop> [, <angular-color-hint>]? ]# , <angular-color-stop>
                //   <alpha-value> = <number> | <percentage>
                //   <hue> = <number> | <angle>
                //   <linear-color-stop> = <color> <color-stop-length>?
                //   <linear-color-hint> = <length-percentage>
                //   <angular-color-stop> = <color> && <color-stop-angle>?
                //   <angular-color-hint> = <angle-percentage>
                //   <color-stop-length> = <length-percentage>{1,2}
                //   <color-stop-angle> = <angle-percentage>{1,2}
                //   <angle-percentage> = <angle> | <percentage>
                var layers = new List <CssBackgroundLayerValue>();
                var color  = default(ICssValue);
                var pos    = 0;
                var c      = source.SkipSpacesAndComments();

                while (!source.IsDone && color == null)
                {
                    if (layers.Count > 0)
                    {
                        if (c != Symbols.Comma)
                        {
                            return(null);
                        }

                        c = source.SkipCurrentAndSpaces();
                    }

                    var image      = default(ICssImageValue);
                    var position   = default(Point?);
                    var size       = default(CssBackgroundSizeValue);
                    var repeat     = default(CssImageRepeatsValue);
                    var attachment = default(ICssValue);
                    var origin     = default(ICssValue);
                    var clip       = default(ICssValue);

                    do
                    {
                        pos = source.Index;

                        if (image == null)
                        {
                            image = source.ParseImageSource() ?? (source.IsIdentifier(CssKeywords.None) ? new CssNoneValue() : null);
                            c     = source.SkipSpacesAndComments();
                        }

                        if (position == null)
                        {
                            position = source.ParsePoint();
                            c        = source.SkipSpacesAndComments();

                            if (c == Symbols.Solidus && size == null)
                            {
                                c    = source.SkipSpacesAndComments();
                                size = source.ParseSize();
                                c    = source.SkipSpacesAndComments();
                            }
                        }

                        if (repeat == null)
                        {
                            repeat = source.ParseBackgroundRepeat();
                            c      = source.SkipSpacesAndComments();
                        }

                        if (attachment == null)
                        {
                            attachment = source.ParseConstant(Map.BackgroundAttachments);
                            c          = source.SkipSpacesAndComments();
                        }

                        if (origin == null)
                        {
                            origin = source.ParseConstant(Map.BoxModels);
                            c      = source.SkipSpacesAndComments();
                        }

                        if (clip == null)
                        {
                            clip = source.ParseConstant(Map.BoxModels);
                            c    = source.SkipSpacesAndComments();
                        }

                        if (color == null)
                        {
                            color = ColorParser.ParseColor(source);
                            c     = source.SkipSpacesAndComments();
                        }
                    }while (pos != source.Index);

                    layers.Add(new CssBackgroundLayerValue(
                                   image,
                                   position,
                                   size,
                                   repeat,
                                   attachment,
                                   origin,
                                   clip));
                }

                return(new CssBackgroundValue(new CssListValue(layers.OfType <ICssValue>().ToArray()), color ?? new CssInitialValue(InitialValues.BackgroundColorDecl)));
            }