Class: ProconBypassMan::ButtonsSettingConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/buttons_setting_configuration.rb,
lib/procon_bypass_man/buttons_setting_configuration/layer.rb,
lib/procon_bypass_man/buttons_setting_configuration/loader.rb,
lib/procon_bypass_man/buttons_setting_configuration/validator.rb,
lib/procon_bypass_man/buttons_setting_configuration/metadata_loader.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/button.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/button_list.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/force_neutral.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/flip_if_pressed.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/open_macro_steps.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed_allows_nil.rb,
lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/disable_macro_if_pressed.rb

Defined Under Namespace

Modules: Loader, ManualMode, ParamNormalizer Classes: Layer, MetadataLoader, Position, Validator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeButtonsSettingConfiguration

Returns a new instance of ButtonsSettingConfiguration.



17
18
19
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 17

def initialize
  reset!
end

Instance Attribute Details

#layersObject

Returns the value of attribute layers.



11
12
13
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 11

def layers
  @layers
end

#macro_registryObject

Returns the value of attribute macro_registry.



11
12
13
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 11

def macro_registry
  @macro_registry
end

#mode_registryObject

Returns the value of attribute mode_registry.



11
12
13
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 11

def mode_registry
  @mode_registry
end

#neutral_positionObject

Returns the value of attribute neutral_position.



11
12
13
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 11

def neutral_position
  @neutral_position
end

#setting_pathObject

Returns the value of attribute setting_path.



11
12
13
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 11

def setting_path
  @setting_path
end

Instance Method Details

#enable(setting_name, *args) ⇒ void

This method returns an undefined value.

Parameters:

  • setting_name (Symbol, String)
  • args (Array<any>)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 75

def enable(setting_name, *args)
  case setting_name.to_sym
  when :rumble_on_layer_change
    ProconBypassMan.ephemeral_config.enable_rumble_on_layer_change = true
  when :procon_color
    color_name = args.first
    return if color_name.nil? || color_name == :default || color_name == 'default'
    color = ProconBypassMan::DeviceConnection::ProconColor.new(color_name)
    if color.valid?
      ProconBypassMan.ephemeral_config.recognized_procon_color = ProconBypassMan::DeviceConnection::ProconColor.new(color_name)
    else
      warn "recognized_procon_colorに存在しないcolor(#{color_name})が呼び出されました。"
    end
  else
    warn "存在しないenable(#{setting_name.to_sym})が呼び出されました。"
  end
end

#install_macro_plugin(klass) ⇒ Object



53
54
55
56
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 53

def install_macro_plugin(klass)
  macro_registry.install_plugin(klass)
  self
end

#install_mode_plugin(klass) ⇒ Object



48
49
50
51
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 48

def install_mode_plugin(klass)
  mode_registry.install_plugin(klass)
  self
end

#layer(direction, mode: ManualMode, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 21

def layer(direction, mode: ManualMode, &block)
  if ProconBypassMan::ButtonsSettingConfiguration::ManualMode == mode
    mode_name = mode.name
  else
    mode_name = case mode
                when ProconBypassMan::ButtonsSettingConfiguration::ManualMode
                  mode.name
                when String
                  mode.to_sym
                when Symbol
                  mode
                else
                  mode.to_s.to_sym
                end
  end

  unless ([ManualMode.name] + mode_registry.plugins.keys).include?(mode_name)
    # TODO: strict modeが有効なときはエラーにする
    warn "#{mode_name}モードがinstallされていません"
  end

  layer = Layer.new(self, mode: mode_name)
  layer.instance_eval(&block) if block_given?
  self.layers[direction] = layer
  self
end

#prefix_keysObject



68
69
70
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 68

def prefix_keys
  @prefix_keys_for_changing_layer
end

#prefix_keys_for_changing_layer(buttons) ⇒ Object



58
59
60
61
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 58

def prefix_keys_for_changing_layer(buttons)
  @prefix_keys_for_changing_layer = buttons
  self
end

#reset!Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 93

def reset!
  @prefix_keys_for_changing_layer = []
  # プロセスを一度起動するとsetting_pathは変わらない、という想定なので適当に扱う. resetでは初期化しない
  # self.setting_path = nil
  # どこかで初期化している気がするのでコメントアウト
  self.layers = {
    up: Layer.new(self),
    down: Layer.new(self),
    left: Layer.new(self),
    right: Layer.new(self),
  }
  @macro_registry = ProconBypassMan::Procon::MacroRegistry2.new
  @mode_registry = ProconBypassMan::Procon::ModeRegistry2.new
  @neutral_position = Position.new(2124, 1808).freeze
end

#set_neutral_position(x, y) ⇒ Object



63
64
65
66
# File 'lib/procon_bypass_man/buttons_setting_configuration.rb', line 63

def set_neutral_position(x, y)
  self.neutral_position = Position.new(x, y).freeze
  self
end