Skip to content

Commit

Permalink
Fix User Input Auto-Advance (#2024)
Browse files Browse the repository at this point in the history
* Fix incorrect Auto-Advance flag being disabled.

* Add missing double newline between methods.

* Add tests for Auto-Advance.

* Add `[autoload]` to the project file.

* Remove `class_name` from unit tests.
  • Loading branch information
CakeVR authored Jan 16, 2024
1 parent 482ee71 commit d8df1d7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/resources/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ config/icon="res://icon.svg"

renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"

[autoload]

Dialogic="*res://addons/dialogic/Other/DialogicGameHandler.gd"
6 changes: 3 additions & 3 deletions addons/dialogic/Modules/Core/subsystem_input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func resume() -> void:
####### MAIN METHODS ###########################################################
#region MAIN METHODS

func handle_input():
func handle_input() -> void:
if dialogic.paused or is_input_blocked():
return

if !action_was_consumed:
if not action_was_consumed:
# We want to stop auto-advancing that cancels on user inputs.
if (auto_advance.is_enabled()
and auto_advance.enabled_until_user_input):
auto_advance.enabled_until_next_event = false
auto_advance.enabled_until_user_input = false
action_was_consumed = true

# We want to stop auto-skipping if it's enabled, we are listening
Expand Down
1 change: 1 addition & 0 deletions addons/dialogic/Modules/Text/auto_advance.gd
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var enabled_until_user_input := false :
enabled_until_user_input = enabled
_try_emit_toggled()


func _init() -> void:
DialogicUtil.autoload().Input.add_child(autoadvance_timer)
autoadvance_timer.one_shot = true
Expand Down
19 changes: 19 additions & 0 deletions addons/dialogic/Tests/Unit/test_auto_advance.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends GdUnitTestSuite

## Ensure Auto-Advance is enabled properly using the user input flag.
func test_enable_auto_advance() -> void:
Dialogic.Input.auto_advance.enabled_until_user_input = true
var is_enabled: bool = Dialogic.Input.auto_advance.is_enabled()

assert(is_enabled == true, "Auto-Advance is not enabled.")


## This test was created to ensure a bug was fixed:
## When the user enabled the Auto-Advance until user input,
## the Auto-Advance would still run after the user input.
func test_disable_auto_advance() -> void:
Dialogic.Input.auto_advance.enabled_until_user_input = true
Dialogic.Input.handle_input()

var is_enabled: bool = Dialogic.Input.auto_advance.is_enabled()
assert(is_enabled == false, "Auto-Advance is still running after input")
1 change: 0 additions & 1 deletion addons/dialogic/Tests/Unit/test_example.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class_name GdUnitExampleTest
extends GdUnitTestSuite

func test_example() -> void:
Expand Down

0 comments on commit d8df1d7

Please sign in to comment.