fix: make run menus layout and input robust

This commit is contained in:
goose
2026-10-02 17:54:49 -04:00
parent 77c5e54728
commit 2938153ca8
6 changed files with 179 additions and 111 deletions
+38 -10
View File
@@ -7,6 +7,7 @@ func before_each() -> void:
menu = MainMenuScene.instantiate()
add_child_autofree(menu)
await get_tree().process_frame
await get_tree().process_frame
func test_actual_menu_creation_flow_starts_game_and_emits_event() -> void:
var started_events: Array[GameEvent] = []
@@ -14,20 +15,21 @@ func test_actual_menu_creation_flow_starts_game_and_emits_event() -> void:
started_events.append_array(run_state.recent_events(1))
)
(menu.get_node("Menu/NewRunButton") as Button).emit_signal("pressed")
await get_tree().process_frame
var new_run_button := menu.get_node("Menu/Layout/NewRunButton") as Button
await _click_button(new_run_button)
var creation := menu.get_node("CharacterCreation") as CharacterCreation
assert_not_null(creation)
assert_true(creation.visible)
(creation.get_node("Panel/Fields/NameEdit") as LineEdit).text = "A6 Hero"
(creation.get_node("Panel/Fields/ArchetypeOption") as OptionButton).select(1)
(creation.get_node("Panel/Fields/PetCheck") as CheckBox).button_pressed = true
(creation.get_node("Panel/Fields/SeedEdit") as LineEdit).text = "A6-E2E-SEED"
(creation.get_node("Panel/Fields/DifficultyOption") as OptionButton).select(2)
(creation.get_node("Panel/Fields/PermadeathOption") as OptionButton).select(1)
(creation.get_node("Panel/StartRunButton") as Button).emit_signal("pressed")
await get_tree().process_frame
(creation.get_node("Panel/Layout/Fields/NameEdit") as LineEdit).text = "A6 Hero"
(creation.get_node("Panel/Layout/Fields/ArchetypeOption") as OptionButton).select(1)
(creation.get_node("Panel/Layout/Fields/PetCheck") as CheckBox).button_pressed = true
(creation.get_node("Panel/Layout/Fields/SeedEdit") as LineEdit).text = "A6-E2E-SEED"
(creation.get_node("Panel/Layout/Fields/DifficultyOption") as OptionButton).select(2)
(creation.get_node("Panel/Layout/Fields/PermadeathOption") as OptionButton).select(1)
var start_run_button := creation.get_node("Panel/Layout/Actions/StartRunButton") as Button
await _click_button(start_run_button)
await get_tree().process_frame
var game := menu.get_node_or_null("Game") as Game
@@ -44,3 +46,29 @@ func test_actual_menu_creation_flow_starts_game_and_emits_event() -> void:
assert_eq(started_events.size(), 1)
assert_eq(started_events[0].payload["seed"], "A6-E2E-SEED")
assert_eq(started_events[0].payload["difficulty_id"], &"veteran")
func _click_button(button: Button) -> void:
assert_not_null(button)
assert_true(button.visible)
var click_position := button.get_global_rect().get_center()
get_tree().root.push_input(_mouse_motion_event(click_position), true)
await get_tree().process_frame
get_tree().root.push_input(_mouse_button_event(click_position, true), true)
await get_tree().process_frame
get_tree().root.push_input(_mouse_button_event(click_position, false), true)
await get_tree().process_frame
func _mouse_motion_event(position: Vector2) -> InputEventMouseMotion:
var event := InputEventMouseMotion.new()
event.position = position
event.global_position = position
return event
func _mouse_button_event(position: Vector2, pressed: bool) -> InputEventMouseButton:
var event := InputEventMouseButton.new()
event.position = position
event.global_position = position
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = MOUSE_BUTTON_MASK_LEFT if pressed else 0
event.pressed = pressed
return event