public static Boolean Check(Command command, InputBuffer input) { if (command == null) throw new ArgumentNullException("command"); if (input == null) throw new ArgumentNullException("input"); Int32 element_index = command.Elements.Count - 1; for (Int32 input_index = 0; input_index != input.Size; ++input_index) { Int32 match_index = ScanForMatch(command, element_index, input, input_index); if (match_index == Int32.MinValue) return false; if (element_index > 0) { if (match_index > command.Time) return false; --element_index; input_index = match_index; } else if (element_index == 0) { return match_index <= command.Time; } else { return false; } } return false; }
static Int32 ScanForMatch(Command command, Int32 element_index, InputBuffer input, Int32 input_index) { if (command == null) throw new ArgumentNullException("command"); if (input == null) throw new ArgumentNullException("input"); CommandElement element = command.Elements[element_index]; Int32 scanlength = Math.Min(input.Size, command.Time); for (Int32 i = input_index; i < scanlength; ++i) { //Only check for the last element at the top of the input buffer if (element_index == command.Elements.Count - 1) { if (element.TriggerOnRelease == null) { if (i != input_index) return Int32.MinValue; } else { if (i - 1 != input_index && i != input_index) return Int32.MinValue; } } if (ElementMatch(element, input, i) == true) { //If no match, confirm CommandElement.NothingElse before going back a tick in the input. if (element_index < command.Elements.Count - 1) { CommandElement nextelement = command.Elements[element_index + 1]; if (nextelement.NothingElse == true && input.AreIdentical(input_index, i) == false) continue; } return i; } } return Int32.MinValue; }
Command BuildCommand(String name, String text, Int32 time, Int32 buffertime) { if (name == null) throw new ArgumentNullException("name"); if (text == null) throw new ArgumentNullException("text"); if (time < 0) throw new ArgumentOutOfRangeException("time"); if (buffertime < 0) throw new ArgumentOutOfRangeException("buffertime"); Command command = new Command(name, text, time, buffertime, ParseCommandText(text)); if (command.IsValid == false) { Log.Write(LogLevel.Warning, LogSystem.CommandSystem, "Invalid command - '{0}'", name); } return command; }