예제 #1
0
        private void SpriteSheetParseLoop(SpriteSheetNode rootNode)
        {
            while (tokenStream.HasMoreTokens && !AdvanceIfTokenType(StyleTokenType.BracesClose))
            {
                StyleToken typeToken  = tokenStream.Current;
                string     optionName = AssertTokenTypeAndAdvance(StyleTokenType.Identifier).ToLower();
                bool       typeFound  = false;
                for (int index = 0; index < s_SpriteSheetOptionNames.Length; index++)
                {
                    string name = s_SpriteSheetOptionNames[index].Item1;
                    if (name == optionName)
                    {
                        AssertTokenTypeAndAdvance(StyleTokenType.EqualSign);
                        StyleToken variableToken = tokenStream.Current;

                        PropertyNode propertyNode = StyleASTNodeFactory.PropertyNode(s_SpriteSheetOptionNames[index].Item2);
                        propertyNode.AddChildNode(ParsePropertyValue());
                        propertyNode.WithLocation(variableToken);

                        rootNode.AddChildNode(propertyNode);

                        typeFound = true;

                        break;
                    }
                }

                if (!typeFound)
                {
                    throw new ParseException(typeToken, $"{optionName} is not a supported spritesheet option. Valid values are: {FormatOptionList(s_SpriteSheetOptionNames)}\n");
                }

                AssertTokenTypeAndAdvance(StyleTokenType.EndStatement);
            }
        }
예제 #2
0
        internal static SpriteSheetNode SpriteSheetNode(string identifier)
        {
            SpriteSheetNode node = s_SpriteSheetNodePool.Get();

            node.identifier = identifier;
            node.type       = StyleASTNodeType.SpriteSheetDeclaration;
            return(node);
        }
예제 #3
0
        private AnimationData CompileSpriteSheetAnimation(SpriteSheetNode node, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            AnimationData data = new AnimationData();

            data.name          = node.identifier;
            data.fileName      = context.fileName;
            data.animationType = AnimationType.SpriteSheet;
            data.options       = CompileSpriteSheetOptions(node);
            return(data);
        }
예제 #4
0
        private void ParseSpriteSheet()
        {
            StyleToken      initialStyleToken = tokenStream.Current;
            SpriteSheetNode rootNode          = StyleASTNodeFactory.SpriteSheetNode(initialStyleToken);

            rootNode.WithLocation(initialStyleToken);
            tokenStream.Advance();
            AssertTokenTypeAndAdvance(StyleTokenType.BracesOpen);
            SpriteSheetParseLoop(rootNode);
            nodes.Add(rootNode);
        }
예제 #5
0
        private AnimationOptions CompileSpriteSheetOptions(SpriteSheetNode node)
        {
            AnimationOptions options = new AnimationOptions();

            LightList <StyleASTNode> spriteSheetProperties = node.children;

            if (spriteSheetProperties == null)
            {
                return(options);
            }

            for (int i = 0; i < spriteSheetProperties.Count; i++)
            {
                if (spriteSheetProperties[i] is PropertyNode property)
                {
                    string       optionName = property.identifier.ToLower();
                    StyleASTNode value      = property.children[0];

                    switch (optionName)
                    {
                    case "iterations":
                        options.iterations = (int)StylePropertyMappers.MapNumberOrInfinite(value, context);
                        break;

                    case "delay":
                        options.delay = StylePropertyMappers.MapUITimeMeasurement(value, context);
                        break;

                    case "duration":
                        options.duration = StylePropertyMappers.MapUITimeMeasurement(value, context);
                        break;

                    case "looptype":
                        options.loopType = StylePropertyMappers.MapEnum <AnimationLoopType>(value, context);
                        break;

                    case "direction":
                        options.direction = StylePropertyMappers.MapEnum <AnimationDirection>(value, context);
                        break;

                    case "forwardstartdelay":
                        options.forwardStartDelay = (int)StylePropertyMappers.MapNumber(value, context);
                        break;

                    case "reversestartdelay":
                        options.reverseStartDelay = (int)StylePropertyMappers.MapNumber(value, context);
                        break;

                    case "fps":
                        options.fps = (int)StylePropertyMappers.MapNumber(value, context);
                        break;

                    case "startframe":
                        options.startFrame = (int)StylePropertyMappers.MapNumber(value, context);
                        break;

                    case "endframe":
                        options.endFrame = (int)StylePropertyMappers.MapNumber(value, context);
                        break;

                    case "pathprefix":
                        options.pathPrefix = StylePropertyMappers.MapString(value, context);
                        break;

                    default:
                        throw new CompileException(property, "Invalid option argument for animation");
                    }
                }
                else
                {
                    throw new CompileException(spriteSheetProperties[i], "Invalid option argument for animation");
                }
            }

            return(options);
        }