Skip to content

Commit

Permalink
Merge pull request #268 from splaplapla/with-press
Browse files Browse the repository at this point in the history
左スティックの感度調整設定で「追加でボタンを押すオプション」を新しく追加する
  • Loading branch information
jiikko authored Jul 15, 2023
2 parents 026dd1f + d308ba0 commit 22e00df
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
29 changes: 29 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 10 additions & 1 deletion lib/procon_bypass_man/buttons_setting_configuration/layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/procon_bypass_man/procon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 |button|
user_operation.press_button(button)
end
user_operation.apply_left_analog_stick_cap(cap: config[:cap])
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/procon_bypass_man/buttons_setting_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 41 additions & 1 deletion spec/lib/procon_bypass_man/procon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand Down

0 comments on commit 22e00df

Please sign in to comment.