Example #1
0
        public IOsbSpriteCommand ParseCommandLine(string line, int lineNumber, CommandPosition initialPosition)
        {
            var values = line.Trim().Split(',');

            if (string.IsNullOrEmpty(values[3]))
            {
                values[3] = values[2];
            }

            var commandType = values[0];
            var easing      = (OsbEasing)int.Parse(values[1]);
            var startTime   = double.Parse(values[2], CultureInfo.InvariantCulture);
            var endTime     = double.Parse(values[3], CultureInfo.InvariantCulture);

            switch (commandType)
            {
            case "F":
            {
                var startValue = double.Parse(values[4], CultureInfo.InvariantCulture);
                var endValue   = values.Length > 5 ? double.Parse(values[5], CultureInfo.InvariantCulture) : startValue;
                return(new FadeCommand()
                    {
                        Easing = easing,
                        StartTime = startTime,
                        EndTime = endTime,
                        StartValue = startValue,
                        EndValue = endValue,
                        Line = lineNumber,
                    });
            }

            case "S":
            {
                var startValue = double.Parse(values[4], CultureInfo.InvariantCulture);
                var endValue   = values.Length > 5 ? double.Parse(values[5], CultureInfo.InvariantCulture) : startValue;
                return(new ScaleCommand()
                    {
                        Easing = easing,
                        StartTime = startTime,
                        EndTime = endTime,
                        StartValue = startValue,
                        EndValue = endValue,
                        Line = lineNumber,
                    });
            }

            case "V":
            {
                var startX = double.Parse(values[4], CultureInfo.InvariantCulture);
                var startY = double.Parse(values[5], CultureInfo.InvariantCulture);
                var endX   = values.Length > 6 ? double.Parse(values[6], CultureInfo.InvariantCulture) : startX;
                var endY   = values.Length > 7 ? double.Parse(values[7], CultureInfo.InvariantCulture) : startY;
                return(new VectorScaleCommand()
                    {
                        Easing = easing,
                        StartTime = startTime,
                        EndTime = endTime,
                        StartValue = new CommandScale()
                        {
                            X = startX, Y = startY
                        },
                        EndValue = new CommandScale()
                        {
                            X = endX, Y = endY
                        },
                        Line = lineNumber,
                    });
            }

            case "R":
            {
                var startValue = double.Parse(values[4], CultureInfo.InvariantCulture);
                var endValue   = values.Length > 5 ? double.Parse(values[5], CultureInfo.InvariantCulture) : startValue;
                return(new RotateCommand()
                    {
                        Easing = easing,
                        StartTime = startTime,
                        EndTime = endTime,
                        StartValue = startValue,
                        EndValue = endValue,
                        Line = lineNumber,
                    });
            }

            case "M":
            {
                var startX = double.Parse(values[4], CultureInfo.InvariantCulture);
                var startY = double.Parse(values[5], CultureInfo.InvariantCulture);
                var endX   = values.Length > 6 ? double.Parse(values[6], CultureInfo.InvariantCulture) : startX;
                var endY   = values.Length > 7 ? double.Parse(values[7], CultureInfo.InvariantCulture) : startY;

                var m = new MoveCommand()
                {
                    Easing     = easing,
                    StartTime  = startTime,
                    EndTime    = endTime,
                    StartValue = new CommandPosition()
                    {
                        X = startX, Y = startY
                    },
                    EndValue = new CommandPosition()
                    {
                        X = endX, Y = endY
                    },
                    Line = lineNumber,
                };
                m.SetDefaultValue(initialPosition);
                return(m);
            }

            case "MX":
            {
                var startValue = double.Parse(values[4], CultureInfo.InvariantCulture);
                var endValue   = values.Length > 5 ? double.Parse(values[5], CultureInfo.InvariantCulture) : startValue;
                var mx         = new MoveXCommand()
                {
                    Easing     = easing,
                    StartTime  = startTime,
                    EndTime    = endTime,
                    StartValue = startValue,
                    EndValue   = endValue,
                    Line       = lineNumber,
                };
                mx.SetDefaultValue(initialPosition);
                return(mx);
            }

            case "MY":
            {
                var startValue = double.Parse(values[4], CultureInfo.InvariantCulture);
                var endValue   = values.Length > 5 ? double.Parse(values[5], CultureInfo.InvariantCulture) : startValue;
                var my         = new MoveYCommand()
                {
                    Easing     = easing,
                    StartTime  = startTime,
                    EndTime    = endTime,
                    StartValue = startValue,
                    EndValue   = endValue,
                    Line       = lineNumber,
                };
                my.SetDefaultValue(initialPosition);
                return(my);
            }

            case "C":
            {
                var startR = byte.Parse(values[4], CultureInfo.InvariantCulture);
                var startG = byte.Parse(values[5], CultureInfo.InvariantCulture);
                var startB = byte.Parse(values[6], CultureInfo.InvariantCulture);
                var endR   = values.Length > 7 ? byte.Parse(values[7], CultureInfo.InvariantCulture) : startR;
                var endG   = values.Length > 8 ? byte.Parse(values[8], CultureInfo.InvariantCulture) : startG;
                var endB   = values.Length > 9 ? byte.Parse(values[9], CultureInfo.InvariantCulture) : startB;
                return(new ColorCommand()
                    {
                        Easing = easing,
                        StartTime = startTime,
                        EndTime = endTime,
                        StartValue = new CommandColor()
                        {
                            R = startR, G = startG, B = startB
                        },
                        EndValue = new CommandColor()
                        {
                            R = endR, G = endG, B = endB
                        },
                        Line = lineNumber,
                    });
            }

            case "P":
            {
                var type = GetParameterType(values[4]);
                return(new ParameterCommand()
                    {
                        Easing = easing,
                        StartTime = startTime,
                        EndTime = endTime,
                        StartValue = type,
                        EndValue = type,
                        Line = lineNumber,
                    });
            }

            default:
                throw new FormatException($"Invalid Commandtype {commandType} detected");
            }
        }