Sha256: b77d528104a798f6f0533374997ac6174c296e840d5dedd267f8edca05eb09b3

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

class ProconBypassMan::Procon::LayerChanger
  def initialize(binary: )
    @procon_reader = ProconBypassMan::ProconReader.new(binary: binary).freeze
  end

  # @return [Symbol]
  def next_layer_key
    case
    when pressed?(button: :up)
      :up
    when pressed?(button: :right)
      :right
    when pressed?(button: :left)
      :left
    when pressed?(button: :down)
      :down
    else
      ProconBypassMan.logger.warn("next_layer_key is unknown")
      :up
    end
  end

  # @return [Boolean]
  def change_layer?
    if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
      raise "prefix_keysが未設定です"
    end
    ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed?(button: b) }.all?
  end

  # @return [Boolean]
  def pressed_next_layer?
    change_layer? && (pressed?(button: :up) || pressed?(button: :right) || pressed?(button: :left) || pressed?(button: :down))
  end

  # @return [Boolean]
  def pressed?(button: )
    @procon_reader.pressed.include?(button)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
procon_bypass_man-0.1.15 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.1.14 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.1.13 lib/procon_bypass_man/procon/layer_changer.rb