Class: ProconBypassMan::ProconReader

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/value_objects/procon_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(binary:) ⇒ ProconReader

Returns a new instance of ProconReader.



3
4
5
6
7
# File 'lib/procon_bypass_man/procon/value_objects/procon_reader.rb', line 3

def initialize(binary: )
  @binary = binary
  @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
  freeze
end

Instance Method Details

#left_analog_stickObject



19
20
21
# File 'lib/procon_bypass_man/procon/value_objects/procon_reader.rb', line 19

def left_analog_stick
  { x: @analog_stick.relative_x, y: @analog_stick.relative_y }
end

#left_analog_stick_by_absObject



23
24
25
# File 'lib/procon_bypass_man/procon/value_objects/procon_reader.rb', line 23

def left_analog_stick_by_abs
  { x: @analog_stick.abs_x, y: @analog_stick.abs_y }
end

#pressingArray<Symbol>

Returns:

  • (Array<Symbol>)


10
11
12
13
14
15
16
17
# File 'lib/procon_bypass_man/procon/value_objects/procon_reader.rb', line 10

def pressing
  aware = ProconBypassMan::PressButtonAware.new(@binary)
  pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
    acc[button] = aware.pressing_button?(button)
    acc
  end
  pressed_table.select { |_key, value| value }.keys
end

#to_hashObject



27
28
29
30
31
32
# File 'lib/procon_bypass_man/procon/value_objects/procon_reader.rb', line 27

def to_hash
  { left_analog_stick: left_analog_stick,
    left_analog_stick_by_abs: left_analog_stick_by_abs,
    buttons: pressing,
  }
end