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()); }
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); }
public override RealTouchCommand Merge(RealTouchCommand last) { return(new RealTouchStopCommand { Axis = Axis, TimeStamp = last.TimeStamp }); }
public bool Continues(RealTouchCommand last) { if (GetType() != last.GetType()) { return(false); } return(ContinuesInternal(last)); }
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); } }
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 }); }
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); }
protected override bool ContinuesInternal(RealTouchCommand last) { return(true); }
protected abstract bool ContinuesInternal(RealTouchCommand last);
public abstract RealTouchCommand Merge(RealTouchCommand last);