Skip to content

Commit

Permalink
left_analog_stick_capにcombined_press_is_pressedオプションを増やす
Browse files Browse the repository at this point in the history
  • Loading branch information
jiikko committed Jul 15, 2023
1 parent 42c3e01 commit 3e5a92b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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 |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
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

0 comments on commit 3e5a92b

Please sign in to comment.