From 42c3e01fbb80d4ccf186830ef0b35ee61db8c84b Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 15 Jul 2023 19:59:05 +0900 Subject: [PATCH 1/4] use 0.0.0.0 --- spec/lib/procon_bypass_man/support/simple_tcp_server_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/procon_bypass_man/support/simple_tcp_server_spec.rb b/spec/lib/procon_bypass_man/support/simple_tcp_server_spec.rb index f4cfe610..bb40ad92 100644 --- a/spec/lib/procon_bypass_man/support/simple_tcp_server_spec.rb +++ b/spec/lib/procon_bypass_man/support/simple_tcp_server_spec.rb @@ -2,7 +2,7 @@ require 'procon_bypass_man/support/simple_tcp_server' describe SimpleTCPServer do - let(:host) { 'localhost' } + let(:host) { '0.0.0.0' } let(:port) { 8000 } let(:server) { SimpleTCPServer.new(host, port) } let(:server_thread) { Thread.new { server.run } } From 3e5a92be8abf47a5c7399d0ed58a7f96e9ec74fa Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 15 Jul 2023 20:02:04 +0900 Subject: [PATCH 2/4] =?UTF-8?q?left=5Fanalog=5Fstick=5Fcap=E3=81=ABcombine?= =?UTF-8?q?d=5Fpress=5Fis=5Fpressed=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=92=E5=A2=97=E3=82=84=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buttons_setting_configuration/layer.rb | 11 ++++++++++- lib/procon_bypass_man/procon.rb | 3 +++ .../buttons_setting_configuration_spec.rb | 18 ++++++++++++++++++ 3 files changed, 31 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 3c661bca..c72f50c8 100644 --- a/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +++ b/lib/procon_bypass_man/buttons_setting_configuration/layer.rb @@ -172,7 +172,7 @@ def remap(button, to: ) end end - def left_analog_stick_cap(cap: nil, if_pressed: nil, force_neutral: nil) + def left_analog_stick_cap(cap: nil, if_pressed: nil, force_neutral: nil, combined_press_is_pressed: nil) case cap when Integer # OK @@ -203,6 +203,15 @@ def left_analog_stick_cap(cap: nil, if_pressed: nil, force_neutral: nil) return end + begin + if(combined_press_is_pressed = ParamNormalizer::IfPressedAllowsFalsy.new(combined_press_is_pressed).to_value!) + hash[:combined_press_is_pressed] = combined_press_is_pressed + end + rescue ParamNormalizer::UnSupportValueError + Kernel.warn "設定ファイルに記述ミスがあります. left_analog_stick_capのcombined_press_is_pressedにはボタンを渡してください." + return + end + left_analog_stick_caps << hash end diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index 747ef245..fad751ac 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -226,6 +226,9 @@ def to_binary(external_input_data: nil) config[:force_neutral]&.each do |force_neutral_button| user_operation.unpress_button(force_neutral_button) end + config[:combined_press_is_pressed]&.each do |combined_press_is_pressed| + combined_press_is_pressed.each { |button| user_operation.press_button(button) } + end user_operation.apply_left_analog_stick_cap(cap: config[:cap]) 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 6c1ff9d1..df7d7000 100644 --- a/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb +++ b/spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb @@ -81,6 +81,24 @@ ]) end end + context 'with force_neutral' do + let(:setting_content) do + <<~EOH + version: 1.0 + setting: |- + prefix_keys_for_changing_layer [:zr, :r, :zl, :l] + layer :up do + left_analog_stick_cap cap: 1000, if_pressed: [:a], force_neutral: [:a], combined_press_is_pressed: [:b] + end + EOH + end + it do + ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting.path) + expect(ProconBypassMan::ButtonsSettingConfiguration.instance.layers[:up].left_analog_stick_caps).to eq([ + {:cap=>1000, :force_neutral=> [:a], if_pressed: [:a], combined_press_is_pressed: [:b] } + ]) + end + end context 'provide array' do let(:setting_content) do <<~EOH From 3069bb0e040282d09d3550706600ef67d9942808 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 15 Jul 2023 20:18:00 +0900 Subject: [PATCH 3/4] add bin/rspec --- bin/rspec | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 bin/rspec diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 00000000..a6c78521 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") From d308ba05de222c59708efc8c1106271c063a6d7e Mon Sep 17 00:00:00 2001 From: jiikko Date: Sat, 15 Jul 2023 20:20:21 +0900 Subject: [PATCH 4/4] =?UTF-8?q?procon=20spec=E3=82=92=E6=9B=B8=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/procon_bypass_man/procon.rb | 4 +-- spec/lib/procon_bypass_man/procon_spec.rb | 42 ++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/procon_bypass_man/procon.rb b/lib/procon_bypass_man/procon.rb index fad751ac..8e67d9d7 100644 --- a/lib/procon_bypass_man/procon.rb +++ b/lib/procon_bypass_man/procon.rb @@ -226,8 +226,8 @@ def to_binary(external_input_data: nil) config[:force_neutral]&.each do |force_neutral_button| user_operation.unpress_button(force_neutral_button) end - config[:combined_press_is_pressed]&.each do |combined_press_is_pressed| - combined_press_is_pressed.each { |button| user_operation.press_button(button) } + config[:combined_press_is_pressed]&.each do |button| + user_operation.press_button(button) end user_operation.apply_left_analog_stick_cap(cap: config[:cap]) end diff --git a/spec/lib/procon_bypass_man/procon_spec.rb b/spec/lib/procon_bypass_man/procon_spec.rb index aff66124..b136121f 100644 --- a/spec/lib/procon_bypass_man/procon_spec.rb +++ b/spec/lib/procon_bypass_man/procon_spec.rb @@ -52,7 +52,7 @@ context 'with left_analog_stick_caps' do let(:data) { "30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000" } # no_action - it do + it 'aを押したら発動すること' do ProconBypassMan.buttons_setting_configure do prefix_keys_for_changing_layer [:zr] layer :up do @@ -66,6 +66,46 @@ end end + context 'with left_analog_stick_caps and combined_press_is_pressed' do + let(:data) { "30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000" } # no_action + it 'aを押したらbを押すこと' do + ProconBypassMan.buttons_setting_configure do + prefix_keys_for_changing_layer [:zr] + layer :up do + left_analog_stick_cap cap: 1000, if_pressed: [:a], combined_press_is_pressed: [:b] + end + end + + ProconBypassMan::Procon.new(binary).tap do |procon| + procon.user_operation.press_button(:a) + expect(procon.user_operation).to receive(:apply_left_analog_stick_cap).once + procon.to_binary + expect(procon.user_operation).to be_pressed_a + expect(procon.user_operation).to be_pressed_b # 明示的に押していないが、combined_press_is_pressedのため押されている + end + end + end + + context 'with left_analog_stick_caps and combined_press_is_pressed' do + let(:data) { "30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000" } # no_action + it 'aを押したらbを押すこと' do + ProconBypassMan.buttons_setting_configure do + prefix_keys_for_changing_layer [:zr] + layer :up do + left_analog_stick_cap cap: 1000, if_pressed: [:a], combined_press_is_pressed: [] + end + end + + ProconBypassMan::Procon.new(binary).tap do |procon| + procon.user_operation.press_button(:a) + expect(procon.user_operation).to receive(:apply_left_analog_stick_cap).once + procon.to_binary + expect(procon.user_operation).to be_pressed_a + expect(procon.user_operation).not_to be_pressed_b + end + end + end + context 'with flip_interval' do let(:data) { "30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000" } # no_action it do