Beispiel #1
0
		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;
		}
Beispiel #2
0
		public CommandManager(CommandSystem commandsystem, String filepath, ReadOnlyList<Command> commands)
		{
			if (commandsystem == null) throw new ArgumentNullException("commandsystem");
			if (filepath == null) throw new ArgumentNullException("filepath");
			if (commands == null) throw new ArgumentNullException("commands");

			m_commandsystem = commandsystem;
			m_filepath = filepath;
			m_commands = commands;
			m_commandcount = new Dictionary<String, BufferCount>(StringComparer.Ordinal);
			m_inputbuffer = new InputBuffer();
			m_activecommands = new List<String>();

			foreach (Command command in Commands)
			{
				if (m_commandcount.ContainsKey(command.Name) == true) continue;

				m_commandcount.Add(command.Name, new BufferCount());
			}
		}
Beispiel #3
0
		static Boolean ElementMatch(CommandElement element, InputBuffer input, Int32 input_index)
		{
			ButtonState state = input.GetState(input_index, element);

			if (element.HeldDown == true)
			{
				Boolean result = (state == ButtonState.Down || state == ButtonState.Pressed);
				return result;
			}
			else if (element.TriggerOnRelease != null)
			{
				if (input_index >= input.Size)
				{
					return false;
				}

				if (input_index == 0 || input.GetState(input_index - 1, element) != ButtonState.Released)
				{
					return false;
				}

				Int32 holdcount = 1;
				for (Int32 i = input_index + 1; i < input.Size; ++i, ++holdcount) if (input.GetState(i, element) != ButtonState.Down) break;

				if (holdcount < element.TriggerOnRelease.Value)
				{
					return false;
				}
			}
			else
			{
				if (state != ButtonState.Pressed)
				{
					return false;
				}
			}

			return true;
		}
Beispiel #4
0
		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;
		}
Beispiel #5
0
		void Test()
		{
			Command command = BuildCommand("Attack", "~10$B, $F, x", 15, 1);

			InputBuffer input = new InputBuffer();
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left, Facing.Right);
			input.Add(PlayerButton.Left | PlayerButton.Right, Facing.Right);
			input.Add(PlayerButton.Right, Facing.Right);
			input.Add(PlayerButton.Right | PlayerButton.X, Facing.Right);

			Boolean check = CommandChecker.Check(command, input);
		}
Beispiel #6
0
        void Test()
        {
            Command command = BuildCommand("Attack", "~10$B, $F, x", 15, 1);

            InputBuffer input = new InputBuffer();

            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left, Facing.Right);
            input.Add(PlayerButton.Left | PlayerButton.Right, Facing.Right);
            input.Add(PlayerButton.Right, Facing.Right);
            input.Add(PlayerButton.Right | PlayerButton.X, Facing.Right);

            Boolean check = CommandChecker.Check(command, input);
        }
Beispiel #7
0
 public DebuggerProxy(InputBuffer data)
 {
     m_data = data.m_buffer;
 }
Beispiel #8
0
			public DebuggerProxy(InputBuffer data)
			{
				m_data = data.m_buffer;
			}