From 751952a1ab3c7bfbbbdbe6ad40680e1fed02b0d9 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 16:37:49 +0900 Subject: [PATCH 1/8] rename --- ...n.rb => buttons_setting_configuration2.rb} | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) rename lib/procon_bypass_man/{setting_configuration.rb => buttons_setting_configuration2.rb} (92%) diff --git a/lib/procon_bypass_man/setting_configuration.rb b/lib/procon_bypass_man/buttons_setting_configuration2.rb similarity index 92% rename from lib/procon_bypass_man/setting_configuration.rb rename to lib/procon_bypass_man/buttons_setting_configuration2.rb index 73199cbc..4eb85ebf 100644 --- a/lib/procon_bypass_man/setting_configuration.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration2.rb @@ -4,20 +4,21 @@ module ProconBypassMan - class Position < Struct.new(:x, :y); end + class ButtonSettingConfiguration2 + class Position < Struct.new(:x, :y); end + + module ManualMode; def self.name; :manual; end; end - class SettingConfiguration attr_accessor :layers, :setting_path, - :mode_plugins, - :macro_plugins, + :macro_registry, + :mode_registry, :neutral_position def initialize reset! end - module ManualMode; def self.name; :manual; end; end def layer(direction, mode: ManualMode, &block) if ProconBypassMan::ButtonsSettingConfiguration::ManualMode == mode mode_name = mode.name @@ -91,7 +92,6 @@ def enable(setting_name, *args) def reset! @prefix_keys_for_changing_layer = [] - self.mode_plugins = {} # プロセスを一度起動するとsetting_pathは変わらない、という想定なので適当に扱う. resetでは初期化しない # self.setting_path = nil # どこかで初期化している気がするのでコメントアウト @@ -101,15 +101,9 @@ def reset! left: Layer.new, right: Layer.new, } + @macro_registry = ProconBypassMan::Procon::MacroRegistry2.new + @mode_registry = ProconBypassMan::Procon::ModeRegistry2.new @neutral_position = Position.new(2124, 1808).freeze end - - def mode_registry - # TODO - end - - def macro_registry - # TODO - end end end From 7e3e9d1a183e01bc450d845d93e9639b6d142773 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 17:26:17 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=E3=83=9C=E3=82=BF=E3=83=B3=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E3=81=AE=E7=AE=A1=E7=90=86=E3=81=A7=E3=82=B7=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=83=AB=E3=83=88=E3=83=B3=E3=83=91=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=B3=E3=82=92=E3=82=84=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man.rb | 14 +- .../buttons_setting_configuration.rb | 42 +--- .../buttons_setting_configuration/loader.rb | 62 +++--- .../buttons_setting_configuration2.rb | 109 ---------- .../buttons_setting_configuration_spec.rb | 199 +++++++++--------- .../procon/analog_stick_cap_spec.rb | 2 +- .../procon/analog_stick_manipulator_spec.rb | 2 +- .../procon/analog_stick_spec.rb | 2 +- spec/support/ext/procon_bypass_man.rb | 2 +- 9 files changed, 144 insertions(+), 290 deletions(-) delete mode 100644 lib/procon_bypass_man/buttons_setting_configuration2.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 8b485a18..e102a025 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -165,20 +165,20 @@ def self.ephemeral_config end # NOTE: setting.ymlから読み込んだボタンに関する値を管理する - # @return [ProconBypassMan::SettingConfiguration] - def self.setting_config - @@setting_configuration ||= ProconBypassMan::SettingConfiguration.instance + def self.buttons_setting_configuration + @@buttons_setting_configuration ||= ProconBypassMan::ButtonsSettingConfiguration.new + # ProconBypassMan::ButtonsSettingConfiguration.instance end - # @deprecated - def self.buttons_setting_configuration - ProconBypassMan::ButtonsSettingConfiguration.instance + # テスト用? + def self.buttons_setting_configuration=(instance) + @@buttons_setting_configuration = instance end # @return [void] def self.reset! ProconBypassMan::Procon.reset! - buttons_setting_configuration.reset! + self.buttons_setting_configuration = nil ProconBypassMan.ephemeral_config.reset! end diff --git a/lib/procon_bypass_man/buttons_setting_configuration.rb b/lib/procon_bypass_man/buttons_setting_configuration.rb index e9cfa599..68ada554 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration.rb @@ -2,43 +2,19 @@ require "procon_bypass_man/buttons_setting_configuration/loader" require "procon_bypass_man/buttons_setting_configuration/layer" -module ProconBypassMan - class Position < Struct.new(:x, :y); end +module ProconBypassMan class ButtonsSettingConfiguration + class Position < Struct.new(:x, :y); end + module ManualMode; def self.name; :manual; end; end attr_accessor :layers, :setting_path, + :macro_registry, + :mode_registry, :neutral_position - def self.instance - @@context ||= {} - @@context[current_context_key] ||= new - end - - def self.current_context_key - @@current_context_key ||= :main - end - - def self.instance=(val) - @@context[current_context_key] = val - end - - def self.switch_new_context(new_context_key) - @@context[new_context_key] = new - previous_key = current_context_key - if block_given? - @@current_context_key = new_context_key - value = yield(@@context[new_context_key]) - return value - else - @@current_context_key = new_context_key - end - ensure - @@current_context_key = previous_key - end - def initialize reset! end @@ -84,14 +60,6 @@ def prefix_keys_for_changing_layer(buttons) self end - def macro_registry - @macro_registry - end - - def mode_registry - @mode_registry - end - def set_neutral_position(x, y) self.neutral_position = Position.new(x, y).freeze self diff --git a/lib/procon_bypass_man/buttons_setting_configuration/loader.rb b/lib/procon_bypass_man/buttons_setting_configuration/loader.rb index 48f1ca3e..3cb79a28 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/loader.rb @@ -8,51 +8,39 @@ module Loader # @return [ProconBypassMan::ButtonsSettingConfiguration] def self.load(setting_path: ) - ProconBypassMan.buttons_setting_configuration.setting_path = setting_path - metadata_loader = ProconBypassMan::ButtonsSettingConfiguration::MetadataLoader.load(setting_path: setting_path) if(Gem::Version.new(metadata_loader.required_pbm_version) >= Gem::Version.new(ProconBypassMan::VERSION)) ProconBypassMan::SendErrorCommand.execute(error: '起動中のPBMが設定ファイルのバージョンを満たしていません。設定ファイルが意図した通り動かない可能性があります。PBMのバージョンをあげてください。') end - ProconBypassMan::ButtonsSettingConfiguration.switch_new_context(:validation) do |new_instance| - yaml = ProconBypassMan::YamlLoader.load(path: setting_path) - new_instance.instance_eval(yaml["setting"]) - validator = Validator.new(new_instance) - if validator.valid? - next - else - raise ProconBypassMan::CouldNotLoadConfigError, validator.errors_to_s + new_instance, yaml = + begin + new_instance = ProconBypassMan::ButtonsSettingConfiguration.new + new_instance.setting_path = setting_path + yaml = ProconBypassMan::YamlLoader.load(path: setting_path) + new_instance.instance_eval(yaml["setting"]) + validator = Validator.new(new_instance) + if validator.valid? + [new_instance, yaml] + else + # TODO: fallbackが必要では? + raise ProconBypassMan::CouldNotLoadConfigError, validator.errors_to_s + end + rescue SyntaxError + fallback_setting_if_has_backup(current_setting_path: setting_path) + raise ProconBypassMan::CouldNotLoadConfigError, "Rubyスクリプトのシンタックスエラーです" + rescue NameError + fallback_setting_if_has_backup(current_setting_path: setting_path) + raise ProconBypassMan::CouldNotLoadConfigError, "Rubyスクリプトに未定義の定数・変数があります" + rescue Psych::SyntaxError + fallback_setting_if_has_backup(current_setting_path: setting_path) + raise ProconBypassMan::CouldNotLoadConfigError, "yamlのシンタックスエラーです" end - rescue SyntaxError - fallback_setting_if_has_backup(current_setting_path: setting_path) - raise ProconBypassMan::CouldNotLoadConfigError, "Rubyスクリプトのシンタックスエラーです" - rescue NameError - fallback_setting_if_has_backup(current_setting_path: setting_path) - raise ProconBypassMan::CouldNotLoadConfigError, "Rubyスクリプトに未定義の定数・変数があります" - rescue Psych::SyntaxError - fallback_setting_if_has_backup(current_setting_path: setting_path) - raise ProconBypassMan::CouldNotLoadConfigError, "yamlのシンタックスエラーです" - end - - ProconBypassMan.buttons_setting_configuration.reset! - ProconBypassMan.reset! - - yaml = ProconBypassMan::YamlLoader.load(path: setting_path) - ProconBypassMan.config.raw_setting = yaml.dup - case yaml["version"] - when 1.0, nil - ProconBypassMan.buttons_setting_configuration.instance_eval(yaml["setting"]) - else - ProconBypassMan.logger.warn "不明なバージョンです。failoverします" - ProconBypassMan.buttons_setting_configuration.instance_eval(yaml["setting"]) - end + ProconBypassMan.config.raw_setting = yaml + ProconBypassMan.buttons_setting_configuration = new_instance File.write(ProconBypassMan.digest_path, Digest::MD5.hexdigest(yaml["setting"])) - - if File.exist?(ProconBypassMan.fallback_setting_path) - FileUtils.rm_rf(ProconBypassMan.fallback_setting_path) - end + FileUtils.rm_rf(ProconBypassMan.fallback_setting_path) # NOTE: 設定ファイルの読み込みに成功したら、バックアップを削除する ProconBypassMan.buttons_setting_configuration end diff --git a/lib/procon_bypass_man/buttons_setting_configuration2.rb b/lib/procon_bypass_man/buttons_setting_configuration2.rb deleted file mode 100644 index 4eb85ebf..00000000 --- a/lib/procon_bypass_man/buttons_setting_configuration2.rb +++ /dev/null @@ -1,109 +0,0 @@ -require "procon_bypass_man/buttons_setting_configuration/validator" -require "procon_bypass_man/buttons_setting_configuration/loader" -require "procon_bypass_man/buttons_setting_configuration/layer" - - -module ProconBypassMan - class ButtonSettingConfiguration2 - class Position < Struct.new(:x, :y); end - - module ManualMode; def self.name; :manual; end; end - - attr_accessor :layers, - :setting_path, - :macro_registry, - :mode_registry, - :neutral_position - - def initialize - reset! - end - - 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] + ProconBypassMan.buttons_setting_configuration.mode_registry.plugins.keys).include?(mode_name) - warn "#{mode_name}モードがinstallされていません" - end - - layer = Layer.new(mode: mode_name) - layer.instance_eval(&block) if block_given? - self.layers[direction] = layer - self - end - - def install_mode_plugin(klass) - mode_registry.install_plugin(klass) - self - end - - def install_macro_plugin(klass) - macro_registry.install_plugin(klass) - self - end - - def prefix_keys_for_changing_layer(buttons) - @prefix_keys_for_changing_layer = buttons - self - end - - def set_neutral_position(x, y) - self.neutral_position = Position.new(x, y).freeze - self - end - - def prefix_keys - @prefix_keys_for_changing_layer - end - - # @param [Symbol, String] setting_name - # @param [Array] args - # @return [void] - 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 - - def reset! - @prefix_keys_for_changing_layer = [] - # プロセスを一度起動するとsetting_pathは変わらない、という想定なので適当に扱う. resetでは初期化しない - # self.setting_path = nil - # どこかで初期化している気がするのでコメントアウト - self.layers = { - up: Layer.new, - down: Layer.new, - left: Layer.new, - right: Layer.new, - } - @macro_registry = ProconBypassMan::Procon::MacroRegistry2.new - @mode_registry = ProconBypassMan::Procon::ModeRegistry2.new - @neutral_position = Position.new(2124, 1808).freeze - end - end -end diff --git a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb index b33c74e1..5019c2fc 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -111,8 +111,8 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position.x).to eq(1000) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position.y).to eq(1000) + expect(ProconBypassMan.buttons_setting_configuration.neutral_position.x).to eq(1000) + expect(ProconBypassMan.buttons_setting_configuration.neutral_position.y).to eq(1000) end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) @@ -133,7 +133,7 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].left_analog_stick_caps).to eq([ {:cap=>1000, :force_neutral=> [:a], if_pressed: [:a] } ]) end @@ -151,7 +151,7 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].left_analog_stick_caps).to eq([ {:cap=>1000, :force_neutral=> [:a], if_pressed: [:a], combined_press_is_pressed: [:b] } ]) end @@ -169,7 +169,7 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].left_analog_stick_caps).to eq([ {:cap=>1000, if_pressed: [:a], } ]) end @@ -187,7 +187,7 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([{:cap=>1000, :if_pressed=>[:a]}]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].left_analog_stick_caps).to eq([{:cap=>1000, :if_pressed=>[:a]}]) end end context 'provide a nil' do @@ -203,7 +203,7 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([{:cap=>1000}]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].left_analog_stick_caps).to eq([{:cap=>1000}]) end end context 'do not provide' do @@ -219,7 +219,7 @@ end it do ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].left_analog_stick_caps).to eq([ cap: 1000 ]) end @@ -451,11 +451,11 @@ EOH instance = ProconBypassMan::ButtonsSettingConfiguration.new - ProconBypassMan::ButtonsSettingConfiguration.instance = instance + ProconBypassMan.buttons_setting_configuration = instance instance.instance_eval(c) expect { instance = ProconBypassMan::ButtonsSettingConfiguration.new - ProconBypassMan::ButtonsSettingConfiguration.instance = instance + ProconBypassMan.buttons_setting_configuration = instance instance.instance_eval(c) }.not_to raise_error end @@ -515,11 +515,11 @@ def self.binaries; ['a']; end first_setting = Setting.new(first_setting_content).to_file second_setting = Setting.new(second_setting_content).to_file ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: first_setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:zr, :r, :zl, :l]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons).to eq(zr: { if_pressed: [:zr] }) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:zr, :r, :zl, :l]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons).to eq(zr: { if_pressed: [:zr] }) ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: second_setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:a]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons).to eq(b: { if_pressed: [:b] }) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:a]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons).to eq(b: { if_pressed: [:b] }) end end end @@ -539,10 +539,10 @@ def self.binaries; ['a']; end end it do ProconBypassMan.buttons_setting_configure(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:zr, :r, :zl, :l]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons).to eq(zr: { if_pressed: [:zr] }) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:down].flips).to eq({}) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path).to eq(setting.path) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:zr, :r, :zl, :l]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons).to eq(zr: { if_pressed: [:zr] }) + expect(ProconBypassMan.buttons_setting_configuration.layers[:down].flips).to eq({}) + expect(ProconBypassMan.buttons_setting_configuration.setting_path).to eq(setting.path) end end @@ -555,7 +555,7 @@ def self.binaries; ['a']; end disable [:b] end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].disables.sort).to eq([:a, :b, :l].sort) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].disables.sort).to eq([:a, :b, :l].sort) end end @@ -573,7 +573,7 @@ def self.steps; [:a, :b]; end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins.keys).to eq([:AMacroPlugin]) expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:AMacroPlugin].call).to eq([:a, :b]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( {:AMacroPlugin=>{:if_pressed=>[:a, :y]}} ) end @@ -590,7 +590,7 @@ def self.steps; [:a, :b]; end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins.keys).to eq([:AMacroPlugin]) expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:AMacroPlugin].call).to eq([:a, :b]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( {:AMacroPlugin=>{:if_pressed=>[:a, :y]}} ) end @@ -606,7 +606,7 @@ def self.steps; [:a, :b]; end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins.keys).to eq([:AMacroPlugin]) expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:AMacroPlugin].call).to eq([:a, :b]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( {:AMacroPlugin=>{:if_pressed=>[:a, :y], if_tilted_left_stick: true }} ) end @@ -622,7 +622,7 @@ def self.steps; [:a, :b]; end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:SaiHuu].call).to eq([:x, :y]) expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:SpecialCommand].call).to eq([:up, :down]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( {"SaiHuu"=>{:if_pressed=>[:x]}, "SpecialCommand"=>{:if_pressed=>[:y]}} ) end @@ -642,7 +642,7 @@ def self.steps; [:a, :b]; end :r, :none, ]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { :sokuwari => {:if_pressed=>[:zr, :down]} } ) end @@ -656,7 +656,7 @@ def self.steps; [:a, :b]; end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:dacan].call).to eq( [{:continue_for=>0.3, :steps=>[:r, :r]}, [:r, :zl], [:r, :none]] ) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) end @@ -667,7 +667,7 @@ def self.steps; [:a, :b]; end end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:dacan].call).to eq([[:r, :zr], [:r, :none]]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) end @@ -678,7 +678,7 @@ def self.steps; [:a, :b]; end end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:dacan].call).to eq([[:r, :zr], [:r, :none]]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: { threshold: 600 } } } ) end @@ -689,7 +689,7 @@ def self.steps; [:a, :b]; end end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:dacan].call).to eq([[:r, :zr], [:r, :none]]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) end @@ -700,7 +700,7 @@ def self.steps; [:a, :b]; end end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:shake_stick].call).to eq([{:continue_for=>0.65, :steps=>[:tilt_left_stick_completely_to_left, :tilt_left_stick_completely_to_right]}]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { shake_stick: { if_pressed: [:zr] } } ) end @@ -711,7 +711,7 @@ def self.steps; [:a, :b]; end end end expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:shake_stick].call).to eq([{:continue_for=>0.1, :steps=>[[:tilt_left_stick_completely_to_left, :b], [:tilt_left_stick_completely_to_right, :none]]}]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq( { shake_stick: { force_neutral: [:b], if_pressed: [:b, :r] } } ) end @@ -725,7 +725,7 @@ def self.steps; [:a, :b]; end expect( ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[ProconBypassMan::Plugin::Splatoon2::Macro::ChargeTansanBomb.to_s.to_sym].call ).to eq([{:continue_for=>0.1, :steps=>[[:tilt_left_stick_completely_to_left, :b], [:tilt_left_stick_completely_to_right, :none]]}]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq({ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq({ :"ProconBypassMan::Plugin::Splatoon2::Macro::ChargeTansanBomb" => {:force_neutral=>[:b], :if_pressed=>[:b, :r]}, }) end @@ -754,7 +754,7 @@ def self.binaries; ['a']; end disable_macro :all end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].disable_macros).to eq([ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].disable_macros).to eq([ {:name=>:all, :if_pressed=>[true]}, ]) end @@ -766,7 +766,7 @@ def self.binaries; ['a']; end disable_macro :sokuwari, if_pressed: :x end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].disable_macros).to eq([ + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].disable_macros).to eq([ {:name=>:all, :if_pressed=>[:b, :y]}, {:name=>:all, :if_pressed=>[:zr]}, {:if_pressed=>[:x], :name=>:sokuwari}, @@ -781,8 +781,8 @@ def self.binaries; ['a']; end flip :l, if_pressed: [:y, :b], force_neutral: :y end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons[:l]).to eq(if_pressed: [:y, :b], force_neutral: [:y]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons.keys).to eq([:l]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons[:l]).to eq(if_pressed: [:y, :b], force_neutral: [:y]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons.keys).to eq([:l]) end end @@ -793,7 +793,7 @@ def self.binaries; ['a']; end remap :l, to: :zr end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].remaps).to eq(:l=>{ to: [:zr] }) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].remaps).to eq(:l=>{ to: [:zr] }) end it 'with remap' do ProconBypassMan.buttons_setting_configure do @@ -801,7 +801,7 @@ def self.binaries; ['a']; end remap :l, to: [:zr] end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].remaps).to eq(:l=>{ to: [:zr] }) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].remaps).to eq(:l=>{ to: [:zr] }) end end @@ -823,17 +823,17 @@ def self.binaries; ['a']; end layer :right, mode: AModePlugin layer :left end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons[:l]).to eq(if_pressed: [:l]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons[:r]).to eq(if_pressed: false) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons.keys).to eq([:l, :r]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].mode).to eq(:manual) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:down].flip_buttons.keys).to eq([:r]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:down].flip_buttons[:r]).to eq(if_pressed: [:zr, :zl]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:down].mode).to eq(:AModePlugin) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:right].flip_buttons.keys).to eq([]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:right].mode).to eq(:AModePlugin) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:left].flip_buttons.keys).to eq([]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:left].mode).to eq(:manual) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons[:l]).to eq(if_pressed: [:l]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons[:r]).to eq(if_pressed: false) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons.keys).to eq([:l, :r]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].mode).to eq(:manual) + expect(ProconBypassMan.buttons_setting_configuration.layers[:down].flip_buttons.keys).to eq([:r]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:down].flip_buttons[:r]).to eq(if_pressed: [:zr, :zl]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:down].mode).to eq(:AModePlugin) + expect(ProconBypassMan.buttons_setting_configuration.layers[:right].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:right].mode).to eq(:AModePlugin) + expect(ProconBypassMan.buttons_setting_configuration.layers[:left].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:left].mode).to eq(:manual) end end @@ -850,10 +850,10 @@ def self.binaries; ['a']; end layer :right layer :left end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons.keys).to eq([:l, :r]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:down].flip_buttons.keys).to eq([:r]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:right].flip_buttons.keys).to eq([]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:left].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons.keys).to eq([:l, :r]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:down].flip_buttons.keys).to eq([:r]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:right].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:left].flip_buttons.keys).to eq([]) end end @@ -869,10 +869,10 @@ def self.binaries; ['a']; end layer :left do end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons.keys).to eq([]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:down].flip_buttons.keys).to eq([]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:right].flip_buttons.keys).to eq([]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:left].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:down].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:right].flip_buttons.keys).to eq([]) + expect(ProconBypassMan.buttons_setting_configuration.layers[:left].flip_buttons.keys).to eq([]) end end @@ -881,7 +881,7 @@ def self.binaries; ['a']; end ProconBypassMan.buttons_setting_configure do prefix_keys_for_changing_layer [:zr] end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:zr]) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:zr]) end end @@ -892,7 +892,7 @@ def self.binaries; ['a']; end flip :zr, flip_interval: "8F" end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons[:zr][:flip_interval]).to eq(0.13) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flip_buttons[:zr][:flip_interval]).to eq(0.13) end end end @@ -907,7 +907,7 @@ def self.binaries; ['a']; end macro ProconBypassMan::Plugin::Splatoon2::Macro::FastReturn, if_pressed: :a end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq({}) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq({}) end end context 'mode' do @@ -934,7 +934,7 @@ def self.binaries; ['a']; end prefix_keys_for_changing_layer [:zr, :r, :zl, :l] set_neutral_position 1000, 1000 EOH - ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path = nil + ProconBypassMan.buttons_setting_configuration.setting_path = nil setting = Setting.new(setting_content).to_file expect { @@ -945,24 +945,24 @@ def self.binaries; ['a']; end context 'シンタックスエラーが起きるとき' do context '初回で失敗する' do - it 'setting.pathは保存すること' do - setting_content = <<~EOH + it 'setting_pathはnilのままであること' do + invalid_setting_content = <<~EOH version: 1.0 setting: |- prefix_keys_for_changing_layer [:zr, :r, :zl, :l] set_neutral_position 1000,, 1000 EOH - ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path = nil - setting = Setting.new(setting_content).to_file + ProconBypassMan.buttons_setting_configuration.setting_path = nil + invalid_setting = Setting.new(invalid_setting_content).to_file begin - ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) + ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: invalid_setting.path) rescue ProconBypassMan::CouldNotLoadConfigError - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path).to eq(setting.path) + expect(ProconBypassMan.buttons_setting_configuration.setting_path).to be_nil end end end - context '初回は成功する' do + context '初回は成功して、次に設定ファイルをロードするとき' do let(:setting_content) { <<~EOH version: 1.0 @@ -979,43 +979,50 @@ def self.binaries; ['a']; end set_neutral_position 1000,, 1000 EOH } + before do - setting = Setting.new(setting_content).to_file - ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:zr, :r, :zl, :l]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path).to eq(setting.path) + valid_setting = Setting.new(setting_content).to_file + ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: valid_setting.path) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:zr, :r, :zl, :l]) + expect(ProconBypassMan.buttons_setting_configuration.setting_path).to eq(valid_setting.path) end + context 'fallback_pathがある' do before { File.write(ProconBypassMan.fallback_setting_path, setting_content) } - it 'next_setting_contentの内容はファイルに保存されないこと' do - setting = Setting.new(error_setting_content).to_file - expect { ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) }.to raise_error ProconBypassMan::CouldNotLoadConfigError - expect(File.read(setting.path)).to eq(setting_content) + it 'invalid_setting_contentの内容はファイルに保存されないこと' do + invalid_setting = Setting.new(error_setting_content).to_file + expect { ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: invalid_setting.path) }.to raise_error ProconBypassMan::CouldNotLoadConfigError + expect(File.read(invalid_setting.path)).to eq(setting_content) expect(File.exist?(ProconBypassMan.fallback_setting_path)).to eq(false) end + it '変更はオブジェクトには反映されないこと' do - setting = Setting.new(error_setting_content).to_file + previous_configuration = ProconBypassMan.buttons_setting_configuration.dup + invalid_setting = Setting.new(error_setting_content).to_file begin - ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) + ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: invalid_setting.path) rescue ProconBypassMan::CouldNotLoadConfigError - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:zr, :r, :zl, :l]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path).to eq(setting.path) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:zr, :r, :zl, :l]) + expect(ProconBypassMan.buttons_setting_configuration.setting_path).to eq(previous_configuration.setting_path) end end end + context 'fallback_pathがない' do - it 'next_setting_contentの内容はファイルに保存されること' do - setting = Setting.new(error_setting_content).to_file - expect { ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) }.to raise_error ProconBypassMan::CouldNotLoadConfigError - expect(File.read(setting.path)).to eq(error_setting_content) + it 'invalid_setting_contentの内容はファイルに保存されること' do + invalid_setting = Setting.new(error_setting_content).to_file + expect { ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: invalid_setting.path) }.to raise_error ProconBypassMan::CouldNotLoadConfigError + expect(File.read(invalid_setting.path)).to eq(error_setting_content) end + it '変更はオブジェクトには反映されないこと' do - setting = Setting.new(error_setting_content).to_file + previous_configuration = ProconBypassMan.buttons_setting_configuration.dup + invalid_setting = Setting.new(error_setting_content).to_file begin - ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) + ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: invalid_setting.path) rescue ProconBypassMan::CouldNotLoadConfigError - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys).to eq([:zr, :r, :zl, :l]) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path).to eq(setting.path) + expect(ProconBypassMan.buttons_setting_configuration.prefix_keys).to eq([:zr, :r, :zl, :l]) + expect(ProconBypassMan.buttons_setting_configuration.setting_path).to eq(previous_configuration.setting_path) end end end @@ -1039,10 +1046,10 @@ def self.binaries; ['a']; end EOH instance = ProconBypassMan::ButtonsSettingConfiguration.new - ProconBypassMan::ButtonsSettingConfiguration.instance = instance + ProconBypassMan.buttons_setting_configuration = instance instance.instance_eval(c) validator = ProconBypassMan::ButtonsSettingConfiguration::Validator.new( - ProconBypassMan::ButtonsSettingConfiguration.instance + ProconBypassMan.buttons_setting_configuration ) expect(validator.valid?).to eq(false) expect(validator.errors).to eq(:macro=>["マクロ ProconBypassMan::Plugin::SmashBrothers::Macro::FastFujinkenを読み込めませんでした。"]) @@ -1064,10 +1071,10 @@ def self.binaries; ['a']; end EOH instance = ProconBypassMan::ButtonsSettingConfiguration.new - ProconBypassMan::ButtonsSettingConfiguration.instance = instance - ProconBypassMan::ButtonsSettingConfiguration.instance.instance_eval(c) + ProconBypassMan.buttons_setting_configuration = instance + ProconBypassMan.buttons_setting_configuration.instance_eval(c) validator = ProconBypassMan::ButtonsSettingConfiguration::Validator.new( - ProconBypassMan::ButtonsSettingConfiguration.instance + ProconBypassMan.buttons_setting_configuration ) expect(validator.valid?).to eq(false) expect(validator.errors).to eq(:mode=>["モード ProconBypassMan::Plugin::SmashBrothers::Mode::EternalJumpを読み込めませんでした。"]) @@ -1086,9 +1093,9 @@ def self.binaries; ['a']; end end }.not_to raise_error expect(ProconBypassMan::ButtonsSettingConfiguration::Validator.new( - ProconBypassMan::ButtonsSettingConfiguration.instance + ProconBypassMan.buttons_setting_configuration ).valid?).to eq(true) - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flips).to eq(:zr=>{:if_pressed=>[:x]}) + expect(ProconBypassMan.buttons_setting_configuration.layers[:up].flips).to eq(:zr=>{:if_pressed=>[:x]}) end end @@ -1105,7 +1112,7 @@ def self.binaries; ['a']; end end end validator = ProconBypassMan::ButtonsSettingConfiguration::Validator.new( - ProconBypassMan::ButtonsSettingConfiguration.instance + ProconBypassMan.buttons_setting_configuration ) expect(validator.valid?).to eq(false) expect(validator.errors).to eq({:layers=>["レイヤーupで、連打とリマップの定義が重複しているボタンzrがあります"]}) @@ -1126,7 +1133,7 @@ def self.binaries; ['a']; end end end validator = ProconBypassMan::ButtonsSettingConfiguration::Validator.new( - ProconBypassMan::ButtonsSettingConfiguration.instance + ProconBypassMan.buttons_setting_configuration ) expect(validator.valid?).to eq(false) expect(validator.errors).to eq(:layers=>["upでmodeを設定しているのでボタンの設定はできません。"]) diff --git a/spec/lib/procon_bypass_man/procon/analog_stick_cap_spec.rb b/spec/lib/procon_bypass_man/procon/analog_stick_cap_spec.rb index b7b3b36f..0a11b69e 100644 --- a/spec/lib/procon_bypass_man/procon/analog_stick_cap_spec.rb +++ b/spec/lib/procon_bypass_man/procon/analog_stick_cap_spec.rb @@ -11,7 +11,7 @@ def with_default_y(n) end before do - ProconBypassMan::ButtonsSettingConfiguration.instance.set_neutral_position(2124, 1807) + ProconBypassMan.buttons_setting_configuration.set_neutral_position(2124, 1807) end context 'detail' do diff --git a/spec/lib/procon_bypass_man/procon/analog_stick_manipulator_spec.rb b/spec/lib/procon_bypass_man/procon/analog_stick_manipulator_spec.rb index f22f7efd..e388b3c8 100644 --- a/spec/lib/procon_bypass_man/procon/analog_stick_manipulator_spec.rb +++ b/spec/lib/procon_bypass_man/procon/analog_stick_manipulator_spec.rb @@ -25,7 +25,7 @@ describe 'method: tilt_left_stick_completely_to_(\d+)deg' do before do - allow(ProconBypassMan::ButtonsSettingConfiguration.instance).to receive(:neutral_position) { OpenStruct.new(x: 2124, y: 1808) } + allow(ProconBypassMan.buttons_setting_configuration).to receive(:neutral_position) { OpenStruct.new(x: 2124, y: 1808) } end it do diff --git a/spec/lib/procon_bypass_man/procon/analog_stick_spec.rb b/spec/lib/procon_bypass_man/procon/analog_stick_spec.rb index 5519fe3c..70fe149b 100644 --- a/spec/lib/procon_bypass_man/procon/analog_stick_spec.rb +++ b/spec/lib/procon_bypass_man/procon/analog_stick_spec.rb @@ -4,7 +4,7 @@ let(:binary) { [data].pack("H*") } before do - ProconBypassMan::ButtonsSettingConfiguration.instance.reset! + ProconBypassMan.buttons_setting_configuration = ProconBypassMan::ButtonsSettingConfiguration.new end describe '#relative_hypotenuse' do diff --git a/spec/support/ext/procon_bypass_man.rb b/spec/support/ext/procon_bypass_man.rb index 1be6e1ce..e0a10f14 100644 --- a/spec/support/ext/procon_bypass_man.rb +++ b/spec/support/ext/procon_bypass_man.rb @@ -1,7 +1,7 @@ module ProconBypassMan def self.buttons_setting_configure(setting_path: nil, &block) if block_given? - ProconBypassMan::ButtonsSettingConfiguration.instance.instance_eval(&block) + ProconBypassMan.buttons_setting_configuration.instance_eval(&block) else ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path) end From bc08f0069aca43316ac584816bca07c6b5d16248 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 18:00:31 +0900 Subject: [PATCH 3/8] =?UTF-8?q?layer=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=81=AB=E8=A6=AA=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=B9=E3=81=AE=E5=8F=82=E7=85=A7=E3=82=92?= =?UTF-8?q?=E5=85=A5=E5=8A=9B=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buttons_setting_configuration.rb | 10 +++++----- .../buttons_setting_configuration/layer.rb | 7 ++++--- .../buttons_setting_configuration/layer_spec.rb | 15 ++++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/procon_bypass_man/buttons_setting_configuration.rb b/lib/procon_bypass_man/buttons_setting_configuration.rb index 68ada554..d7ec1921 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration.rb @@ -39,7 +39,7 @@ def layer(direction, mode: ManualMode, &block) warn "#{mode_name}モードがinstallされていません" end - layer = Layer.new(mode: mode_name) + layer = Layer.new(self, mode: mode_name) layer.instance_eval(&block) if block_given? self.layers[direction] = layer self @@ -96,10 +96,10 @@ def reset! # self.setting_path = nil # どこかで初期化している気がするのでコメントアウト self.layers = { - up: Layer.new, - down: Layer.new, - left: Layer.new, - right: Layer.new, + 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 diff --git a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb index 233a1be6..82460ed9 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb @@ -3,7 +3,8 @@ class ButtonsSettingConfiguration class Layer attr_accessor :mode, :flips, :macros, :disable_macros, :remaps, :left_analog_stick_caps, :disables - def initialize(mode: :manual) + def initialize(context, mode: :manual) + @context = context self.mode = mode self.flips = {} self.macros = {} @@ -83,7 +84,7 @@ def macro(name, if_pressed: nil, if_tilted_left_stick: nil, force_neutral: nil) end macro_name = name.to_s.to_sym - if ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[macro_name] + if @context.macro_registry.plugins[macro_name] self.macros[macro_name] = { if_pressed: if_pressed, if_tilted_left_stick: if_tilted_left_stick, force_neutral: force_neutral }.compact else warn "#{macro_name}マクロがinstallされていません" @@ -133,7 +134,7 @@ def open_macro(name, steps: [], if_pressed: nil, if_tilted_left_stick: nil, forc end macro_name = name || "OpenMacro-#{steps.join}".to_sym - ProconBypassMan.buttons_setting_configuration.macro_registry.install_plugin(macro_name, steps: steps) + @context.macro_registry.install_plugin(macro_name, steps: steps) self.macros[macro_name] = { if_pressed: if_pressed, if_tilted_left_stick: if_tilted_left_stick, force_neutral: force_neutral }.compact end diff --git a/spec/lib/procon_bypass_man/buttons_setting_configuration/layer_spec.rb b/spec/lib/procon_bypass_man/buttons_setting_configuration/layer_spec.rb index 8db322aa..9d752781 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration/layer_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration/layer_spec.rb @@ -1,7 +1,8 @@ require "spec_helper" describe ProconBypassMan::ButtonsSettingConfiguration::Layer do - let(:layer) { ProconBypassMan::ButtonsSettingConfiguration::Layer.new } + let(:buttons_setting_configuration) { ProconBypassMan::ButtonsSettingConfiguration.new } + let(:layer) { ProconBypassMan::ButtonsSettingConfiguration::Layer.new(buttons_setting_configuration) } before do ProconBypassMan.reset! @@ -106,7 +107,7 @@ def self.steps context 'macroをインストール済み' do before do klass = macro_class - ProconBypassMan.buttons_setting_configure do + buttons_setting_configuration.instance_eval do install_macro_plugin klass end end @@ -153,7 +154,7 @@ def self.steps it { expect(subject).to eq({:TheMacro => {:if_pressed=>[:x] }}) } it do subject - expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:TheMacro].call).not_to be_nil + expect(buttons_setting_configuration.macro_registry.plugins[:TheMacro].call).not_to be_nil end end context 'is array' do @@ -161,7 +162,7 @@ def self.steps it { expect(subject).to eq({:TheMacro => {:if_pressed=>[:x] } }) } it do subject - expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:TheMacro].call).not_to be_nil + expect(buttons_setting_configuration.macro_registry.plugins[:TheMacro].call).not_to be_nil end end context 'is hash' do @@ -256,7 +257,7 @@ def self.steps it { expect(subject).to eq({"name" => {:if_pressed=>[:x]}}) } it do subject - expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:name].call).to eq([:x]) + expect(buttons_setting_configuration.macro_registry.plugins[:name].call).to eq([:x]) end end context 'is string' do @@ -264,7 +265,7 @@ def self.steps it { expect(subject).to eq({"name" => {:if_pressed=>[:x]}}) } it do subject - expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:name].call).to eq([:x]) + expect(buttons_setting_configuration.macro_registry.plugins[:name].call).to eq([:x]) end end context 'is array' do @@ -272,7 +273,7 @@ def self.steps it { expect(subject).to eq({"name" => {:if_pressed=>[:x]}}) } it do subject - expect(ProconBypassMan.buttons_setting_configuration.macro_registry.plugins[:name].call).to eq([:x, :x]) + expect(buttons_setting_configuration.macro_registry.plugins[:name].call).to eq([:x, :x]) end end end From 41364997ba3db4f59ae26703bb79159ee1f0fbd4 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 18:15:55 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=E9=96=93=E9=81=95=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index e102a025..280e6ee1 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -170,7 +170,6 @@ def self.buttons_setting_configuration # ProconBypassMan::ButtonsSettingConfiguration.instance end - # テスト用? def self.buttons_setting_configuration=(instance) @@buttons_setting_configuration = instance end From 1caac9c8319faffd0b558c0eacff10b965526a10 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 18:32:21 +0900 Subject: [PATCH 5/8] format --- lib/procon_bypass_man.rb | 1 - lib/procon_bypass_man/buttons_setting_configuration.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 280e6ee1..f3eb2754 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -167,7 +167,6 @@ def self.ephemeral_config # NOTE: setting.ymlから読み込んだボタンに関する値を管理する def self.buttons_setting_configuration @@buttons_setting_configuration ||= ProconBypassMan::ButtonsSettingConfiguration.new - # ProconBypassMan::ButtonsSettingConfiguration.instance end def self.buttons_setting_configuration=(instance) diff --git a/lib/procon_bypass_man/buttons_setting_configuration.rb b/lib/procon_bypass_man/buttons_setting_configuration.rb index d7ec1921..7ae7eee5 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration.rb @@ -2,7 +2,6 @@ require "procon_bypass_man/buttons_setting_configuration/loader" require "procon_bypass_man/buttons_setting_configuration/layer" - module ProconBypassMan class ButtonsSettingConfiguration class Position < Struct.new(:x, :y); end From 2e69773308dea4936c7b91d6cdb4f68662e7f9b5 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 18:39:22 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=81=97=E3=81=9Fmode=E3=82=92=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=82=81=E3=81=AA=E3=81=84=E4=B8=8D=E5=85=B7?= =?UTF-8?q?=E5=90=88=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/buttons_setting_configuration.rb | 3 ++- .../procon_bypass_man/buttons_setting_configuration_spec.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/buttons_setting_configuration.rb b/lib/procon_bypass_man/buttons_setting_configuration.rb index 7ae7eee5..99c21b07 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration.rb @@ -34,7 +34,8 @@ def layer(direction, mode: ManualMode, &block) end end - unless ([ManualMode.name] + ProconBypassMan.buttons_setting_configuration.mode_registry.plugins.keys).include?(mode_name) + unless ([ManualMode.name] + mode_registry.plugins.keys).include?(mode_name) + # TODO: strict modeが有効なときはエラーにする warn "#{mode_name}モードがinstallされていません" end diff --git a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb index 5019c2fc..9d6264da 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -910,6 +910,7 @@ def self.binaries; ['a']; end expect(ProconBypassMan.buttons_setting_configuration.layers[:up].macros).to eq({}) end end + context 'mode' do it 'ロードしない' do class AModePlugin From 5629c983e2ac2258d7e0becce0b8a2cf4f31bf64 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 18:49:42 +0900 Subject: [PATCH 7/8] =?UTF-8?q?=E9=81=A9=E5=BD=93=E3=81=ABProconBypassMan:?= =?UTF-8?q?:Procon.reset!=E3=82=92=E5=85=A5=E3=82=8C=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/buttons_setting_configuration/loader.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/procon_bypass_man/buttons_setting_configuration/loader.rb b/lib/procon_bypass_man/buttons_setting_configuration/loader.rb index 3cb79a28..0d098134 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/loader.rb @@ -13,6 +13,8 @@ def self.load(setting_path: ) ProconBypassMan::SendErrorCommand.execute(error: '起動中のPBMが設定ファイルのバージョンを満たしていません。設定ファイルが意図した通り動かない可能性があります。PBMのバージョンをあげてください。') end + ProconBypassMan::Procon.reset! # TODO: ここでresetするのは微妙な気がする + new_instance, yaml = begin new_instance = ProconBypassMan::ButtonsSettingConfiguration.new From 1b59f773a65e62bbddfbc60b1c752278f63b3a6b Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 7 Jan 2024 18:51:24 +0900 Subject: [PATCH 8/8] =?UTF-8?q?test=E7=94=A8=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E5=8B=95=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man.rb | 7 ------- spec/support/ext/procon_bypass_man.rb | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index f3eb2754..f20f7b0f 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -173,13 +173,6 @@ def self.buttons_setting_configuration=(instance) @@buttons_setting_configuration = instance end - # @return [void] - def self.reset! - ProconBypassMan::Procon.reset! - self.buttons_setting_configuration = nil - ProconBypassMan.ephemeral_config.reset! - end - # @return [void] def self.initialize_pbm if ProconBypassMan.pid && ProconBypassMan::ProcessChecker.running?(ProconBypassMan.pid) diff --git a/spec/support/ext/procon_bypass_man.rb b/spec/support/ext/procon_bypass_man.rb index e0a10f14..a8d51a26 100644 --- a/spec/support/ext/procon_bypass_man.rb +++ b/spec/support/ext/procon_bypass_man.rb @@ -6,4 +6,10 @@ def self.buttons_setting_configure(setting_path: nil, &block) ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path) end end + + def self.reset! + ProconBypassMan::Procon.reset! + self.buttons_setting_configuration = nil + ProconBypassMan.ephemeral_config.reset! + end end