Skip to content

Commit

Permalink
Emit did_change signal when setting from empty (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhoad authored Mar 20, 2024
1 parent 70d6513 commit 3d50dfb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Input Helper.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.1.1">
<Project Sdk="Godot.NET.Sdk/4.2.1">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
Expand Down
7 changes: 7 additions & 0 deletions Input Helper.csproj.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Godot.NET.Sdk/4.1.1">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>InputHelper</RootNamespace>
</PropertyGroup>
</Project>
9 changes: 4 additions & 5 deletions addons/input_helper/input_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func _update_input_for_action(action: String, input: InputEvent, swap_if_taken:

# Find the key based event for the target action
var action_events: Array[InputEvent] = InputMap.action_get_events(action)
var did_change: bool = false
var is_replacing: bool = false
for i in range(0, action_events.size()):
var event: InputEvent = action_events[i]
if check_is_valid.call(event):
Expand All @@ -376,11 +376,11 @@ func _update_input_for_action(action: String, input: InputEvent, swap_if_taken:

# Replace the event
action_events[i] = input
did_change = true
is_replacing = true
break

# If we were trying to replace something but didn't find it then just add it to the end
if not did_change:
if not is_replacing:
action_events.append(input)

# Apply the changes
Expand All @@ -389,8 +389,7 @@ func _update_input_for_action(action: String, input: InputEvent, swap_if_taken:
if event != null:
InputMap.action_add_event(action, event)

if did_change:
did_change_signal.emit(action, input)
did_change_signal.emit(action, input)

return OK

Expand Down
6 changes: 5 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="Input Helper"
run/main_scene="res://tests/tests.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/features=PackedStringArray("4.2", "C#", "Forward Plus")
config/icon="res://icon.svg"

[autoload]
Expand Down Expand Up @@ -48,3 +48,7 @@ ui_accept={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
]
}
ui_test_empty={
"deadzone": 0.5,
"events": []
}
Loading

0 comments on commit 3d50dfb

Please sign in to comment.