Class: ProconBypassMan::Procon::LayerChanger

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

Instance Method Summary collapse

Constructor Details

#initialize(binary:) ⇒ LayerChanger

Returns a new instance of LayerChanger.



5
6
7
# File 'lib/procon_bypass_man/procon/layer_changer.rb', line 5

def initialize(binary: )
  @procon_reader = binary.to_procon_reader
end

Instance Method Details

#change_layer?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/procon_bypass_man/procon/layer_changer.rb', line 27

def change_layer?
  if ProconBypassMan.buttons_setting_configuration.prefix_keys.empty?
    ProconBypassMan.cache.fetch key: 'unknown prefix_keys', expires_in: 60 do
      warn "prefix_keysが未設定です"
    end
    return false
  end
  ProconBypassMan.buttons_setting_configuration.prefix_keys.map { |b| pressed?(button: b) }.all?
end

#next_layer_keySymbol

Returns:

  • (Symbol)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/procon_bypass_man/procon/layer_changer.rb', line 10

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

#pressed?(button:) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/procon_bypass_man/procon/layer_changer.rb', line 43

def pressed?(button: )
  @procon_reader.pressing.include?(button)
end

#pressed_next_layer?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/procon_bypass_man/procon/layer_changer.rb', line 38

def pressed_next_layer?
  change_layer? && (pressed?(button: :up) || pressed?(button: :right) || pressed?(button: :left) || pressed?(button: :down))
end