Exemplo n.º 1
0
        public override List <ScriptAction> Load(Stream stream)
        {
            List <RealTouchCommand> commands = new List <RealTouchCommand>();

            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true))
            {
                while (!reader.EndOfStream)
                {
                    string           line    = reader.ReadLine();
                    RealTouchCommand command = RealTouchCommand.Parse(line);
                    if (command != null)
                    {
                        commands.Add(command);
                    }
                }
            }

            List <RawScriptAction> intermediateResult = ConvertToRawFunscript(commands);
            List <FunScriptAction> finalResult        = intermediateResult.Select(raw => new FunScriptAction
            {
                TimeStamp = raw.TimeStamp,
                Position  = raw.Position
            }).ToList();

            //TODO Smooth movement (e.g. CH_Corruptors.ott @ 21:00)
            finalResult = RawScriptConverter.Convert(intermediateResult);

            return(finalResult.Cast <ScriptAction>().ToList());
        }
Exemplo n.º 2
0
        private static List <RealTouchCommand> RemoveRepeatingCommands(List <RealTouchCommand> commands)
        {
            List <RealTouchCommand> result = new List <RealTouchCommand>();

            foreach (RealTouchCommand command in commands)
            {
                if (result.Count == 0)
                {
                    result.Add(command);
                    continue;
                }

                RealTouchCommand previous = result.Last();

                if (command.Continues(previous))
                {
                    result.Remove(previous);
                    result.Add(command.Merge(previous));
                }
                else
                {
                    result.Add(command);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 public override RealTouchCommand Merge(RealTouchCommand last)
 {
     return(new RealTouchStopCommand
     {
         Axis = Axis,
         TimeStamp = last.TimeStamp
     });
 }
Exemplo n.º 4
0
            public bool Continues(RealTouchCommand last)
            {
                if (GetType() != last.GetType())
                {
                    return(false);
                }

                return(ContinuesInternal(last));
            }
Exemplo n.º 5
0
            public static RealTouchCommand Parse(string line)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        return(null);
                    }

                    string[] parts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length < 2)
                    {
                        return(null);
                    }


                    TimeSpan timestamp = ParseDuration(parts[0]);

                    RealTouchCommand command = null;

                    switch (parts[1])
                    {
                    case "V":
                        command = new RealTouchVectorMovementCommand();
                        break;

                    case "P":
                        command = new RealTouchPeriodicMovementCommand();
                        break;

                    case "S":
                        command = new RealTouchStopCommand();
                        break;

                    default:
                        return(null);
                    }

                    if (command.MinParametersCount > parts.Length - 2)
                    {
                        return(null);
                    }

                    command.TimeStamp = timestamp;
                    command.Init(parts, 2);

                    return(command);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Could not parse line '{0}': {1}", line, e.Message);
                    return(null);
                }
            }
Exemplo n.º 6
0
            public override RealTouchCommand Merge(RealTouchCommand last)
            {
                RealTouchVectorMovementCommand previous = (RealTouchVectorMovementCommand)last;

                return(new RealTouchVectorMovementCommand
                {
                    Axis = Axis,
                    Direction = Direction,
                    TimeStamp = previous.TimeStamp,
                    Duration = (TimeStamp + Duration) - previous.TimeStamp,
                    Magnitude = Magnitude
                });
            }
Exemplo n.º 7
0
            protected override bool ContinuesInternal(RealTouchCommand last)
            {
                RealTouchVectorMovementCommand previous = (RealTouchVectorMovementCommand)last;

                if (previous.Direction != Direction)
                {
                    return(false);
                }
                if (Math.Abs((previous.TimeStamp + previous.Duration - TimeStamp).TotalMilliseconds) > 50)
                {
                    return(false);
                }
                if (Math.Abs(previous.Magnitude - Magnitude) > 10)
                {
                    return(false);
                }

                return(true);
            }
Exemplo n.º 8
0
 protected override bool ContinuesInternal(RealTouchCommand last)
 {
     return(true);
 }
Exemplo n.º 9
0
 protected abstract bool ContinuesInternal(RealTouchCommand last);
Exemplo n.º 10
0
 public abstract RealTouchCommand Merge(RealTouchCommand last);