Class: ProconBypassMan::Procon::UserOperation

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

Overview

ボタンを押しているか判断するクラス。バイナリの書き換えはしない

Constant Summary collapse

ASCII_ENCODING =
"ASCII-8BIT"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary) ⇒ UserOperation

Returns a new instance of UserOperation.

Parameters:

  • binary (String)


10
11
12
13
14
15
16
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 10

def initialize(binary)
  unless binary.encoding.name == ASCII_ENCODING
    raise "おかしいです"
  end

  @binary = ProconBypassMan::Domains::ProcessingProconBinary.new(binary: binary)
end

Instance Attribute Details

#binaryObject (readonly)

Returns the value of attribute binary.



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

def binary
  @binary
end

Instance Method Details

#apply_left_analog_stick_cap(cap:) ⇒ Object



22
23
24
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 22

def apply_left_analog_stick_cap(cap: )
  binary.write_as_apply_left_analog_stick_cap(cap: cap)
end

#is_button?(button) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 78

def is_button?(button)
  button = [button] if not button.is_a?(Array)

  button.all? do |b|
    !!ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP[b.to_sym] || b.to_sym == ProconBypassMan::Procon::MacroBuilder::RESERVED_WORD_NONE
  end
end

#is_stick?(step) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 87

def is_stick?(step)
  !!(step =~ /\Atilt_/)
end

#merge(target_binary) ⇒ void

This method returns an undefined value.



58
59
60
61
62
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 58

def merge(target_binary)
  binary.write_as_merge!(
    ProconBypassMan::Domains::ProcessingProconBinary.new(binary: target_binary)
  )
end

#press_button(button) ⇒ Object

Parameters:

  • button (Symbol)


33
34
35
36
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 33

def press_button(button)
  return if pressing_button?(button)
  binary.write_as_press_button(button)
end

#press_button_only_or_tilt_sticks(macro_step) ⇒ Object

Parameters:

  • macro_step (Symbol, Array<Symbol>)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 39

def press_button_only_or_tilt_sticks(macro_step)
  macro_step = [macro_step] if not macro_step.is_a?(Array)
  # スティック操作を含む時はボタン入力を通す
  binary.set_no_action! if is_button?(macro_step)

  macro_step.uniq.each do |ms|
    next if ProconBypassMan::Procon::MacroBuilder::RESERVED_WORD_NONE == ms

    if is_button?(ms)
      binary.write_as_press_button(ms)
    elsif is_stick?(ms)
      binary.write_as_tilt_left_stick(ms)
    else
      warn "知らないmacro stepです"
    end
  end
end

#pressing_all_buttons?(buttons) ⇒ Boolean

Parameters:

  • buttons (Array<Symbol>)

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 72

def pressing_all_buttons?(buttons)
  aware = ProconBypassMan::PressButtonAware.new(@binary.raw)
  buttons.all? { |b| aware.pressing_button?(b) }
end

#pressing_button?(button) ⇒ Boolean

Parameters:

  • button (Symbol)

Returns:

  • (Boolean)


66
67
68
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 66

def pressing_button?(button)
  pressing_all_buttons?([button])
end

#set_no_action!Object



18
19
20
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 18

def set_no_action!
  binary.set_no_action!
end

#unpress_button(button) ⇒ Object

Parameters:

  • button (Symbol)


27
28
29
30
# File 'lib/procon_bypass_man/procon/user_operation.rb', line 27

def unpress_button(button)
  return if not pressing_button?(button)
  binary.write_as_unpress_button(button)
end