Sha256: 32590eed8f177667939c1807595c3ffc538da14565fa54be68f0281c94c9e540

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

class ProconBypassMan::Procon::LayerChanger
  # @param [ProconBypassMan::Domains::ProcessingProconBinary] binary
  def initialize(binary: )
    @procon_reader = binary.to_procon_reader
  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?
      ProconBypassMan.cache.fetch key: 'unknown prefix_keys', expires_in: 60 do
        warn "prefix_keysが未設定です"
      end
      return false
    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.pressing.include?(button)
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.11 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/procon/layer_changer.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/procon/layer_changer.rb