Class: ProconBypassMan::Procon::LayerChanger
- Inherits:
-
Object
- Object
- ProconBypassMan::Procon::LayerChanger
- Defined in:
- lib/procon_bypass_man/procon/layer_changer.rb
Instance Method Summary collapse
- #change_layer? ⇒ Boolean
-
#initialize(binary:) ⇒ LayerChanger
constructor
A new instance of LayerChanger.
- #next_layer_key ⇒ Symbol
- #pressed?(button:) ⇒ Boolean
- #pressed_next_layer? ⇒ Boolean
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
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..prefix_keys.empty? ProconBypassMan.cache.fetch key: 'unknown prefix_keys', expires_in: 60 do warn "prefix_keysが未設定です" end return false end ProconBypassMan..prefix_keys.map { |b| pressed?(button: b) }.all? end |
#next_layer_key ⇒ 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
43 44 45 |
# File 'lib/procon_bypass_man/procon/layer_changer.rb', line 43 def pressed?(button: ) @procon_reader.pressing.include?() end |
#pressed_next_layer? ⇒ 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 |