Sha256: f3b1296a4592854cf5427d93947cec8808ceae1c3dfe89fcf325995127eb268c

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

# read
class ProconBypassMan::ReadonlyProcon
  def initialize(binary: )
    @binary = binary
    @user_operation = ProconBypassMan::Procon::UserOperation.new(binary.dup)
    @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
  end

  # @return [Array<Symbol>]
  def pressed
    pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
      acc[button] = @user_operation.pressed_button?(button)
      acc
    end
    pressed_table.select { |_key, value| value }.keys
  end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
procon_bypass_man-0.1.11 lib/procon_bypass_man/readonly_procon.rb