Esempio n. 1
0
 /**
  * Tests the setKeyCodes() method.
  * @param array $expected The expected value.
  * @param int|array $keyCodes The key codes to be set.
  * @covers \ManiaScript\Builder\Event\KeyPress::setKeyCodes
  * @dataProvider providerSetKeyCodes
  */
 public function testSetKeyCodes($expected, $keyCodes)
 {
     $event = new KeyPress();
     $result = $event->setKeyCodes($keyCodes);
     $this->assertPropertyEquals($expected, $event, 'keyCodes');
     $this->assertEquals($event, $result);
 }
Esempio n. 2
0
 /**
  * Builds the condition to be used for the specified event.
  * @param \ManiaScript\Builder\Event\KeyPress $event The event.
  * @return string The condition.
  */
 protected function buildCondition($event)
 {
     $conditions = array();
     foreach ($event->getKeyCodes() as $code) {
         $conditions[$code] = 'Event.KeyCode == ' . $code;
     }
     $result = '';
     if (!empty($conditions)) {
         $result = implode(' || ', $conditions);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * Adds a KeyPress event to the ManiaScript.
  * @param string $code The code to be executed.
  * @param array $keyCodes The codes of the keys on which the code should be executed.
  * @param int $priority The priority, 0 for most important, bigger for less important.
  * @param boolean $inline Whether this event is handled inline, i.e. without wrapping function.
  * @return $this Implementing fluent interface.
  */
 public function addKeyPress($code, $keyCodes = array(), $priority = 5, $inline = false)
 {
     $keyPress = new KeyPress();
     $keyPress->setCode($code)->setKeyCodes($keyCodes)->setPriority($priority)->setInline($inline);
     $this->builder->addEvent($keyPress);
     return $this;
 }