From 556119b0453098dfe007d931f873d3cb22de67fa Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 13:07:31 +0900 Subject: [PATCH 01/44] add map --- lib/procon_bypass_man.rb | 1 + .../support/time_scoped_map.rb | 32 +++++++++++++++++++ .../support/time_scoped_map_spec.rb | 25 +++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/procon_bypass_man/support/time_scoped_map.rb create mode 100644 spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index e649a313..20c9a88e 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -25,6 +25,7 @@ require_relative "procon_bypass_man/support/update_remote_pbm_action_status_http_client" require_relative "procon_bypass_man/support/send_device_stats_http_client" require_relative "procon_bypass_man/support/server_pool" +require_relative "procon_bypass_man/support/time_scoped_map" require_relative "procon_bypass_man/background" require_relative "procon_bypass_man/commands" require_relative "procon_bypass_man/bypass" diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb new file mode 100644 index 00000000..5d96bec6 --- /dev/null +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -0,0 +1,32 @@ +class ProconBypassMan::TimeScopedMap + def initialize + @duration = 60 + @map = {} + @result = nil + end + + def add(value) + if @map[key].nil? + rotate + @map = { key => [] } + end + + @map[key] << value + end + + def result + @result || {} + end + + private + + # 0.1sec刻みで進行する + def key + t = Time.now.to_i + @duration - (t % @duration) + end + + def rotate + @result = { list: @map.values.first } + end +end diff --git a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb new file mode 100644 index 00000000..67b66b51 --- /dev/null +++ b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb @@ -0,0 +1,25 @@ +require "spec_helper" + +describe ProconBypassMan::TimeScopedMap do + it do + map = ProconBypassMan::TimeScopedMap.new + Timecop.freeze do + map.add 1 + map.add 2 + expect(map.result).to eq({ list: nil }) + end + end + + it do + map = ProconBypassMan::TimeScopedMap.new + Timecop.freeze do + map.add 1 + map.add 2 + end + + Timecop.freeze(Time.now + 1) do + map.add 1 + expect(map.result).to eq({ list: [1, 2] }) + end + end +end From f9b63d81864ab9431abda1f8514081e659d048fd Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 13:28:49 +0900 Subject: [PATCH 02/44] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=AE=E6=A7=8B=E6=96=87=E3=82=92=E6=B1=BA?= =?UTF-8?q?=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buttons_setting_configuration/layer.rb | 8 +++++++- .../buttons_setting_configuration_spec.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb index 37ee2de2..ffe073aa 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb @@ -1,11 +1,12 @@ module ProconBypassMan class ButtonsSettingConfiguration class Layer - attr_accessor :mode, :flips, :macros, :remaps, :left_analog_stick_caps, :disables + attr_accessor :mode, :flips, :toggles, :macros, :remaps, :left_analog_stick_caps, :disables def initialize(mode: :manual) self.mode = mode self.flips = {} + self.toggles = {} self.macros = {} self.remaps = {} self.left_analog_stick_caps = [] @@ -53,6 +54,11 @@ def flip(button, if_pressed: false, force_neutral: nil, flip_interval: nil) self.flips[button] = hash end + # ユースケースが不明なので雑な実装をする + def toggle(buttons, if_tilted_left_stick: ) + self.toggles[buttons] = { if_tilted_left_stick: if_tilted_left_stick } + end + # @param [String, Class] プラグインのclass def macro(name, if_pressed: ) macro_name = name.to_s.to_sym 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 ecc5ae1f..4b2a5273 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -661,6 +661,17 @@ def self.binaries; ['a']; end expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons[:zr][:flip_interval]).to eq(0.13) end end + + context 'toggle with if_tilted_left_stick' do + it do + ProconBypassMan.buttons_setting_configure do + layer :up do + toggle :zr, if_tilted_left_stick: true + end + end + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].toggles[:zr]).to eq(if_tilted_left_stick: true) + end + end end describe 'validations' do From fdbaabdaf3cf1ecaedf5b4e726451be506a6db83 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 13:34:57 +0900 Subject: [PATCH 03/44] Drop ruby2-7 --- .circleci/config.yml | 5 ----- .github/workflows/ruby.yml | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a1b18900..4c9d2b81 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -96,7 +96,6 @@ build_jobs: &build_jobs matrix: parameters: ruby-version: - - "2.7" - "3.0.1" - "3.0.2" - "3.1.1" @@ -104,7 +103,6 @@ build_jobs: &build_jobs matrix: parameters: ruby-version: - - "2.7" - "3.0.1" - "3.0.2" - "3.1.1" @@ -112,7 +110,6 @@ build_jobs: &build_jobs matrix: parameters: ruby-version: - - "2.7" - "3.0.1" - "3.0.2" - "3.1.1" @@ -122,7 +119,6 @@ build_jobs: &build_jobs matrix: parameters: ruby-version: - - "2.7" # - "3.0.1" # たまにSEGVするので - "3.0.2" - "3.1.1" @@ -132,7 +128,6 @@ build_jobs: &build_jobs matrix: parameters: ruby-version: - - "2.7" - "3.0.1" - "3.0.2" - "3.1.1" diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 64020d7b..d2e48bcb 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.7', '3.0.1'] + ruby-version: ['3.0.1', '3.1.1'] steps: - uses: actions/checkout@v2 From 889c7db3bd7d14fd628708145678147aecf0ba70 Mon Sep 17 00:00:00 2001 From: jiikko Date: Tue, 22 Feb 2022 21:08:00 +0900 Subject: [PATCH 04/44] watchdog --- lib/procon_bypass_man.rb | 1 + .../websocket/pbm_job_client.rb | 20 +++++++++++++++---- lib/procon_bypass_man/websocket/watchdog.rb | 15 ++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 lib/procon_bypass_man/websocket/watchdog.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 20c9a88e..203c0c3a 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -48,6 +48,7 @@ require_relative "procon_bypass_man/scheduler" require_relative "procon_bypass_man/plugins" require_relative "procon_bypass_man/websocket/pbm_job_client" +require_relative "procon_bypass_man/websocket/watch_dog" STDOUT.sync = true Thread.abort_on_exception = true diff --git a/lib/procon_bypass_man/websocket/pbm_job_client.rb b/lib/procon_bypass_man/websocket/pbm_job_client.rb index ffdef9e1..3a1a17fd 100644 --- a/lib/procon_bypass_man/websocket/pbm_job_client.rb +++ b/lib/procon_bypass_man/websocket/pbm_job_client.rb @@ -8,10 +8,20 @@ def self.start! Thread.start do loop do - run - rescue => e - ProconBypassMan.logger.error("websocket client: #{e.full_message}") - retry + ws_thread = Thread.start do + loop do + run + rescue => e + ProconBypassMan.logger.error("websocket client: #{e.full_message}") + retry + end + end + + if Watchdog.outdated? + ws_thread.kill + end + + sleep(10) end end end @@ -55,6 +65,8 @@ def self.run sleep 2 } client.pinged { |msg| + Watchdog.active! + ProconBypassMan.cache.fetch key: 'ws_pinged', expires_in: 10 do ProconBypassMan.logger.info('websocket client: pinged!!') ProconBypassMan.logger.info(msg) diff --git a/lib/procon_bypass_man/websocket/watchdog.rb b/lib/procon_bypass_man/websocket/watchdog.rb new file mode 100644 index 00000000..a4541320 --- /dev/null +++ b/lib/procon_bypass_man/websocket/watchdog.rb @@ -0,0 +1,15 @@ +module ProconBypassMan + module Websocket + class Watchdog + def self.outdated? + @@time < (Time.now + 60) + end + + def self.active! + @@time = Time.now + end + + active! + end + end +end From 7ba92aaf728e0addaa1bbe87faa01b9006f4f6fc Mon Sep 17 00:00:00 2001 From: jiikko Date: Tue, 22 Feb 2022 22:48:14 +0900 Subject: [PATCH 05/44] =?UTF-8?q?wecsocket=E3=81=AE=E6=8E=A5=E7=B6=9A?= =?UTF-8?q?=E3=81=8C=E6=AD=BB=E3=82=93=E3=81=A0=E3=82=89=E3=82=82=E3=81=86?= =?UTF-8?q?=E4=B8=80=E5=BA=A6=E6=8E=A5=E7=B6=9A=E3=82=92=E8=A9=A6=E3=81=BF?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man.rb | 3 +- lib/procon_bypass_man/websocket/forever.rb | 47 +++++++++++++++++++ .../websocket/pbm_job_client.rb | 17 +------ lib/procon_bypass_man/websocket/watchdog.rb | 8 +++- .../websocket/forever_spec.rb | 38 +++++++++++++++ .../websocket/watchdog_spec.rb | 19 ++++++++ 6 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 lib/procon_bypass_man/websocket/forever.rb create mode 100644 spec/lib/procon_bypass_man/websocket/forever_spec.rb create mode 100644 spec/lib/procon_bypass_man/websocket/watchdog_spec.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 203c0c3a..8db17a5e 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -48,7 +48,8 @@ require_relative "procon_bypass_man/scheduler" require_relative "procon_bypass_man/plugins" require_relative "procon_bypass_man/websocket/pbm_job_client" -require_relative "procon_bypass_man/websocket/watch_dog" +require_relative "procon_bypass_man/websocket/watchdog" +require_relative "procon_bypass_man/websocket/forever" STDOUT.sync = true Thread.abort_on_exception = true diff --git a/lib/procon_bypass_man/websocket/forever.rb b/lib/procon_bypass_man/websocket/forever.rb new file mode 100644 index 00000000..9dd5c831 --- /dev/null +++ b/lib/procon_bypass_man/websocket/forever.rb @@ -0,0 +1,47 @@ +module ProconBypassMan + module Websocket + class Forever + # 動作確認方法 + # - 10秒ごとにrefreshするのでタイムアウトは起きない + # - ProconBypassMan::Websocket::Forever.run { loop { puts(:hi); sleep(10); ProconBypassMan::Websocket::Watchdog.active! } } + # - タイムアウトが起きること + # - ProconBypassMan::Websocket::Forever.run { puts(:hi); sleep(3000); } + # - ブロックを1回評価するとThreadが死ぬので100秒後にタイムアウトが起きること + # - ProconBypassMan::Websocket::Forever.run { puts(:hi); sleep(10); ProconBypassMan::Websocket::Watchdog.active! } + def self.run(&block) + loop do + new.run(&block) + end + end + + def run(&block) + raise("need a block") unless block_given? + + ws_thread = work_one(callable: block) + wait_and_kill_if_outdated(ws_thread) + end + + # @return [Thread] + def work_one(callable: ) + Thread.start do + callable.call + rescue => e + ProconBypassMan.logger.error("websocket client with forever: #{e.full_message}") + end + end + + def wait_and_kill_if_outdated(thread) + loop do + if Watchdog.outdated? + Watchdog.active! + ProconBypassMan.logger.error("watchdog timeout!!") + thread.kill + return + end + + sleep(10) + end + end + end + end +end diff --git a/lib/procon_bypass_man/websocket/pbm_job_client.rb b/lib/procon_bypass_man/websocket/pbm_job_client.rb index 3a1a17fd..fa3edd68 100644 --- a/lib/procon_bypass_man/websocket/pbm_job_client.rb +++ b/lib/procon_bypass_man/websocket/pbm_job_client.rb @@ -7,22 +7,7 @@ def self.start! return unless ProconBypassMan.config.enable_ws? Thread.start do - loop do - ws_thread = Thread.start do - loop do - run - rescue => e - ProconBypassMan.logger.error("websocket client: #{e.full_message}") - retry - end - end - - if Watchdog.outdated? - ws_thread.kill - end - - sleep(10) - end + Forever.run { run } end end diff --git a/lib/procon_bypass_man/websocket/watchdog.rb b/lib/procon_bypass_man/websocket/watchdog.rb index a4541320..18f0b8b3 100644 --- a/lib/procon_bypass_man/websocket/watchdog.rb +++ b/lib/procon_bypass_man/websocket/watchdog.rb @@ -2,11 +2,15 @@ module ProconBypassMan module Websocket class Watchdog def self.outdated? - @@time < (Time.now + 60) + @@time < Time.now + end + + def self.time + @@time end def self.active! - @@time = Time.now + @@time = Time.now + 100 end active! diff --git a/spec/lib/procon_bypass_man/websocket/forever_spec.rb b/spec/lib/procon_bypass_man/websocket/forever_spec.rb new file mode 100644 index 00000000..cb7ee9ff --- /dev/null +++ b/spec/lib/procon_bypass_man/websocket/forever_spec.rb @@ -0,0 +1,38 @@ +require "spec_helper" + +describe ProconBypassMan::Websocket::Forever do + let(:instance) { described_class.new } + + describe '#work_one' do + let(:block) { double(:block) } + + subject { instance.work_one(callable: block) } + + it do + expect(block).to receive(:call) + thread = subject + thread.join + end + end + + describe '#wait_and_kill_if_outdated' do + let(:thread) { double(:thread) } + + subject { instance.wait_and_kill_if_outdated(thread) } + + before do + allow(ProconBypassMan::Websocket::Watchdog).to receive(:outdated?) { true } + thread.as_null_object + end + + it 'should kill the thread' do + expect(thread).to receive(:kill) + subject + end + + it 'refresh Watchdog' do + expect(ProconBypassMan::Websocket::Watchdog).to receive(:active!) + subject + end + end +end diff --git a/spec/lib/procon_bypass_man/websocket/watchdog_spec.rb b/spec/lib/procon_bypass_man/websocket/watchdog_spec.rb new file mode 100644 index 00000000..e55ebc8a --- /dev/null +++ b/spec/lib/procon_bypass_man/websocket/watchdog_spec.rb @@ -0,0 +1,19 @@ +require "spec_helper" + +describe ProconBypassMan::Websocket::Watchdog do + describe '.active!, .outdated?' do + it do + ProconBypassMan::Websocket::Watchdog.active! + Timecop.freeze(Time.now + 300) do + expect(ProconBypassMan::Websocket::Watchdog.outdated?).to eq(true) + end + end + + it do + Timecop.freeze do + ProconBypassMan::Websocket::Watchdog.active! + expect(ProconBypassMan::Websocket::Watchdog.outdated?).to eq(false) + end + end + end +end From ba1b9596d92bae90dcfe9d582fb345a4aedcca77 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 13:54:13 +0900 Subject: [PATCH 06/44] log --- lib/procon_bypass_man/procon.rb | 8 ++++++++ lib/procon_bypass_man/support/time_scoped_map.rb | 3 ++- .../support/time_scoped_map_spec.rb | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 71669f5f..3194093c 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -19,6 +19,7 @@ def self.reset! ongoing_macro: MacroRegistry.load(:null), ongoing_mode: ModeRegistry.load(:manual), } + @@map = ProconBypassMan::TimeScopedMap.new end reset! @@ -27,6 +28,13 @@ def initialize(binary) self.user_operation = ProconBypassMan::Procon::UserOperation.new( binary.dup ) + + reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: binary.dup).to_procon_reader + @@map.add( + { relative: reader.left_analog_stick, abs: reader.left_analog_stick_by_abs } + ) do |result| + ProconBypassMan.logger.info result + end end def status; @@status[:buttons]; end diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb index 5d96bec6..93f5aeff 100644 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -5,9 +5,10 @@ def initialize @result = nil end - def add(value) + def add(value, &block) if @map[key].nil? rotate + block.call(result) if block_given? && result[:list] @map = { key => [] } end diff --git a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb index 67b66b51..298e2216 100644 --- a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb +++ b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb @@ -22,4 +22,17 @@ expect(map.result).to eq({ list: [1, 2] }) end end + + it do + map = ProconBypassMan::TimeScopedMap.new + Timecop.freeze do + map.add(1) { raise "do not call" } + map.add(2) { raise "do not call" } + end + + Timecop.freeze(Time.now + 1) do + map.add(1) { |result| expect(result).to eq({ list: [1, 2] }) } + expect(map.result).to eq({ list: [1, 2] }) + end + end end From 0612d44ac35b4a944ac4393fa232419c9f07a81c Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 14:08:44 +0900 Subject: [PATCH 07/44] fix interval --- lib/procon_bypass_man/procon.rb | 3 ++- lib/procon_bypass_man/support/time_scoped_map.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 3194093c..e8af18f0 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -30,8 +30,9 @@ def initialize(binary) ) reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: binary.dup).to_procon_reader + hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) @@map.add( - { relative: reader.left_analog_stick, abs: reader.left_analog_stick_by_abs } + { relative: reader.left_analog_stick, hypotenuse: hypotenuse } ) do |result| ProconBypassMan.logger.info result end diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb index 93f5aeff..f33d6e74 100644 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -23,7 +23,8 @@ def result # 0.1sec刻みで進行する def key - t = Time.now.to_i + time = Time.now + t = [time.to_i, time.usec.to_s[0]].join.to_i @duration - (t % @duration) end From ee8990095c7c4c4b32de88d45daf282d20739196 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 14:16:20 +0900 Subject: [PATCH 08/44] ooooooops --- lib/procon_bypass_man/support/time_scoped_map.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb index f33d6e74..a72929f1 100644 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -6,13 +6,14 @@ def initialize end def add(value, &block) - if @map[key].nil? + current_key = key + if @map[current_key].nil? rotate block.call(result) if block_given? && result[:list] - @map = { key => [] } + @map = { current_key => [] } end - @map[key] << value + @map[current_key] << value end def result From 77ad32443f432c6be9b11287849a74a0f7b0b8e7 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 16:47:23 +0900 Subject: [PATCH 09/44] summary --- lib/procon_bypass_man/procon.rb | 2 +- lib/procon_bypass_man/procon/stick_positions_list.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 lib/procon_bypass_man/procon/stick_positions_list.rb diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index e8af18f0..4b27ad24 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -34,7 +34,7 @@ def initialize(binary) @@map.add( { relative: reader.left_analog_stick, hypotenuse: hypotenuse } ) do |result| - ProconBypassMan.logger.info result + ProconBypassMan.logger.info ProconBypassMan::StickPositionsList.new(result[:list]).moving_power end end diff --git a/lib/procon_bypass_man/procon/stick_positions_list.rb b/lib/procon_bypass_man/procon/stick_positions_list.rb new file mode 100644 index 00000000..c4112574 --- /dev/null +++ b/lib/procon_bypass_man/procon/stick_positions_list.rb @@ -0,0 +1,11 @@ +class ProconBypassMan::StickPositionsList + def initialize(list) + @list = list + end + + def moving_power + max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + (max - min).abs + end +end From 06512efcd2741ab549773e02c700780504813f74 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 16:50:27 +0900 Subject: [PATCH 10/44] oooooops --- lib/procon_bypass_man.rb | 1 + lib/procon_bypass_man/procon/stick_positions_list.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 8db17a5e..cd55155d 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -44,6 +44,7 @@ require_relative "procon_bypass_man/procon/value_objects/analog_stick" require_relative "procon_bypass_man/procon/value_objects/procon_reader" require_relative "procon_bypass_man/procon/analog_stick_cap" +require_relative "procon_bypass_man/procon/stick_positions_list" require_relative "procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object" require_relative "procon_bypass_man/scheduler" require_relative "procon_bypass_man/plugins" diff --git a/lib/procon_bypass_man/procon/stick_positions_list.rb b/lib/procon_bypass_man/procon/stick_positions_list.rb index c4112574..943e0afb 100644 --- a/lib/procon_bypass_man/procon/stick_positions_list.rb +++ b/lib/procon_bypass_man/procon/stick_positions_list.rb @@ -4,8 +4,8 @@ def initialize(list) end def moving_power - max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } - min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] }[:hypotenuse] + min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] }[:hypotenuse] (max - min).abs end end From d72ac34f1b8b02c30f7f9f5a695382f28fa03a24 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 17:19:47 +0900 Subject: [PATCH 11/44] =?UTF-8?q?=E3=81=AF=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/procon.rb | 6 ++---- lib/procon_bypass_man/procon/stick_positions_list.rb | 6 +++--- lib/procon_bypass_man/support/time_scoped_map.rb | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 4b27ad24..34b60471 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -31,10 +31,8 @@ def initialize(binary) reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: binary.dup).to_procon_reader hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) - @@map.add( - { relative: reader.left_analog_stick, hypotenuse: hypotenuse } - ) do |result| - ProconBypassMan.logger.info ProconBypassMan::StickPositionsList.new(result[:list]).moving_power + @@map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| + ProconBypassMan.logger.info "moving: #{ProconBypassMan::StickPositionsList.new(result[:list]).moving_power}" end end diff --git a/lib/procon_bypass_man/procon/stick_positions_list.rb b/lib/procon_bypass_man/procon/stick_positions_list.rb index 943e0afb..695378d8 100644 --- a/lib/procon_bypass_man/procon/stick_positions_list.rb +++ b/lib/procon_bypass_man/procon/stick_positions_list.rb @@ -4,8 +4,8 @@ def initialize(list) end def moving_power - max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] }[:hypotenuse] - min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] }[:hypotenuse] - (max - min).abs + max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + { power: (max[:hypotenuse] - min[:hypotenuse]).abs, max: max[:relative], min: min[:relative] } end end diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb index a72929f1..567f75ee 100644 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -1,6 +1,5 @@ class ProconBypassMan::TimeScopedMap def initialize - @duration = 60 @map = {} @result = nil end @@ -25,8 +24,8 @@ def result # 0.1sec刻みで進行する def key time = Time.now - t = [time.to_i, time.usec.to_s[0]].join.to_i - @duration - (t % @duration) + m1 = time.strftime('%L')[0] + [time.to_i, m1].join.to_i end def rotate From 1aeda15372aafde37edb473728ff75d631e420da Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 17:58:09 +0900 Subject: [PATCH 12/44] =?UTF-8?q?=E5=88=A4=E5=AE=9A=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=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 + .../buttons_setting_configuration/layer.rb | 17 ++++++++++++++-- lib/procon_bypass_man/procon.rb | 20 ++++++++++++------- .../procon/tilting_stick_aware.rb | 9 +++++++++ .../buttons_setting_configuration_spec.rb | 2 +- .../procon/tilting_stich_aware_spec.rb | 17 ++++++++++++++++ 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 lib/procon_bypass_man/procon/tilting_stick_aware.rb create mode 100644 spec/lib/procon_bypass_man/procon/tilting_stich_aware_spec.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index cd55155d..6e589ed5 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -45,6 +45,7 @@ require_relative "procon_bypass_man/procon/value_objects/procon_reader" require_relative "procon_bypass_man/procon/analog_stick_cap" require_relative "procon_bypass_man/procon/stick_positions_list" +require_relative "procon_bypass_man/procon/tilting_stick_aware" require_relative "procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object" require_relative "procon_bypass_man/scheduler" require_relative "procon_bypass_man/plugins" diff --git a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb index ffe073aa..9660ca8d 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb @@ -55,8 +55,21 @@ def flip(button, if_pressed: false, force_neutral: nil, flip_interval: nil) end # ユースケースが不明なので雑な実装をする - def toggle(buttons, if_tilted_left_stick: ) - self.toggles[buttons] = { if_tilted_left_stick: if_tilted_left_stick } + def toggle(button, if_tilted_left_stick: , if_pressed: nil) + case if_pressed + when TrueClass + if_pressed = [button] + when Symbol, String + if_pressed = [if_pressed] + when Array + # if_pressed = if_pressed + when FalseClass, NilClass + # no-op + else + raise "not support class" + end + + self.toggles[button] = { if_tilted_left_stick: if_tilted_left_stick, if_pressed: if_pressed } end # @param [String, Class] プラグインのclass diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 34b60471..60930bbb 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -19,7 +19,7 @@ def self.reset! ongoing_macro: MacroRegistry.load(:null), ongoing_mode: ModeRegistry.load(:manual), } - @@map = ProconBypassMan::TimeScopedMap.new + @@left_stick_report_map = ProconBypassMan::TimeScopedMap.new end reset! @@ -28,12 +28,6 @@ def initialize(binary) self.user_operation = ProconBypassMan::Procon::UserOperation.new( binary.dup ) - - reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: binary.dup).to_procon_reader - hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) - @@map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| - ProconBypassMan.logger.info "moving: #{ProconBypassMan::StickPositionsList.new(result[:list]).moving_power}" - end end def status; @@status[:buttons]; end @@ -148,6 +142,18 @@ def to_binary end end + current_layer.toggles.each do |button, options| + reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw).to_procon_reader + hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) + + @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| + ProconBypassMan.logger.info "moving: #{ProconBypassMan::StickPositionsList.new(result[:list]).moving_power}" + if ProconBypassMan::StickSwingAware.swing?(result) && user_operation.pressing_all_buttons?(options[:if_pressed]) + user_operation.press_button(button) + end + end + end + user_operation.binary.raw end diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb new file mode 100644 index 00000000..4ca68a9d --- /dev/null +++ b/lib/procon_bypass_man/procon/tilting_stick_aware.rb @@ -0,0 +1,9 @@ +class ProconBypassMan::TiltingStickAware + def self.tilting?(result) + if (-200..200).include?(result[:min][:x]) && (-200..200).include?(result[:min][:y]) + return false + end + + result[:power] > 500 + 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 4b2a5273..9ccce008 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -669,7 +669,7 @@ def self.binaries; ['a']; end toggle :zr, if_tilted_left_stick: true end end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].toggles[:zr]).to eq(if_tilted_left_stick: true) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].toggles[:zr]).to eq(if_tilted_left_stick: true, if_pressed: nil) end end end diff --git a/spec/lib/procon_bypass_man/procon/tilting_stich_aware_spec.rb b/spec/lib/procon_bypass_man/procon/tilting_stich_aware_spec.rb new file mode 100644 index 00000000..01426f55 --- /dev/null +++ b/spec/lib/procon_bypass_man/procon/tilting_stich_aware_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe ProconBypassMan::TiltingStickAware do + context 'スティックを傾けるとき' do + it do + report = {:power=>668.242084, :max=>{:x=>-1398, :y=>-365}, :min=>{:x=>-752, :y=>-194}} + expect(described_class.tilting?(report)).to eq(true) + end + end + + context 'スティックを戻すとき' do + it do + report = {:power=>1069.9772189999999, :max=>{:x=>-1025, :y=>-464}, :min=>{:x=>-21, :y=>-51}} + expect(described_class.tilting?(report)).to eq(false) + end + end +end From b4701a466b90b734fa5e0702c0569d4845cfbad5 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 18:02:31 +0900 Subject: [PATCH 13/44] ooops --- lib/procon_bypass_man/procon.rb | 2 +- ...{tilting_stich_aware_spec.rb => tilting_stick_aware_spec.rb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename spec/lib/procon_bypass_man/procon/{tilting_stich_aware_spec.rb => tilting_stick_aware_spec.rb} (100%) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 60930bbb..78d2c2d5 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -148,7 +148,7 @@ def to_binary @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| ProconBypassMan.logger.info "moving: #{ProconBypassMan::StickPositionsList.new(result[:list]).moving_power}" - if ProconBypassMan::StickSwingAware.swing?(result) && user_operation.pressing_all_buttons?(options[:if_pressed]) + if ProconBypassMan::TiltingStickAware.tilting?(result) && user_operation.pressing_all_buttons?(options[:if_pressed]) user_operation.press_button(button) end end diff --git a/spec/lib/procon_bypass_man/procon/tilting_stich_aware_spec.rb b/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb similarity index 100% rename from spec/lib/procon_bypass_man/procon/tilting_stich_aware_spec.rb rename to spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb From 81898951d8945de6e012734dc3c00796a7638db7 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 18:06:49 +0900 Subject: [PATCH 14/44] guard --- lib/procon_bypass_man/procon/tilting_stick_aware.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb index 4ca68a9d..3318d6c2 100644 --- a/lib/procon_bypass_man/procon/tilting_stick_aware.rb +++ b/lib/procon_bypass_man/procon/tilting_stick_aware.rb @@ -1,5 +1,6 @@ class ProconBypassMan::TiltingStickAware def self.tilting?(result) + return false if result.nil? if (-200..200).include?(result[:min][:x]) && (-200..200).include?(result[:min][:y]) return false end From 295494ec7e434e55e82a654af4fbae67a54df238 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 18:10:31 +0900 Subject: [PATCH 15/44] oooooooops --- lib/procon_bypass_man/procon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 78d2c2d5..1cc7ea71 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -148,7 +148,7 @@ def to_binary @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| ProconBypassMan.logger.info "moving: #{ProconBypassMan::StickPositionsList.new(result[:list]).moving_power}" - if ProconBypassMan::TiltingStickAware.tilting?(result) && user_operation.pressing_all_buttons?(options[:if_pressed]) + if ProconBypassMan::TiltingStickAware.tilting?(result[:list].moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) user_operation.press_button(button) end end From f438be75c4f817b4669bf2ed303041b4c7ffb37d Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 18:15:45 +0900 Subject: [PATCH 16/44] ooooooops --- lib/procon_bypass_man/procon.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 1cc7ea71..6b1dc480 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -147,8 +147,9 @@ def to_binary hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| - ProconBypassMan.logger.info "moving: #{ProconBypassMan::StickPositionsList.new(result[:list]).moving_power}" - if ProconBypassMan::TiltingStickAware.tilting?(result[:list].moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) + moving_power = ProconBypassMan::StickPositionsList.new(result[:list]).moving_power + ProconBypassMan.logger.info "moving: #{moving_power}" + if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) user_operation.press_button(button) end end From 917e13a7dbc76fa02ddd4d5b98d9e7e66fa98f40 Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 18:23:50 +0900 Subject: [PATCH 17/44] wakaran --- lib/procon_bypass_man/procon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 6b1dc480..0e4eac66 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -143,7 +143,7 @@ def to_binary end current_layer.toggles.each do |button, options| - reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw).to_procon_reader + reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| From 28e849036a491e83a7c1b65abb0db203f3b17fde Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 23 Feb 2022 22:25:37 +0900 Subject: [PATCH 18/44] =?UTF-8?q?macro=E3=81=A8=E3=81=97=E3=81=A6=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buttons_setting_configuration/layer.rb | 25 +++---------------- lib/procon_bypass_man/procon.rb | 24 ++++++++---------- .../support/time_scoped_map.rb | 9 ++++++- .../buttons_setting_configuration_spec.rb | 24 ++++++++++-------- .../support/time_scoped_map_spec.rb | 6 ++--- 5 files changed, 38 insertions(+), 50 deletions(-) diff --git a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb index 9660ca8d..d5e3560b 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb @@ -1,12 +1,11 @@ module ProconBypassMan class ButtonsSettingConfiguration class Layer - attr_accessor :mode, :flips, :toggles, :macros, :remaps, :left_analog_stick_caps, :disables + attr_accessor :mode, :flips, :macros, :remaps, :left_analog_stick_caps, :disables def initialize(mode: :manual) self.mode = mode self.flips = {} - self.toggles = {} self.macros = {} self.remaps = {} self.left_analog_stick_caps = [] @@ -54,24 +53,6 @@ def flip(button, if_pressed: false, force_neutral: nil, flip_interval: nil) self.flips[button] = hash end - # ユースケースが不明なので雑な実装をする - def toggle(button, if_tilted_left_stick: , if_pressed: nil) - case if_pressed - when TrueClass - if_pressed = [button] - when Symbol, String - if_pressed = [if_pressed] - when Array - # if_pressed = if_pressed - when FalseClass, NilClass - # no-op - else - raise "not support class" - end - - self.toggles[button] = { if_tilted_left_stick: if_tilted_left_stick, if_pressed: if_pressed } - end - # @param [String, Class] プラグインのclass def macro(name, if_pressed: ) macro_name = name.to_s.to_sym @@ -81,10 +62,10 @@ def macro(name, if_pressed: ) # 設定ファイルに直接マクロを打ち込める # @param [String, Class] macroの識別子 # @paramh[Array] macroの本体. ボタンの配列 - def open_macro(name, steps: , if_pressed: ) + def open_macro(name, steps: , if_pressed: , if_tilted_left_stick: nil) macro_name = name || "OpenMacro-#{steps.join}".to_sym ProconBypassMan::Procon::MacroRegistry.install_plugin(macro_name, steps: steps) - self.macros[macro_name] = { if_pressed: if_pressed } + self.macros[macro_name] = { if_pressed: if_pressed, if_tilted_left_stick: if_tilted_left_stick }.compact end def remap(button, to: ) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 0e4eac66..c3285e6a 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -49,6 +49,17 @@ def apply! if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| + if options[:if_tilted_left_stick] + reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader + hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) + + rotated = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) + if user_operation.pressing_all_buttons?(options[:if_pressed]) && rotated + @@status[:ongoing_macro] = MacroRegistry.load(macro_name) + end + next + end + if user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) end @@ -142,19 +153,6 @@ def to_binary end end - current_layer.toggles.each do |button, options| - reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader - hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) - - @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) do |result| - moving_power = ProconBypassMan::StickPositionsList.new(result[:list]).moving_power - ProconBypassMan.logger.info "moving: #{moving_power}" - if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) - user_operation.press_button(button) - end - end - end - user_operation.binary.raw end diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb index 567f75ee..04b6a34c 100644 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -5,14 +5,21 @@ def initialize end def add(value, &block) + rotated = false current_key = key if @map[current_key].nil? rotate - block.call(result) if block_given? && result[:list] + if result[:list] + if block_given? + block.call(result) + end + rotated = true + end @map = { current_key => [] } end @map[current_key] << value + rotated end def result 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 9ccce008..a9b3e2b0 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -514,6 +514,19 @@ def self.steps; [:a, :b]; end { :sokuwari => {:if_pressed=>[:zr, :down]} } ) end + context 'with if_tilted_left_stick' do + it do + ProconBypassMan.buttons_setting_configure do + layer :up do + open_macro :dacan, steps: [:r, :zl], if_tilted_left_stick: true, if_pressed: [:zr] + end + end + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([:r, :zl]) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } + ) + end + end end end context 'with install mode plugin' do @@ -661,17 +674,6 @@ def self.binaries; ['a']; end expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].flip_buttons[:zr][:flip_interval]).to eq(0.13) end end - - context 'toggle with if_tilted_left_stick' do - it do - ProconBypassMan.buttons_setting_configure do - layer :up do - toggle :zr, if_tilted_left_stick: true - end - end - expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].toggles[:zr]).to eq(if_tilted_left_stick: true, if_pressed: nil) - end - end end describe 'validations' do diff --git a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb index 298e2216..89ac0632 100644 --- a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb +++ b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb @@ -13,12 +13,12 @@ it do map = ProconBypassMan::TimeScopedMap.new Timecop.freeze do - map.add 1 - map.add 2 + expect(map.add 1).to eq(false) + expect(map.add 2).to eq(false) end Timecop.freeze(Time.now + 1) do - map.add 1 + expect(map.add 1).to eq(true) expect(map.result).to eq({ list: [1, 2] }) end end From fd2cd6419dc7a54f5a238e5124ead5c00f5435b8 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 19:36:21 +0900 Subject: [PATCH 19/44] =?UTF-8?q?v2=20macro=E3=81=AE=E5=87=BA=E5=8A=9B?= =?UTF-8?q?=E3=81=99=E3=82=8B=E9=A0=86=E7=95=AA=E3=82=92=E5=85=A5=E3=82=8C?= =?UTF-8?q?=E6=9B=BF=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/procon.rb | 1 + lib/procon_bypass_man/procon/macro_builder.rb | 24 ++++++++++++------- .../buttons_setting_configuration_spec.rb | 13 +++++++--- .../procon/macro_builder_spec.rb | 11 +++++++++ 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index c3285e6a..a085b5c9 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -55,6 +55,7 @@ def apply! rotated = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) if user_operation.pressing_all_buttons?(options[:if_pressed]) && rotated + ProconBypassMan.logger.info(rotated) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) end next diff --git a/lib/procon_bypass_man/procon/macro_builder.rb b/lib/procon_bypass_man/procon/macro_builder.rb index 514ac7a7..c7c17429 100644 --- a/lib/procon_bypass_man/procon/macro_builder.rb +++ b/lib/procon_bypass_man/procon/macro_builder.rb @@ -38,7 +38,7 @@ def pressing? def to_steps case @type when :toggle - [@button.to_sym, :none] + [:none, @button.to_sym] when :pressing [@button.to_sym, @button.to_sym] end @@ -88,13 +88,21 @@ def build_if_v2_format?(step: ) end # 時間指定あり - if %r!^(pressing_|toggle_)! =~ step && (subjects = step.scan(%r!pressing_[^_]+|toggle_[^_]+!)) && (match = step.match(%r!_for_([\d_]+)(sec)?\z!)) - sec = match[1] - return [ - { continue_for: to_num(sec), - steps: SubjectMerger.merge(subjects.map { |x| Subject.new(x) }), - } - ] + if %r!^(pressing_|toggle_)! =~ step && (subjects = step.scan(%r!pressing_[^_]+|toggle_[^_]+!)) + if(match = step.match(%r!_for_([\d_]+)(sec)?\z!)) + sec = match[1] + return [ + { continue_for: to_num(sec), + steps: SubjectMerger.merge(subjects.map { |x| Subject.new(x) }), + } + ] + else + return [ + { continue_for: nil, + steps: SubjectMerger.merge(subjects.map { |x| Subject.new(x) }), + } + ] + end end # no-op command 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 a9b3e2b0..8c8e1ae8 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -509,7 +509,14 @@ def self.steps; [:a, :b]; end open_macro :sokuwari, steps: [:toggle_r, :toggle_thumbr_for_2sec, :toggle_zr_for_1sec, :toggle_r], if_pressed: [:zr, :down] end end - expect(ProconBypassMan::Procon::MacroRegistry.plugins[:sokuwari].call).to eq([:r, :none, {:continue_for=>2, :steps=>[:thumbr, :none]}, {:continue_for=>1, :steps=>[:zr, :none]}, :r, :none]) + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:sokuwari].call).to eq([ + :r, + :none, + {:continue_for=>2, :steps=>[:none, :thumbr]}, + {:continue_for=>1, :steps=>[:none, :zr]}, + :r, + :none, + ]) expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( { :sokuwari => {:if_pressed=>[:zr, :down]} } ) @@ -518,10 +525,10 @@ def self.steps; [:a, :b]; end it do ProconBypassMan.buttons_setting_configure do layer :up do - open_macro :dacan, steps: [:r, :zl], if_tilted_left_stick: true, if_pressed: [:zr] + open_macro :dacan, steps: [:pressing_r_and_toggle_zr], if_tilted_left_stick: true, if_pressed: [:zr] end end - expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([:r, :zl]) + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([{:continue_for=>nil, :steps=>[[:r, :none], [:r, :zr]]}]) expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) diff --git a/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb b/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb index 7d7b294a..ddf75cc8 100644 --- a/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb +++ b/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb @@ -94,6 +94,17 @@ end end + describe 'pressing_r_and_toggle_zr' do + it do + expect(described_class.new([:pressing_r_and_toggle_zr]).build).to eq( + [{ continue_for: nil, steps: [ + [:r, :zr], + [:r, :none], + ] }] + ) + end + end + describe 'pressing_x_and_toggle_zr_for_0_2sec' do it do expect(described_class.new([:pressing_x_and_toggle_zr_for_0_2sec]).build).to eq( From 2379224b61e53073ede17a9ad8d9f81bdc70e75d Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:07:49 +0900 Subject: [PATCH 20/44] =?UTF-8?q?v2=20macro=E3=81=A7=E6=99=82=E9=96=93?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=81=AA=E3=81=97=E3=81=A7=E5=8B=95=E3=81=8F?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=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/procon/macro.rb | 54 +++++++++++++++++-- .../procon/macro_builder_spec.rb | 24 ++++----- .../procon_bypass_man/procon/macro_spec.rb | 18 +++++++ spec/lib/procon_bypass_man/procon_spec.rb | 8 +-- 4 files changed, 83 insertions(+), 21 deletions(-) diff --git a/lib/procon_bypass_man/procon/macro.rb b/lib/procon_bypass_man/procon/macro.rb index 1e3f111b..b2a44594 100644 --- a/lib/procon_bypass_man/procon/macro.rb +++ b/lib/procon_bypass_man/procon/macro.rb @@ -1,4 +1,38 @@ class ProconBypassMan::Procon::Macro + class OnetimeNestedStep + def initialize(value) + @hash = value + end + + def over? + current_step.nil? + end + + def next_step + step = current_step + incr_step_index! + step + end + + private + + def current_step + @hash[:steps][step_index] + end + + def step_index + @hash[:step_index] ||= 0 + end + + def incr_step_index! + if step_index + @hash[:step_index] += 1 + else + @hash[:step_index] = 0 + end + end + end + class NestedStep def initialize(value) @hash = value @@ -69,12 +103,22 @@ def next_step end if step.is_a?(Hash) - nested_step = NestedStep.new(step) - if nested_step.over_end_at? - steps.shift # NestedStepを破棄する - return next_step + if step[:continue_for] + nested_step = NestedStep.new(step) + if nested_step.over_end_at? + steps.shift # NestedStepを破棄する + return next_step + else + return nested_step.next_step + end else - return nested_step.next_step + nested_step = OnetimeNestedStep.new(step) + if nested_step.over? + steps.shift # NestedStepを破棄する + return next_step + else + return nested_step.next_step + end end end end diff --git a/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb b/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb index ddf75cc8..dc1ce3d3 100644 --- a/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb +++ b/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb @@ -41,14 +41,14 @@ describe 'toggle_x_for_2sec' do it do expect(described_class.new([:toggle_r_for_2sec]).build).to eq( - [{ continue_for: 2, steps: [:r, :none] }] + [{ continue_for: 2, steps: [:none, :r] }] ) end it do expect(described_class.new([:toggle_r, :toggle_r_for_3sec]).build).to eq( [ :r, :none, - { continue_for: 3, steps: [:r, :none] } + { continue_for: 3, steps: [:none, :r] } ] ) end @@ -57,14 +57,14 @@ describe 'toggle_x_for_0_2sec' do it do expect(described_class.new([:toggle_r_for_0_2sec]).build).to eq( - [{ continue_for: 0.2, steps: [:r, :none] }] + [{ continue_for: 0.2, steps: [:none,:r] }] ) end it do expect(described_class.new([:toggle_r, :toggle_r_for_0_3sec]).build).to eq( [ :r, :none, - { continue_for: 0.3, steps: [:r, :none] } + { continue_for: 0.3, steps: [:none, :r] } ] ) end @@ -98,8 +98,8 @@ it do expect(described_class.new([:pressing_r_and_toggle_zr]).build).to eq( [{ continue_for: nil, steps: [ - [:r, :zr], [:r, :none], + [:r, :zr], ] }] ) end @@ -109,8 +109,8 @@ it do expect(described_class.new([:pressing_x_and_toggle_zr_for_0_2sec]).build).to eq( [{ continue_for: 0.2, steps: [ - [:x, :zr], [:x, :none], + [:x, :zr], ] }] ) end @@ -120,8 +120,8 @@ it do expect(described_class.new([:pressing_x_and_toggle_zr_for_0_2sec]).build).to eq( [{ continue_for: 0.2, steps: [ - [:x, :zr], [:x, :none], + [:x, :zr], ] }] ) end @@ -131,8 +131,8 @@ it do expect(described_class.new([:toggle_x_and_toggle_zr_for_0_2sec]).build).to eq( [{ continue_for: 0.2, steps: [ - [:x, :zr], [:none, :none], + [:x, :zr], ] }] ) end @@ -153,8 +153,8 @@ it do expect(described_class.new([:pressing_thumbr_and_toggle_zr_for_0_6sec]).build).to eq( [{ continue_for: 0.6, steps: [ - [:thumbr, :zr], [:thumbr, :none], + [:thumbr, :zr], ] }] ) end @@ -164,8 +164,8 @@ it do expect(described_class.new([:pressing_zr_and_toggle_b_for_0_6sec]).build).to eq( [{ continue_for: 0.6, steps: [ - [:zr, :b], [:zr, :none], + [:zr, :b], ] }] ) end @@ -175,8 +175,8 @@ it do expect(described_class.new([:pressing_zr_and_toggle_b_for_0_65sec]).build).to eq( [{ continue_for: 0.65, steps: [ - [:zr, :b], [:zr, :none], + [:zr, :b], ] }] ) end @@ -184,8 +184,8 @@ it do expect(described_class.new([:pressing_zr_and_toggle_b_for_0_65]).build).to eq( [{ continue_for: 0.65, steps: [ - [:zr, :b], [:zr, :none], + [:zr, :b], ] }] ) end diff --git a/spec/lib/procon_bypass_man/procon/macro_spec.rb b/spec/lib/procon_bypass_man/procon/macro_spec.rb index 73845bcb..2ef8327f 100644 --- a/spec/lib/procon_bypass_man/procon/macro_spec.rb +++ b/spec/lib/procon_bypass_man/procon/macro_spec.rb @@ -80,6 +80,24 @@ end end + context 'nested_stepのみ(continue_forがnil)' do + let(:nested_step) { + { continue_for: nil, steps: [:r, :none], } + } + it do + macro = described_class.new(name: nil, steps: [nested_step]) + Timecop.freeze '2021-11-11 00:00:00' do + expect(macro.next_step).to eq(:r) + expect(macro.next_step).to eq(:none) + expect(macro.next_step).to eq(nil) + end + + Timecop.freeze '2021-11-11 00:00:05' do + expect(macro.next_step).to eq(nil) + end + end + end + context 'nested_stepが続くとき' do let(:nested_step) { { continue_for: 3, steps: [:r, :none], } diff --git a/spec/lib/procon_bypass_man/procon_spec.rb b/spec/lib/procon_bypass_man/procon_spec.rb index 6201e532..201ac934 100644 --- a/spec/lib/procon_bypass_man/procon_spec.rb +++ b/spec/lib/procon_bypass_man/procon_spec.rb @@ -233,7 +233,7 @@ def self.steps end it do expect(ProconBypassMan::Procon::MacroRegistry.plugins[:multi].call).to eq( - [{:continue_for=>2, :steps=>[[:thumbr, :zr], [:thumbr, :none]]}, :a] + [{:continue_for=>2, :steps=>[[:thumbr, :none], [:thumbr, :zr]]}, :a] ) procon = ProconBypassMan::Procon.new(binary) @@ -243,17 +243,17 @@ def self.steps procon = ProconBypassMan::Procon.new(procon.to_binary) expect(procon.pressed_thumbr?).to eq(true) - expect(procon.pressed_zr?).to eq(true) + expect(procon.pressed_zr?).to eq(false) procon.apply! procon = ProconBypassMan::Procon.new(procon.to_binary) expect(procon.pressed_thumbr?).to eq(true) - expect(procon.pressed_zr?).to eq(false) + expect(procon.pressed_zr?).to eq(true) procon.apply! procon = ProconBypassMan::Procon.new(procon.to_binary) expect(procon.pressed_thumbr?).to eq(true) - expect(procon.pressed_zr?).to eq(true) + expect(procon.pressed_zr?).to eq(false) procon.apply! end end From 5f31c2d2dfd8b1da892c9a98a8439da6c11d1666 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:18:06 +0900 Subject: [PATCH 21/44] =?UTF-8?q?=E5=88=A4=E5=AE=9A=E3=81=8C=E6=8A=9C?= =?UTF-8?q?=E3=81=91=E3=81=A6=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/procon.rb | 6 +++--- lib/procon_bypass_man/support/time_scoped_map.rb | 4 ++-- spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index a085b5c9..15369bd5 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -53,9 +53,9 @@ def apply! reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) - rotated = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) - if user_operation.pressing_all_buttons?(options[:if_pressed]) && rotated - ProconBypassMan.logger.info(rotated) + rotated_result = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) + if user_operation.pressing_all_buttons?(options[:if_pressed]) && ProconBypassMan::TiltingStickAware.tilting?(rotated_result[:list]) + ProconBypassMan.logger.info(rotated_result[:list]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) end next diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb index 04b6a34c..082f68de 100644 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ b/lib/procon_bypass_man/support/time_scoped_map.rb @@ -5,7 +5,7 @@ def initialize end def add(value, &block) - rotated = false + rotated = nil current_key = key if @map[current_key].nil? rotate @@ -13,7 +13,7 @@ def add(value, &block) if block_given? block.call(result) end - rotated = true + rotated = result end @map = { current_key => [] } end diff --git a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb index 89ac0632..3b83d073 100644 --- a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb +++ b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb @@ -13,12 +13,12 @@ it do map = ProconBypassMan::TimeScopedMap.new Timecop.freeze do - expect(map.add 1).to eq(false) - expect(map.add 2).to eq(false) + expect(map.add 1).to eq(nil) + expect(map.add 2).to eq(nil) end Timecop.freeze(Time.now + 1) do - expect(map.add 1).to eq(true) + expect(map.add 1).to be_a(Hash) expect(map.result).to eq({ list: [1, 2] }) end end From 66ac4ae31fad076004bfda5a66b9f44ca6317804 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:20:49 +0900 Subject: [PATCH 22/44] ooooops --- lib/procon_bypass_man/procon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 15369bd5..94676a71 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -54,7 +54,7 @@ def apply! hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) rotated_result = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) - if user_operation.pressing_all_buttons?(options[:if_pressed]) && ProconBypassMan::TiltingStickAware.tilting?(rotated_result[:list]) + if user_operation.pressing_all_buttons?(options[:if_pressed]) && rotated_result && ProconBypassMan::TiltingStickAware.tilting?(rotated_result[:list]) ProconBypassMan.logger.info(rotated_result[:list]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) end From e2a6db9005d12909760f9e593ec3927142ad6f1e Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:30:02 +0900 Subject: [PATCH 23/44] oooooops --- lib/procon_bypass_man/procon.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 94676a71..1f6292ab 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -47,18 +47,19 @@ def apply! return end + reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader + hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) + rotated_result = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) + if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| - if options[:if_tilted_left_stick] - reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader - hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) - - rotated_result = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) - if user_operation.pressing_all_buttons?(options[:if_pressed]) && rotated_result && ProconBypassMan::TiltingStickAware.tilting?(rotated_result[:list]) - ProconBypassMan.logger.info(rotated_result[:list]) + if options[:if_tilted_left_stick] && rotated_result + moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power + ProconBypassMan.logger.info "moving: #{moving_power}" + if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) + next end - next end if user_operation.pressing_all_buttons?(options[:if_pressed]) From 3c6194212be0594d7889172a0b4f142c21e21a09 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:36:58 +0900 Subject: [PATCH 24/44] logru --- lib/procon_bypass_man/procon.rb | 1 + lib/procon_bypass_man/procon/tilting_stick_aware.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 1f6292ab..59ee2e6d 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -53,6 +53,7 @@ def apply! if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| + ProconBypassMan.logger.info "DDDDDDDD: #{options[:if_tilted_left_stick]} && #{rotated_result}" if options[:if_tilted_left_stick] && rotated_result moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power ProconBypassMan.logger.info "moving: #{moving_power}" diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb index 3318d6c2..0f1a2b7e 100644 --- a/lib/procon_bypass_man/procon/tilting_stick_aware.rb +++ b/lib/procon_bypass_man/procon/tilting_stick_aware.rb @@ -1,6 +1,6 @@ class ProconBypassMan::TiltingStickAware def self.tilting?(result) - return false if result.nil? + return false if !result if (-200..200).include?(result[:min][:x]) && (-200..200).include?(result[:min][:y]) return false end From 0c18863ed33c43ae11185cdb64a1bad53d8abe4f Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:42:07 +0900 Subject: [PATCH 25/44] wakaran --- lib/procon_bypass_man/procon.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 59ee2e6d..388d946c 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -53,8 +53,7 @@ def apply! if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| - ProconBypassMan.logger.info "DDDDDDDD: #{options[:if_tilted_left_stick]} && #{rotated_result}" - if options[:if_tilted_left_stick] && rotated_result + if options[:if_tilted_left_stick] && !!rotated_result moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power ProconBypassMan.logger.info "moving: #{moving_power}" if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) From be048cd29b0a2480f707310277e9ae3ea8d4c346 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:48:45 +0900 Subject: [PATCH 26/44] log --- lib/procon_bypass_man/procon.rb | 3 ++- .../procon_bypass_man/procon/tilting_stick_aware_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 388d946c..32b0428d 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -57,8 +57,9 @@ def apply! moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power ProconBypassMan.logger.info "moving: #{moving_power}" if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) + ProconBypassMan.logger.info "if_tilted_left_stick!!!!!!!!!!!!!" @@status[:ongoing_macro] = MacroRegistry.load(macro_name) - next + break end end diff --git a/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb b/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb index 01426f55..b73d983b 100644 --- a/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb +++ b/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb @@ -14,4 +14,11 @@ expect(described_class.tilting?(report)).to eq(false) end end + + context '止まっている' do + it do + report = {:power=>1.4043980000000005, :max=>{:x=>83, :y=>13}, :min=>{:x=>82, :y=>10}} + expect(described_class.tilting?(report)).to eq(false) + end + end end From 1171b851e7807f7b4703458ce04f8c6b96e9578b Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:53:53 +0900 Subject: [PATCH 27/44] ooooooooooooops --- lib/procon_bypass_man/procon.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 32b0428d..457bf0de 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -61,6 +61,8 @@ def apply! @@status[:ongoing_macro] = MacroRegistry.load(macro_name) break end + + next end if user_operation.pressing_all_buttons?(options[:if_pressed]) From ca57ea1215c58a8f04f2efe7ec68860c43abda48 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 20:57:34 +0900 Subject: [PATCH 28/44] aaaaaaaaaaa --- lib/procon_bypass_man/procon.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 457bf0de..ac0d9b2d 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -53,7 +53,8 @@ def apply! if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| - if options[:if_tilted_left_stick] && !!rotated_result + if options[:if_tilted_left_stick] + next unless rotated_result moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power ProconBypassMan.logger.info "moving: #{moving_power}" if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) From 7fc03a986fd924bd7704abded1889b20db4c25ca Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 21:14:16 +0900 Subject: [PATCH 29/44] add test --- lib/procon_bypass_man/procon.rb | 1 - .../buttons_setting_configuration_spec.rb | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index ac0d9b2d..f4e8d8ea 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -56,7 +56,6 @@ def apply! if options[:if_tilted_left_stick] next unless rotated_result moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power - ProconBypassMan.logger.info "moving: #{moving_power}" if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) ProconBypassMan.logger.info "if_tilted_left_stick!!!!!!!!!!!!!" @@status[:ongoing_macro] = MacroRegistry.load(macro_name) 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 8c8e1ae8..2665c2df 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -522,6 +522,19 @@ def self.steps; [:a, :b]; end ) end context 'with if_tilted_left_stick' do + it do + ProconBypassMan.buttons_setting_configure do + layer :up do + open_macro :dacan, steps: [:pressing_r_for_0_3sec, :pressing_r_and_toggle_zl], if_tilted_left_stick: true, if_pressed: [:zr] + end + end + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq( + [{:continue_for=>0.3, :steps=>[:r, :r]}, {:continue_for=>nil, :steps=>[[:r, :none], [:r, :zl]]}] + ) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } + ) + end it do ProconBypassMan.buttons_setting_configure do layer :up do From 3eb809ff0f52ca5706cdc3bb1d6f6f9a61b3f956 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 21:37:03 +0900 Subject: [PATCH 30/44] =?UTF-8?q?=E9=96=BE=E5=80=A4=E3=82=92=E4=B8=8B?= =?UTF-8?q?=E3=81=92=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/procon/tilting_stick_aware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb index 0f1a2b7e..4dee4648 100644 --- a/lib/procon_bypass_man/procon/tilting_stick_aware.rb +++ b/lib/procon_bypass_man/procon/tilting_stick_aware.rb @@ -5,6 +5,6 @@ def self.tilting?(result) return false end - result[:power] > 500 + result[:power] > 300 end end From 33aaa931eb1bc1d640d0e537d3985a641a141c44 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 21:38:35 +0900 Subject: [PATCH 31/44] log --- lib/procon_bypass_man/procon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index f4e8d8ea..bd009fb5 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -56,8 +56,8 @@ def apply! if options[:if_tilted_left_stick] next unless rotated_result moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power + ProconBypassMan.logger.info "moving_power: #{moving_power}" if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) - ProconBypassMan.logger.info "if_tilted_left_stick!!!!!!!!!!!!!" @@status[:ongoing_macro] = MacroRegistry.load(macro_name) break end From e5df805cb62480054d8a3484062afe00fc1041f0 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 24 Feb 2022 21:45:11 +0900 Subject: [PATCH 32/44] commentout --- lib/procon_bypass_man/procon/tilting_stick_aware.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb index 4dee4648..d333a7e0 100644 --- a/lib/procon_bypass_man/procon/tilting_stick_aware.rb +++ b/lib/procon_bypass_man/procon/tilting_stick_aware.rb @@ -1,9 +1,9 @@ class ProconBypassMan::TiltingStickAware def self.tilting?(result) return false if !result - if (-200..200).include?(result[:min][:x]) && (-200..200).include?(result[:min][:y]) - return false - end + # if (-200..200).include?(result[:min][:x]) && (-200..200).include?(result[:min][:y]) + # return false + # end result[:power] > 300 end From 99dd35447f0b85ae523585875ba10195b6bfa41e Mon Sep 17 00:00:00 2001 From: jiikko Date: Fri, 25 Feb 2022 21:27:56 +0900 Subject: [PATCH 33/44] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man.rb | 3 +- lib/procon_bypass_man/procon.rb | 14 +++--- .../procon/stick_positions_list.rb | 11 ----- .../procon/tilting_stick_aware.rb | 13 ++--- .../procon/value_objects/analog_stick.rb | 14 ++++-- .../analog_stick_hypotenuse_summarizer.rb | 47 +++++++++++++++++++ .../support/time_scoped_map.rb | 41 ---------------- .../procon/tilting_stick_aware_spec.rb | 41 ++++++++++------ ...analog_stick_hypotenuse_summarizer_spec.rb | 16 +++++++ .../support/time_scoped_map_spec.rb | 38 --------------- 10 files changed, 113 insertions(+), 125 deletions(-) delete mode 100644 lib/procon_bypass_man/procon/stick_positions_list.rb create mode 100644 lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb delete mode 100644 lib/procon_bypass_man/support/time_scoped_map.rb create mode 100644 spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb delete mode 100644 spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 6e589ed5..09e9b82f 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -25,7 +25,7 @@ require_relative "procon_bypass_man/support/update_remote_pbm_action_status_http_client" require_relative "procon_bypass_man/support/send_device_stats_http_client" require_relative "procon_bypass_man/support/server_pool" -require_relative "procon_bypass_man/support/time_scoped_map" +require_relative "procon_bypass_man/support/analog_stick_hypotenuse_summarizer" require_relative "procon_bypass_man/background" require_relative "procon_bypass_man/commands" require_relative "procon_bypass_man/bypass" @@ -44,7 +44,6 @@ require_relative "procon_bypass_man/procon/value_objects/analog_stick" require_relative "procon_bypass_man/procon/value_objects/procon_reader" require_relative "procon_bypass_man/procon/analog_stick_cap" -require_relative "procon_bypass_man/procon/stick_positions_list" require_relative "procon_bypass_man/procon/tilting_stick_aware" require_relative "procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object" require_relative "procon_bypass_man/scheduler" diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index bd009fb5..ec6d3d51 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -19,7 +19,7 @@ def self.reset! ongoing_macro: MacroRegistry.load(:null), ongoing_mode: ModeRegistry.load(:manual), } - @@left_stick_report_map = ProconBypassMan::TimeScopedMap.new + @@left_stick_hypotenuse_summarizer = ProconBypassMan::AnalogStickHypotenuseSummarizer.new end reset! @@ -47,17 +47,15 @@ def apply! return end - reader = ProconBypassMan::Domains::InboundProconBinary.new(binary: user_operation.binary.raw.dup).to_procon_reader - hypotenuse = Math.sqrt((reader.left_analog_stick[:x]**2) + (reader.left_analog_stick[:y]**2)).floor(6) - rotated_result = @@left_stick_report_map.add({ relative: reader.left_analog_stick, hypotenuse: hypotenuse }) + analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: user_operation.binary.raw) + summarizable_chunk = @@left_stick_hypotenuse_summarizer.add({ hypotenuse: analog_stick.relative_hypotenuse }) if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| if options[:if_tilted_left_stick] - next unless rotated_result - moving_power = ProconBypassMan::StickPositionsList.new(rotated_result[:list]).moving_power - ProconBypassMan.logger.info "moving_power: #{moving_power}" - if ProconBypassMan::TiltingStickAware.tilting?(moving_power) && user_operation.pressing_all_buttons?(options[:if_pressed]) + next unless summarizable_chunk + ProconBypassMan.logger.info "moving_power: #{summarizable_chunk.moving_power}, current_position_x,y: [#{analog_stick.relative_x}, #{analog_stick.relative_y}]" + if ProconBypassMan::TiltingStickAware.tilting?(summarizable_chunk.moving_power, current_position_x: analog_stick.relative_x, current_position_y: analog_stick.relative_y) && user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) break end diff --git a/lib/procon_bypass_man/procon/stick_positions_list.rb b/lib/procon_bypass_man/procon/stick_positions_list.rb deleted file mode 100644 index 695378d8..00000000 --- a/lib/procon_bypass_man/procon/stick_positions_list.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ProconBypassMan::StickPositionsList - def initialize(list) - @list = list - end - - def moving_power - max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } - min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } - { power: (max[:hypotenuse] - min[:hypotenuse]).abs, max: max[:relative], min: min[:relative] } - end -end diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb index d333a7e0..28387211 100644 --- a/lib/procon_bypass_man/procon/tilting_stick_aware.rb +++ b/lib/procon_bypass_man/procon/tilting_stick_aware.rb @@ -1,10 +1,11 @@ class ProconBypassMan::TiltingStickAware - def self.tilting?(result) - return false if !result - # if (-200..200).include?(result[:min][:x]) && (-200..200).include?(result[:min][:y]) - # return false - # end + def self.tilting?(moving_power, current_position_x: , current_position_y: ) + return false if !moving_power + # スティックがニュートラルな時 + if (-200..200).include?(current_position_x) && (-200..200).include?(current_position_y) + return false + end - result[:power] > 300 + moving_power > 300 end end diff --git a/lib/procon_bypass_man/procon/value_objects/analog_stick.rb b/lib/procon_bypass_man/procon/value_objects/analog_stick.rb index 94fcb553..2c8adfe8 100644 --- a/lib/procon_bypass_man/procon/value_objects/analog_stick.rb +++ b/lib/procon_bypass_man/procon/value_objects/analog_stick.rb @@ -1,6 +1,6 @@ class ProconBypassMan::Procon::AnalogStick attr_accessor :neutral_position - attr_accessor :bin_x, :bin_y + attr_writer :bin_x, :bin_y def initialize(binary: ) @neutral_position = ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position @@ -13,18 +13,22 @@ def initialize(binary: ) end def abs_x - bin_x.to_i(2) + @bin_x.to_i(2) end def abs_y - bin_y.to_i(2) + @bin_y.to_i(2) end def relative_x - bin_x.to_i(2) - neutral_position.x + @bin_x.to_i(2) - neutral_position.x end def relative_y - bin_y.to_i(2) - neutral_position.y + @bin_y.to_i(2) - neutral_position.y + end + + def relative_hypotenuse + Math.sqrt((relative_x**2) + (relative_y**2)).floor(6) end end diff --git a/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb b/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb new file mode 100644 index 00000000..044cca91 --- /dev/null +++ b/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb @@ -0,0 +1,47 @@ +class ProconBypassMan::AnalogStickHypotenuseSummarizer + class SummarizableChunk + def initialize(list) + @list = list + end + + def moving_power + max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } + moving_power = (max[:hypotenuse] - min[:hypotenuse]).abs + end + end + + def initialize + @map = {} + end + + def add(value, &block) + rotated = nil + current_key = key + if @map[current_key].nil? + rotated = rotate + @map = { current_key => [] } # renew or initialize + end + + @map[current_key] << value + rotated + end + + private + + # 0.1sec刻みで進行する + def key + time = Time.now + m1 = time.strftime('%L')[0] + [time.to_i, m1].join.to_i + end + + def rotate + list = @map.values.first + if list + return SummarizableChunk.new(list) + else + return nil + end + end +end diff --git a/lib/procon_bypass_man/support/time_scoped_map.rb b/lib/procon_bypass_man/support/time_scoped_map.rb deleted file mode 100644 index 082f68de..00000000 --- a/lib/procon_bypass_man/support/time_scoped_map.rb +++ /dev/null @@ -1,41 +0,0 @@ -class ProconBypassMan::TimeScopedMap - def initialize - @map = {} - @result = nil - end - - def add(value, &block) - rotated = nil - current_key = key - if @map[current_key].nil? - rotate - if result[:list] - if block_given? - block.call(result) - end - rotated = result - end - @map = { current_key => [] } - end - - @map[current_key] << value - rotated - end - - def result - @result || {} - end - - private - - # 0.1sec刻みで進行する - def key - time = Time.now - m1 = time.strftime('%L')[0] - [time.to_i, m1].join.to_i - end - - def rotate - @result = { list: @map.values.first } - end -end diff --git a/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb b/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb index b73d983b..b5bff17d 100644 --- a/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb +++ b/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb @@ -1,24 +1,37 @@ require "spec_helper" describe ProconBypassMan::TiltingStickAware do - context 'スティックを傾けるとき' do - it do - report = {:power=>668.242084, :max=>{:x=>-1398, :y=>-365}, :min=>{:x=>-752, :y=>-194}} - expect(described_class.tilting?(report)).to eq(true) + describe '.tilting?' do + subject { described_class.tilting?(power, current_position_x: current_position_x, current_position_y: current_position_y) } + + context 'スティックを傾けるとき' do + let(:power) { 500 } + let(:current_position_x) { 1000 } + let(:current_position_y) { 1000 } + + it do + expect(subject).to eq(true) + end end - end - context 'スティックを戻すとき' do - it do - report = {:power=>1069.9772189999999, :max=>{:x=>-1025, :y=>-464}, :min=>{:x=>-21, :y=>-51}} - expect(described_class.tilting?(report)).to eq(false) + context 'スティックを戻すとき' do + let(:power) { 1000 } + let(:current_position_x) { 10 } + let(:current_position_y) { 10 } + + it do + expect(subject).to eq(false) + end end - end - context '止まっている' do - it do - report = {:power=>1.4043980000000005, :max=>{:x=>83, :y=>13}, :min=>{:x=>82, :y=>10}} - expect(described_class.tilting?(report)).to eq(false) + context '止まっている' do + let(:power) { 100 } + let(:current_position_x) { 10 } + let(:current_position_y) { 10 } + + it do + expect(subject).to eq(false) + end end end end diff --git a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb new file mode 100644 index 00000000..238f3f3c --- /dev/null +++ b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb @@ -0,0 +1,16 @@ +require "spec_helper" + +describe ProconBypassMan::AnalogStickHypotenuseSummarizer do + it do + map = described_class.new + Timecop.freeze do + expect(map.add({ hypotenuse: 5 })).to eq(nil) + expect(map.add({ hypotenuse: 10 })).to eq(nil) + end + + Timecop.freeze(Time.now + 1) do + actual = map.add({ hypotenuse: 3 }) + expect(actual.moving_power).to eq(5) + end + end +end diff --git a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb b/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb deleted file mode 100644 index 3b83d073..00000000 --- a/spec/lib/procon_bypass_man/support/time_scoped_map_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require "spec_helper" - -describe ProconBypassMan::TimeScopedMap do - it do - map = ProconBypassMan::TimeScopedMap.new - Timecop.freeze do - map.add 1 - map.add 2 - expect(map.result).to eq({ list: nil }) - end - end - - it do - map = ProconBypassMan::TimeScopedMap.new - Timecop.freeze do - expect(map.add 1).to eq(nil) - expect(map.add 2).to eq(nil) - end - - Timecop.freeze(Time.now + 1) do - expect(map.add 1).to be_a(Hash) - expect(map.result).to eq({ list: [1, 2] }) - end - end - - it do - map = ProconBypassMan::TimeScopedMap.new - Timecop.freeze do - map.add(1) { raise "do not call" } - map.add(2) { raise "do not call" } - end - - Timecop.freeze(Time.now + 1) do - map.add(1) { |result| expect(result).to eq({ list: [1, 2] }) } - expect(map.result).to eq({ list: [1, 2] }) - end - end -end From e4e98c4427a520df4b4591f966d021e18dc8b58c Mon Sep 17 00:00:00 2001 From: jiikko Date: Fri, 25 Feb 2022 21:53:54 +0900 Subject: [PATCH 34/44] simple --- lib/procon_bypass_man/procon.rb | 4 ++-- .../support/analog_stick_hypotenuse_summarizer.rb | 9 +++++---- .../support/analog_stick_hypotenuse_summarizer_spec.rb | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index ec6d3d51..a37fd80e 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -48,13 +48,13 @@ def apply! end analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: user_operation.binary.raw) - summarizable_chunk = @@left_stick_hypotenuse_summarizer.add({ hypotenuse: analog_stick.relative_hypotenuse }) + summarizable_chunk = @@left_stick_hypotenuse_summarizer.add(analog_stick.relative_hypotenuse) if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| if options[:if_tilted_left_stick] next unless summarizable_chunk - ProconBypassMan.logger.info "moving_power: #{summarizable_chunk.moving_power}, current_position_x,y: [#{analog_stick.relative_x}, #{analog_stick.relative_y}]" + # ProconBypassMan.logger.info "moving_power: #{summarizable_chunk.moving_power}, current_position_x,y: [#{analog_stick.relative_x}, #{analog_stick.relative_y}]" if ProconBypassMan::TiltingStickAware.tilting?(summarizable_chunk.moving_power, current_position_x: analog_stick.relative_x, current_position_y: analog_stick.relative_y) && user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) break diff --git a/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb b/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb index 044cca91..a41f7cc2 100644 --- a/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb +++ b/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb @@ -5,9 +5,9 @@ def initialize(list) end def moving_power - max = @list.max {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } - min = @list.min {|a, b| a[:hypotenuse] <=> b[:hypotenuse] } - moving_power = (max[:hypotenuse] - min[:hypotenuse]).abs + max = @list.max + min = @list.min + moving_power = (max - min).abs end end @@ -15,7 +15,8 @@ def initialize @map = {} end - def add(value, &block) + # @return [NilClass, SummarizableChunk] ローテトしたらvalueを返す + def add(value) rotated = nil current_key = key if @map[current_key].nil? diff --git a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb index 238f3f3c..9498671b 100644 --- a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb +++ b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb @@ -4,12 +4,12 @@ it do map = described_class.new Timecop.freeze do - expect(map.add({ hypotenuse: 5 })).to eq(nil) - expect(map.add({ hypotenuse: 10 })).to eq(nil) + expect(map.add(5)).to eq(nil) + expect(map.add(10)).to eq(nil) end Timecop.freeze(Time.now + 1) do - actual = map.add({ hypotenuse: 3 }) + actual = map.add(3) expect(actual.moving_power).to eq(5) end end From be99824ef0b259d3550f13aca03cf810913bca16 Mon Sep 17 00:00:00 2001 From: jiikko Date: Fri, 25 Feb 2022 22:16:21 +0900 Subject: [PATCH 35/44] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0=EF=BC=88=E3=83=AA=E3=83=8D?= =?UTF-8?q?=E3=83=BC=E3=83=A0=E3=81=A8=E3=81=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man.rb | 3 +- lib/procon_bypass_man/procon.rb | 8 +-- .../procon/tilting_stick_aware.rb | 11 ---- ..._stick_hypotenuse_tilting_power_scaler.rb} | 19 ++++-- .../procon/tilting_stick_aware_spec.rb | 37 ------------ ...analog_stick_hypotenuse_summarizer_spec.rb | 16 ----- ...ck_hypotenuse_tilting_power_scaler_spec.rb | 58 +++++++++++++++++++ 7 files changed, 76 insertions(+), 76 deletions(-) delete mode 100644 lib/procon_bypass_man/procon/tilting_stick_aware.rb rename lib/procon_bypass_man/support/{analog_stick_hypotenuse_summarizer.rb => analog_stick_hypotenuse_tilting_power_scaler.rb} (58%) delete mode 100644 spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb delete mode 100644 spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb create mode 100644 spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb diff --git a/lib/procon_bypass_man.rb b/lib/procon_bypass_man.rb index 09e9b82f..d834df38 100644 --- a/lib/procon_bypass_man.rb +++ b/lib/procon_bypass_man.rb @@ -25,7 +25,7 @@ require_relative "procon_bypass_man/support/update_remote_pbm_action_status_http_client" require_relative "procon_bypass_man/support/send_device_stats_http_client" require_relative "procon_bypass_man/support/server_pool" -require_relative "procon_bypass_man/support/analog_stick_hypotenuse_summarizer" +require_relative "procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler" require_relative "procon_bypass_man/background" require_relative "procon_bypass_man/commands" require_relative "procon_bypass_man/bypass" @@ -44,7 +44,6 @@ require_relative "procon_bypass_man/procon/value_objects/analog_stick" require_relative "procon_bypass_man/procon/value_objects/procon_reader" require_relative "procon_bypass_man/procon/analog_stick_cap" -require_relative "procon_bypass_man/procon/tilting_stick_aware" require_relative "procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object" require_relative "procon_bypass_man/scheduler" require_relative "procon_bypass_man/plugins" diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index a37fd80e..c215873f 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -19,7 +19,7 @@ def self.reset! ongoing_macro: MacroRegistry.load(:null), ongoing_mode: ModeRegistry.load(:manual), } - @@left_stick_hypotenuse_summarizer = ProconBypassMan::AnalogStickHypotenuseSummarizer.new + @@left_stick_tilting_power_scaler = ProconBypassMan::AnalogStickTiltingPowerScaler.new end reset! @@ -48,14 +48,12 @@ def apply! end analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: user_operation.binary.raw) - summarizable_chunk = @@left_stick_hypotenuse_summarizer.add(analog_stick.relative_hypotenuse) + dumped_tilting_power = @@left_stick_tilting_power_scaler.add_sample(analog_stick.relative_hypotenuse) if ongoing_macro.finished? current_layer.macros.each do |macro_name, options| if options[:if_tilted_left_stick] - next unless summarizable_chunk - # ProconBypassMan.logger.info "moving_power: #{summarizable_chunk.moving_power}, current_position_x,y: [#{analog_stick.relative_x}, #{analog_stick.relative_y}]" - if ProconBypassMan::TiltingStickAware.tilting?(summarizable_chunk.moving_power, current_position_x: analog_stick.relative_x, current_position_y: analog_stick.relative_y) && user_operation.pressing_all_buttons?(options[:if_pressed]) + if dumped_tilting_power&.tilting?(current_position_x: analog_stick.relative_x, current_position_y: analog_stick.relative_y) && user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) break end diff --git a/lib/procon_bypass_man/procon/tilting_stick_aware.rb b/lib/procon_bypass_man/procon/tilting_stick_aware.rb deleted file mode 100644 index 28387211..00000000 --- a/lib/procon_bypass_man/procon/tilting_stick_aware.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ProconBypassMan::TiltingStickAware - def self.tilting?(moving_power, current_position_x: , current_position_y: ) - return false if !moving_power - # スティックがニュートラルな時 - if (-200..200).include?(current_position_x) && (-200..200).include?(current_position_y) - return false - end - - moving_power > 300 - end -end diff --git a/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb b/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb similarity index 58% rename from lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb rename to lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb index a41f7cc2..c3b1ad99 100644 --- a/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer.rb +++ b/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb @@ -1,5 +1,5 @@ -class ProconBypassMan::AnalogStickHypotenuseSummarizer - class SummarizableChunk +class ProconBypassMan::AnalogStickTiltingPowerScaler + class PowerChunk def initialize(list) @list = list end @@ -9,14 +9,23 @@ def moving_power min = @list.min moving_power = (max - min).abs end + + def tilting?(current_position_x: , current_position_y: ) + # スティックがニュートラルな時 + if (-200..200).include?(current_position_x) && (-200..200).include?(current_position_y) + return false + end + + moving_power > 300 + end end def initialize @map = {} end - # @return [NilClass, SummarizableChunk] ローテトしたらvalueを返す - def add(value) + # @return [NilClass, Chunk] ローテトしたらvalueを返す + def add_sample(value) rotated = nil current_key = key if @map[current_key].nil? @@ -40,7 +49,7 @@ def key def rotate list = @map.values.first if list - return SummarizableChunk.new(list) + return PowerChunk.new(list) else return nil end diff --git a/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb b/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb deleted file mode 100644 index b5bff17d..00000000 --- a/spec/lib/procon_bypass_man/procon/tilting_stick_aware_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "spec_helper" - -describe ProconBypassMan::TiltingStickAware do - describe '.tilting?' do - subject { described_class.tilting?(power, current_position_x: current_position_x, current_position_y: current_position_y) } - - context 'スティックを傾けるとき' do - let(:power) { 500 } - let(:current_position_x) { 1000 } - let(:current_position_y) { 1000 } - - it do - expect(subject).to eq(true) - end - end - - context 'スティックを戻すとき' do - let(:power) { 1000 } - let(:current_position_x) { 10 } - let(:current_position_y) { 10 } - - it do - expect(subject).to eq(false) - end - end - - context '止まっている' do - let(:power) { 100 } - let(:current_position_x) { 10 } - let(:current_position_y) { 10 } - - it do - expect(subject).to eq(false) - end - end - end -end diff --git a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb deleted file mode 100644 index 9498671b..00000000 --- a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_summarizer_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require "spec_helper" - -describe ProconBypassMan::AnalogStickHypotenuseSummarizer do - it do - map = described_class.new - Timecop.freeze do - expect(map.add(5)).to eq(nil) - expect(map.add(10)).to eq(nil) - end - - Timecop.freeze(Time.now + 1) do - actual = map.add(3) - expect(actual.moving_power).to eq(5) - end - end -end diff --git a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb new file mode 100644 index 00000000..86d6baa5 --- /dev/null +++ b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb @@ -0,0 +1,58 @@ +require "spec_helper" + +describe ProconBypassMan::AnalogStickTiltingPowerScaler do + describe ProconBypassMan::AnalogStickTiltingPowerScaler::PowerChunk do + describe '.tilting?' do + let(:instance) { described_class.new(nil) } + + subject { instance.tilting?(current_position_x: current_position_x, current_position_y: current_position_y) } + + before do + allow(instance).to receive(:moving_power) { power } + end + + context 'スティックを傾けるとき' do + let(:power) { 500 } + let(:current_position_x) { 1000 } + let(:current_position_y) { 1000 } + + it do + expect(subject).to eq(true) + end + end + + context 'スティックを戻すとき' do + let(:power) { 1000 } + let(:current_position_x) { 10 } + let(:current_position_y) { 10 } + + it do + expect(subject).to eq(false) + end + end + + context '止まっている' do + let(:power) { 100 } + let(:current_position_x) { 10 } + let(:current_position_y) { 10 } + + it do + expect(subject).to eq(false) + end + end + end + end + + it do + map = described_class.new + Timecop.freeze do + expect(map.add_sample(5)).to eq(nil) + expect(map.add_sample(10)).to eq(nil) + end + + Timecop.freeze(Time.now + 1) do + actual = map.add_sample(3) + expect(actual.moving_power).to eq(5) + end + end +end From e5f870588f4254f138773fead41a43817c11ce89 Mon Sep 17 00:00:00 2001 From: jiikko Date: Fri, 25 Feb 2022 23:37:45 +0900 Subject: [PATCH 36/44] =?UTF-8?q?=E9=96=BE=E5=80=A4=E3=82=92=E4=B8=8A?= =?UTF-8?q?=E3=81=92=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/analog_stick_hypotenuse_tilting_power_scaler.rb | 2 +- .../analog_stick_hypotenuse_tilting_power_scaler_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb b/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb index c3b1ad99..f5908c11 100644 --- a/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb +++ b/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb @@ -16,7 +16,7 @@ def tilting?(current_position_x: , current_position_y: ) return false end - moving_power > 300 + moving_power > 500 end end diff --git a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb index 86d6baa5..42e35c9e 100644 --- a/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb +++ b/spec/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler_spec.rb @@ -12,7 +12,7 @@ end context 'スティックを傾けるとき' do - let(:power) { 500 } + let(:power) { 600 } let(:current_position_x) { 1000 } let(:current_position_y) { 1000 } From 22001c47848134cc964c337ff41ceaccc9d2c63d Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 26 Feb 2022 11:20:17 +0900 Subject: [PATCH 37/44] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92=E3=81=BE=E3=81=A8=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/procon/macro.rb | 77 ++++++++++----------------- 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/lib/procon_bypass_man/procon/macro.rb b/lib/procon_bypass_man/procon/macro.rb index b2a44594..fcff434b 100644 --- a/lib/procon_bypass_man/procon/macro.rb +++ b/lib/procon_bypass_man/procon/macro.rb @@ -1,9 +1,25 @@ class ProconBypassMan::Procon::Macro - class OnetimeNestedStep + class BaseNestedStep def initialize(value) @hash = value end + private + + def incr_step_index! + if step_index + @hash[:step_index] += 1 + else + @hash[:step_index] = 0 + end + end + + def current_step + @hash[:steps][step_index] + end + end + + class OnetimeNestedStep < BaseNestedStep def over? current_step.nil? end @@ -16,32 +32,20 @@ def next_step private - def current_step - @hash[:steps][step_index] - end - def step_index @hash[:step_index] ||= 0 end - - def incr_step_index! - if step_index - @hash[:step_index] += 1 - else - @hash[:step_index] = 0 - end - end end - class NestedStep + class NestedStep < BaseNestedStep def initialize(value) - @hash = value + super unless @hash[:end_at] @hash[:end_at] = (Time.now + @hash[:continue_for]).round(4) end end - def over_end_at? + def over? (@hash[:end_at] < Time.now).tap do |result| if result ProconBypassMan.logger.debug { "[Macro] nested step is finished(#{@hash})" } @@ -51,8 +55,6 @@ def over_end_at? def next_step incr_step_index! - - debug_incr_called_count! if step = current_step return step else @@ -63,30 +65,13 @@ def next_step private - def current_step - @hash[:steps][step_index] - end - def step_index @hash[:step_index] end - def incr_step_index! - if step_index - @hash[:step_index] += 1 - else - @hash[:step_index] = 0 - end - end - def reset_step_index! @hash[:step_index] = 0 end - - def debug_incr_called_count! - @hash[:debug_called_count] ||= 0 - @hash[:debug_called_count] += 1 - end end attr_accessor :name, :steps @@ -103,22 +88,18 @@ def next_step end if step.is_a?(Hash) - if step[:continue_for] - nested_step = NestedStep.new(step) - if nested_step.over_end_at? - steps.shift # NestedStepを破棄する - return next_step + nested_step = + if step[:continue_for] + NestedStep.new(step) else - return nested_step.next_step + OnetimeNestedStep.new(step) end + + if nested_step.over? + steps.shift # NestedStepを破棄する + return next_step else - nested_step = OnetimeNestedStep.new(step) - if nested_step.over? - steps.shift # NestedStepを破棄する - return next_step - else - return nested_step.next_step - end + return nested_step.next_step end end end From 9e4a7ba2411f725548e316aabb94ea5c7072ddf0 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 26 Feb 2022 11:39:37 +0900 Subject: [PATCH 38/44] support macro --- .../buttons_setting_configuration/layer.rb | 4 ++-- .../buttons_setting_configuration_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb index 3a4fc519..dc916cea 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb @@ -55,9 +55,9 @@ def flip(button, if_pressed: false, force_neutral: nil, flip_interval: nil) end # @param [String, Class] プラグインのclass - def macro(name, if_pressed: ) + def macro(name, if_pressed: , if_tilted_left_stick: nil) macro_name = name.to_s.to_sym - self.macros[macro_name] = { if_pressed: if_pressed } + self.macros[macro_name] = { if_pressed: if_pressed, if_tilted_left_stick: if_tilted_left_stick }.compact 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 4f421e9e..ceac23a7 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -485,6 +485,22 @@ def self.steps; [:a, :b]; end {:AMacroPlugin=>{:if_pressed=>[:a, :y]}} ) end + it do + class AMacroPlugin + def self.steps; [:a, :b]; end + end + ProconBypassMan.buttons_setting_configure do + install_macro_plugin(AMacroPlugin) + layer :up do + macro AMacroPlugin, if_pressed: [:a, :y], if_tilted_left_stick: true + end + end + expect(ProconBypassMan::Procon::MacroRegistry.plugins.keys).to eq([:AMacroPlugin]) + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:AMacroPlugin].call).to eq([:a, :b]) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + {:AMacroPlugin=>{:if_pressed=>[:a, :y], if_tilted_left_stick: true }} + ) + end end context 'open macro' do context 'macro v1' do From 4d10f09bc34fb92d405131660d9f471afae78662 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 26 Feb 2022 11:42:14 +0900 Subject: [PATCH 39/44] =?UTF-8?q?1=E3=81=A4=E3=81=AE=E3=83=9E=E3=82=AF?= =?UTF-8?q?=E3=83=AD=E3=81=8C=E5=A7=8B=E3=81=BE=E3=81=A3=E3=81=9F=E3=82=89?= =?UTF-8?q?break=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/procon.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 22de4ea7..b1eb16e4 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -77,6 +77,7 @@ def apply! if user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) + break end end end From e9b7e9fb31c9fa9f1b8b433424a4b17e58501630 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 26 Feb 2022 19:42:26 +0900 Subject: [PATCH 40/44] =?UTF-8?q?=E3=82=B9=E3=83=86=E3=82=A3=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=AE=E9=96=BE=E5=80=A4=E3=82=92=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=81=8B=E3=82=89=E6=B1=BA=E3=82=81=E3=82=8C=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=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/procon.rb | 5 +- ...g_stick_hypotenuse_tilting_power_scaler.rb | 6 ++- .../buttons_setting_configuration_spec.rb | 22 +++++++++ spec/lib/procon_bypass_man/procon_spec.rb | 47 +++++++++++++++++++ 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index b1eb16e4..08814e1b 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -66,8 +66,9 @@ def apply! current_layer.macros.each do |macro_name, options| next unless enable_macro_map[macro_name] - if options[:if_tilted_left_stick] - if dumped_tilting_power&.tilting?(current_position_x: analog_stick.relative_x, current_position_y: analog_stick.relative_y) && user_operation.pressing_all_buttons?(options[:if_pressed]) + if(if_tilted_left_stick_value = options[:if_tilted_left_stick]) + threshold = (if_tilted_left_stick_value.is_a?(Hash) && if_tilted_left_stick_value[:threshold]) || ProconBypassMan::AnalogStickTiltingPowerScaler::DEFAULT_THRESHOLD + if dumped_tilting_power&.tilting?(threshold: threshold, current_position_x: analog_stick.relative_x, current_position_y: analog_stick.relative_y) && user_operation.pressing_all_buttons?(options[:if_pressed]) @@status[:ongoing_macro] = MacroRegistry.load(macro_name) break end diff --git a/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb b/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb index f5908c11..e0cd173a 100644 --- a/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb +++ b/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb @@ -1,4 +1,6 @@ class ProconBypassMan::AnalogStickTiltingPowerScaler + DEFAULT_THRESHOLD = 500 + class PowerChunk def initialize(list) @list = list @@ -10,13 +12,13 @@ def moving_power moving_power = (max - min).abs end - def tilting?(current_position_x: , current_position_y: ) + def tilting?(threshold: DEFAULT_THRESHOLD, current_position_x: , current_position_y: ) # スティックがニュートラルな時 if (-200..200).include?(current_position_x) && (-200..200).include?(current_position_y) return false end - moving_power > 500 + moving_power >= threshold 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 ceac23a7..0bef1f0e 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -562,6 +562,28 @@ def self.steps; [:a, :b]; end { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) end + it do + ProconBypassMan.buttons_setting_configure do + layer :up do + open_macro :dacan, steps: [:pressing_r_and_toggle_zr], if_tilted_left_stick: { threshold: 600 }, if_pressed: [:zr] + end + end + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([{:continue_for=>nil, :steps=>[[:r, :zr], [:r, :none]]}]) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + { dacan: { if_pressed: [:zr], if_tilted_left_stick: { threshold: 600 } } } + ) + end + it do + ProconBypassMan.buttons_setting_configure do + layer :up do + open_macro :dacan, steps: [:pressing_r_and_toggle_zr], if_tilted_left_stick: true, if_pressed: [:zr] + end + end + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([{:continue_for=>nil, :steps=>[[:r, :zr], [:r, :none]]}]) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( + { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } + ) + end end end end diff --git a/spec/lib/procon_bypass_man/procon_spec.rb b/spec/lib/procon_bypass_man/procon_spec.rb index 1a292c99..f4b636a6 100644 --- a/spec/lib/procon_bypass_man/procon_spec.rb +++ b/spec/lib/procon_bypass_man/procon_spec.rb @@ -260,6 +260,53 @@ def self.steps end end + context 'if_tilted_left_stick option' do + context 'provide true' do + let(:data) { "30778105800099277344e86b0a7909f4f5a8f4b500c5ff8dff6c09cdf5b8f49a00c5ff92ff6a0979f5eef46500d5ff9bff000000000000000000000000000000" } + before do + ProconBypassMan.buttons_setting_configure do + prefix_keys_for_changing_layer [:zr] + layer :up do + open_macro :the_macro, steps: [:pressing_thumbr_and_toggle_zr_for_2sec], if_pressed: [:y, :b], if_tilted_left_stick: true + end + end + end + it do + procon = ProconBypassMan::Procon.new(binary) + expect(procon.pressed_y?).to eq(true) + expect(procon.pressed_b?).to eq(true) + expect(procon.pressed_thumbr?).to eq(false) + procon.apply! + + procon = ProconBypassMan::Procon.new(procon.to_binary) + expect(procon.pressed_thumbr?).to eq(false) + expect(procon.pressed_zr?).to eq(false) + end + end + context 'provide Hash' do + let(:data) { "30778105800099277344e86b0a7909f4f5a8f4b500c5ff8dff6c09cdf5b8f49a00c5ff92ff6a0979f5eef46500d5ff9bff000000000000000000000000000000" } + before do + ProconBypassMan.buttons_setting_configure do + prefix_keys_for_changing_layer [:zr] + layer :up do + open_macro :the_macro, steps: [:pressing_thumbr_and_toggle_zr_for_2sec], if_pressed: [:y, :b], if_tilted_left_stick: { threshold: 601 } + end + end + end + it do + procon = ProconBypassMan::Procon.new(binary) + expect(procon.pressed_y?).to eq(true) + expect(procon.pressed_b?).to eq(true) + expect(procon.pressed_thumbr?).to eq(false) + procon.apply! + + procon = ProconBypassMan::Procon.new(procon.to_binary) + expect(procon.pressed_thumbr?).to eq(false) + expect(procon.pressed_zr?).to eq(false) + end + end + end + describe 'disable_macro' do context '条件なし' do context 'すべてのマクロを無効にするとき' do From ce384349c8b3f882dd6104ab6b5274f0c8fe1d09 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 3 Mar 2022 20:06:23 +0900 Subject: [PATCH 41/44] =?UTF-8?q?master=E3=81=AE=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=82=92=E5=8F=96=E3=82=8A=E8=BE=BC=E3=82=93=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/procon/macro_builder.rb | 28 +++++++++---------- .../buttons_setting_configuration_spec.rb | 8 +++--- .../procon/macro_builder_spec.rb | 10 +++---- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/procon_bypass_man/procon/macro_builder.rb b/lib/procon_bypass_man/procon/macro_builder.rb index a9edb9da..f4af7dfe 100644 --- a/lib/procon_bypass_man/procon/macro_builder.rb +++ b/lib/procon_bypass_man/procon/macro_builder.rb @@ -56,7 +56,7 @@ def initialize(steps) # @return [Arary] def build - steps = @steps.map { |step| + steps = @steps.flat_map { |step| if is_reserved?(step: step) || v1_format?(step: step) step.to_sym elsif value = build_if_v2_format?(step: step) @@ -65,7 +65,8 @@ def build nil end } - steps.compact.flatten + + steps.compact end private @@ -93,17 +94,16 @@ def build_if_v2_format?(step: ) if %r!^(pressing_|toggle_)! =~ step && (subjects = step.scan(%r!pressing_[^_]+|toggle_[^_]+!)) && (match = step.match(%r!_for_([\d_]+)(sec)?\z!)) if sec = match[1] - return [ - { continue_for: to_f(sec), - steps: SubjectMerger.merge(subjects.map { |x| Subject.new(x) }).select { |x| - if x.is_a?(Array) - x.select { |y| is_button(y) || RESERVED_WORD_NONE == y } - else - is_button(x) || RESERVED_WORD_NONE == x - end - }, - } - ] + return { + continue_for: to_f(sec), + steps: SubjectMerger.merge(subjects.map { |x| Subject.new(x) }).select { |x| + if x.is_a?(Array) + x.select { |y| is_button(y) || RESERVED_WORD_NONE == y } + else + is_button(x) || RESERVED_WORD_NONE == x + end + }, + } end end @@ -114,7 +114,7 @@ def build_if_v2_format?(step: ) else is_button(x) || RESERVED_WORD_NONE == x end - }.flatten + } 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 24da05df..885a0f8d 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -545,7 +545,7 @@ def self.steps; [:a, :b]; end end end expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq( - [{:continue_for=>0.3, :steps=>[:r, :r]}, {:continue_for=>nil, :steps=>[[:r, :zl], [:r, :none]]}] + [{:continue_for=>0.3, :steps=>[:r, :r]}, [:r, :zl], [:r, :none]] ) expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } @@ -557,7 +557,7 @@ def self.steps; [:a, :b]; end open_macro :dacan, steps: [:pressing_r_and_toggle_zr], if_tilted_left_stick: true, if_pressed: [:zr] end end - expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([{:continue_for=>nil, :steps=>[[:r, :zr], [:r, :none]]}]) + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([[:r, :zr], [:r, :none]]) expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) @@ -568,7 +568,7 @@ def self.steps; [:a, :b]; end open_macro :dacan, steps: [:pressing_r_and_toggle_zr], if_tilted_left_stick: { threshold: 600 }, if_pressed: [:zr] end end - expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([{:continue_for=>nil, :steps=>[[:r, :zr], [:r, :none]]}]) + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([[:r, :zr], [:r, :none]]) expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: { threshold: 600 } } } ) @@ -579,7 +579,7 @@ def self.steps; [:a, :b]; end open_macro :dacan, steps: [:pressing_r_and_toggle_zr], if_tilted_left_stick: true, if_pressed: [:zr] end end - expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([{:continue_for=>nil, :steps=>[[:r, :zr], [:r, :none]]}]) + expect(ProconBypassMan::Procon::MacroRegistry.plugins[:dacan].call).to eq([[:r, :zr], [:r, :none]]) expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].macros).to eq( { dacan: { if_pressed: [:zr], if_tilted_left_stick: true } } ) diff --git a/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb b/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb index 0897c819..3ffba37e 100644 --- a/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb +++ b/spec/lib/procon_bypass_man/procon/macro_builder_spec.rb @@ -102,12 +102,10 @@ describe 'pressing_r_and_toggle_zr' do it do - expect(described_class.new([:pressing_r_and_toggle_zr]).build).to eq( - [{ continue_for: nil, steps: [ - [:r, :zr], - [:r, :none], - ] }] - ) + expect(described_class.new([:pressing_r_and_toggle_zr]).build).to eq([ + [:r, :zr], + [:r, :none], + ]) end end From 19bbc45008fd288c2b267a0dd816c0df2c56042e Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 3 Mar 2022 20:33:18 +0900 Subject: [PATCH 42/44] add splatoo2 maco --- .../plugin/splatoon2/macro/dasei_cancel.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb diff --git a/lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb b/lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb new file mode 100644 index 00000000..706c08e4 --- /dev/null +++ b/lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb @@ -0,0 +1,21 @@ +module ProconBypassMan + module Plugin + module Splatoon2 + module Macro + module DaseiCancel + def self.display_name + :dasei_cancel + end + + def self.steps + [:pressing_r_for_0_03sec, :pressing_r_and_pressing_zl_for_0_2sec].freeze + end + + def self.description + '惰性キャンセル' + end + end + end + end + end +end From e26e25bebf35fd33e4e0bd7406f0131605ad15ab Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 3 Mar 2022 20:50:04 +0900 Subject: [PATCH 43/44] =?UTF-8?q?=E3=82=B9=E3=83=97=E3=83=A9=E3=81=AE?= =?UTF-8?q?=E3=83=97=E3=83=A9=E3=82=B0=E3=82=A4=E3=83=B3=E3=81=A8=E3=81=97?= =?UTF-8?q?=E3=81=A6=E7=99=BB=E9=8C=B2=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++- docs/setting/splatoon2_macro_dasei_cancel.md | 55 ++++++++++++++++++++ lib/procon_bypass_man/plugins.rb | 1 + 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 docs/setting/splatoon2_macro_dasei_cancel.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bfa4238..e40bd140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## [0.1.21] - 2022-2- +## [0.1.21] - 2022-03-03 - install_macro_pluginしていないマクロをlayer内で使うとクラッシュしていた問題を修正しました - 数十時間起動しっぱなしだとpbm-cloudとのwebsocketの接続が切断される問題を修正しました - 誤発動を防ぐために、マクロを無効にする設定ができるようになりました @@ -8,8 +8,12 @@ - 特定のマクロを無効にする - disable_macro TheMacro - disable_macro TheMacro, if_pressed: [:a] +- スティックを傾けたタイミングでマクロを発動するオプションを実装しました + - これによってスプラトゥーン2の惰性キャンセルができるようになります + - ただし、精度がイマイチなので今後改善していきます + - 詳しくは `スプラトゥーン2: 惰性キャンセル マクロの設定方法` を参照してください -## [0.1.20.2] - 2022-2-18 +## [0.1.20.2] - 2022-02-18 - 起動時にreniceするようにしました - 起動時にusb gadgetモードを有効にするようにしました - pbm-cloudからprocon_bypass_manをアップグレードできるようになりました diff --git a/docs/setting/splatoon2_macro_dasei_cancel.md b/docs/setting/splatoon2_macro_dasei_cancel.md new file mode 100644 index 00000000..cd9ec4d7 --- /dev/null +++ b/docs/setting/splatoon2_macro_dasei_cancel.md @@ -0,0 +1,55 @@ +# スプラトゥーン2: 惰性キャンセル マクロの設定方法 + +* procon_bypass_man: 0.1.21以上が必要です + +## 1. install_macro_pluginでマクロを有効化します +* `setting.yml` に`install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel` と書きます +* これを記述することで、layer内で呼び出せるようになります + +``` +install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel +``` + +## 2. どのlayerで発動するかを宣言します +* `setting.yml` のlayer内に`macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_pressed: [:zl]` と書きます + * `if_pressed` がどのボタンを押したときにこのマクロが発動するかの設定です + * 惰性キャンセルなのでイカ状態になるためにzlを押します + * `if_tilted_left_stick` がスティックを倒した時に発動するオプションです + +``` +layer :up do + macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_tilted_left_stick: true, if_pressed: [:zl] +end +``` + +## 3. 設定を反映させる +* 上記の記述を加えたsetting.ymlを起動中のprocon_bypass_manプロセスで読み込むには、プロセスにその旨を伝える必要があります + * ラズベリーパイを再起動して、プロセスを立ち上げ直す、でも目的は達成できますが、もっと簡単にsetting.ymlを再読み込みする必要があります +* 書き換えたsetting.ymlを、起動中のprocon_bypass_manプロセスへ即時反映するには、procon_bypass_manプロセスを動かしたまま、別のshellから 以下をを実行してください + * setting.ymlのシンタックスが正しければ、switchとの接続が継続したままsetting.ymlの内容を読み込んでいるはずです + +## 設定例1 +```yaml +version: 1.0 +setting: |- + prefix_keys_for_changing_layer [:zr, :zl, :l] + install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel + + layer :up do + macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_tilted_left_stick: true, if_pressed: [:zl] + end +``` + +## 設定例2 +* `open_macro` キーワードを使っても同じことが実行可能です。 +* この場合は、 `install_macro_plugin` が不要です。 + +```yaml +version: 1.0 +setting: |- + prefix_keys_for_changing_layer [:zr, :zl, :l] + + layer :up do + open_macro :dacan, steps: [:pressing_r_for_0_03sec, :pressing_r_and_pressing_zl_for_0_2sec], if_tilted_left_stick: true, if_pressed: [:zl] + end +``` diff --git a/lib/procon_bypass_man/plugins.rb b/lib/procon_bypass_man/plugins.rb index 1eef0716..a011a138 100644 --- a/lib/procon_bypass_man/plugins.rb +++ b/lib/procon_bypass_man/plugins.rb @@ -4,6 +4,7 @@ require_relative "plugin/splatoon2/macro/jump_to_up_key" require_relative "plugin/splatoon2/macro/jump_to_left_key" require_relative "plugin/splatoon2/macro/sokuwari_for_splash_bomb" +require_relative "plugin/splatoon2/macro/dasei_cancel" require_relative "plugin/splatoon2/mode/guruguru" module ProconBypassMan From 1ce9aafbf7127e79a38cc8b811a69d0a79d6728e Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 3 Mar 2022 21:14:01 +0900 Subject: [PATCH 44/44] =?UTF-8?q?disable=5Fmacro=E3=81=AB=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6=E8=A8=80=E5=8F=8A=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/setting/splatoon2_macro_dasei_cancel.md | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/setting/splatoon2_macro_dasei_cancel.md b/docs/setting/splatoon2_macro_dasei_cancel.md index cd9ec4d7..8dc67689 100644 --- a/docs/setting/splatoon2_macro_dasei_cancel.md +++ b/docs/setting/splatoon2_macro_dasei_cancel.md @@ -1,12 +1,13 @@ # スプラトゥーン2: 惰性キャンセル マクロの設定方法 +* 本マクロは実験段階で、オプション名などの仕様が変更される可能性が高いです * procon_bypass_man: 0.1.21以上が必要です ## 1. install_macro_pluginでマクロを有効化します * `setting.yml` に`install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel` と書きます -* これを記述することで、layer内で呼び出せるようになります +* これを記述することで、layer内でmacroを呼び出せるようになります -``` +```ruby install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel ``` @@ -14,10 +15,25 @@ install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel * `setting.yml` のlayer内に`macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_pressed: [:zl]` と書きます * `if_pressed` がどのボタンを押したときにこのマクロが発動するかの設定です * 惰性キャンセルなのでイカ状態になるためにzlを押します - * `if_tilted_left_stick` がスティックを倒した時に発動するオプションです + * `if_tilted_left_stick` がスティックを倒した時に発動するオプションで、trueを渡すと有効になります + * また、傾けた時の閾値を変更することができて、trueの代わりに `{ threshold: 500 }` と書くことができます + * デフォルトが500で、ここの数値を上げると、スティックを倒した判定がより厳しくなります。最大1400くらいです。 +* 連打中に、マクロの発動を無効にしたい場合は `disable_macro` で無効にできます +```ruby +layer :up do + macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_tilted_left_stick: true, if_pressed: [:zl] +end +``` +```ruby +layer :up do + macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_tilted_left_stick: { threshold: 500 }, if_pressed: [:zl] +end ``` +```ruby layer :up do + disable_macro :all, if_pressed: :a + disable_macro :all, if_pressed: :zr macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_tilted_left_stick: true, if_pressed: [:zl] end ``` @@ -36,6 +52,8 @@ setting: |- install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel layer :up do + disable_macro :all, if_pressed: :a + disable_macro :all, if_pressed: :zr macro ProconBypassMan::Plugin::Splatoon2::Macro::DaseiCancel, if_tilted_left_stick: true, if_pressed: [:zl] end ```