Module: KeyboardDirections

Included in:
FullKeyboard
Defined in:
tomes/conjurations/keyboard/keyboard_directions.rb

Overview

A module for dealing with directional Keyboard inputs. The arrow keys and WASD are supported.

Instance Method Summary collapse

Instance Method Details

#directionArray

Gives current direction-button presses as a list.

Returns:

  • (Array)


7
8
9
10
11
# File 'tomes/conjurations/keyboard/keyboard_directions.rb', line 7

def direction
  direction_inputs.map do |key, value|
    key unless (value.intersection down_inputs).empty?
  end.compact
end

#direction?Boolean

Checks if a direction-button is currently pressed or held (down).

Returns:

  • (Boolean)


32
33
34
# File 'tomes/conjurations/keyboard/keyboard_directions.rb', line 32

def direction?
  !direction_held.empty?
end

#direction_heldArray Also known as: direction_hold

Gives current direction-button holds as a list.

Returns:

  • (Array)


15
16
17
18
19
# File 'tomes/conjurations/keyboard/keyboard_directions.rb', line 15

def direction_held
  direction_inputs.map do |key, value|
    key unless (value.intersection held_inputs).empty?
  end.compact
end

#direction_upArray

Gives current direction-button releases as a list.

Returns:

  • (Array)


24
25
26
27
28
# File 'tomes/conjurations/keyboard/keyboard_directions.rb', line 24

def direction_up
  direction_inputs.map do |key, value|
    key unless (value.intersection up_inputs).empty?
  end.compact
end