A10: Menus and settings
The game now opens on a main menu when it has a window: practice against bots (count and skill), join a server (by address, or from a LAN search list), settings, and quit. In a match, Escape brings up a pause menu (the match goes on) with settings and leave; when a match the player was in ends, a results screen shows their place, eliminations and the last of the feed. - KeyBindings: every action rebindable to a key or mouse button. bind() refuses an input another action uses and names it; Escape is reserved. ClientInput reads keys through the bindings. - GameSettings: bindings, mouse, graphics (quality preset and the print pass), audio (master, music and effects buses), display (window mode, vsync, frame cap), name, last server and practice choices, saved in user://settings.cfg. Missing, unreadable or corrupt files and bad values fall back to defaults, value by value; hand-edited key clashes are repaired on load. - Menus (src/ui): paper-and-ink panels, brass focus edge, keyboard navigable; a drawn sea-and-tide-post backdrop, or an ink wash over a match. AppShell runs menus and the session. - LocalServer takes a bot difficulty. - make menu-captures renders every screen. Closes #50 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "join"
|
||||
over_match = false
|
||||
settings_tab = 0
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "main"
|
||||
over_match = false
|
||||
settings_tab = 0
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "pause"
|
||||
over_match = true
|
||||
settings_tab = 0
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "practice"
|
||||
over_match = false
|
||||
settings_tab = 0
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "results"
|
||||
over_match = true
|
||||
settings_tab = 0
|
||||
@@ -0,0 +1,37 @@
|
||||
## Capture scenario for the menus (A10): one screen of Menus, as a player would first see
|
||||
## it, with default settings and nothing saved. `screen` is one of Menus.SCREENS; the
|
||||
## join screen lists two made-up servers, and the results screen a made-up finish.
|
||||
## `over_match` puts the ink wash over a plain stand-in for a match instead of the
|
||||
## backdrop.
|
||||
extends Control
|
||||
|
||||
@export var screen: String = "main"
|
||||
@export var over_match: bool = false
|
||||
@export var settings_tab: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
if over_match:
|
||||
var stand_in: MenuBackdrop = MenuBackdrop.new()
|
||||
stand_in.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
add_child(stand_in)
|
||||
var menus: Menus = Menus.new()
|
||||
menus.use_settings(GameSettings.new(), "user://capture_unsaved.cfg")
|
||||
add_child(menus)
|
||||
menus.over_match = over_match
|
||||
match screen:
|
||||
"join":
|
||||
menus.show_screen("join", false)
|
||||
menus.show_servers([
|
||||
{"name": "Harbour Lights", "players": 11, "max_players": 24, "address": "192.0.2.10", "port": 24650, "source": "lan", "compatible": true},
|
||||
{"name": "Saltmarsh", "players": 2, "max_players": 24, "address": "192.0.2.11", "port": 24650, "source": "list", "compatible": true},
|
||||
{"name": "Old Pier", "players": 0, "max_players": 24, "address": "192.0.2.12", "port": 24650, "source": "lan", "compatible": false},
|
||||
] as Array[Dictionary])
|
||||
"results":
|
||||
menus.show_results(3, 24, 4, ["Ada drowned", "You took Thole with a dock carbine", "Gannet fell"] as Array[String])
|
||||
"settings":
|
||||
menus.show_screen("settings", false)
|
||||
menus._tabs.current_tab = settings_tab
|
||||
_:
|
||||
menus.show_screen(screen, false)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxiu5n42retf7
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "settings"
|
||||
over_match = false
|
||||
settings_tab = 0
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureMenu" type="Control"]
|
||||
script = ExtResource("1")
|
||||
screen = "settings"
|
||||
over_match = false
|
||||
settings_tab = 1
|
||||
@@ -0,0 +1,130 @@
|
||||
extends TestCase
|
||||
|
||||
## A10: settings saved between launches, and corrupt files falling back to defaults.
|
||||
|
||||
const PATH: String = "user://test_game_settings.cfg"
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
super.after_each()
|
||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH))
|
||||
|
||||
|
||||
func test_everything_round_trips() -> void:
|
||||
var settings: GameSettings = GameSettings.new()
|
||||
settings.mouse.mouse_sensitivity = 2.5
|
||||
settings.mouse.invert_y = true
|
||||
assert_eq(settings.bindings.bind("jump", KEY_F), "")
|
||||
settings.quality = GameSettings.QUALITY_LOW
|
||||
settings.print_pass = false
|
||||
settings.master_volume = 0.3
|
||||
settings.music_volume = 0.0
|
||||
settings.effects_volume = 0.55
|
||||
settings.window_mode = 1
|
||||
settings.vsync = false
|
||||
settings.max_fps = 144
|
||||
settings.player_name = " Wren of the Point "
|
||||
settings.last_server = "example.org:24650"
|
||||
settings.practice_bots = 7
|
||||
settings.practice_difficulty = 2
|
||||
assert_eq(settings.save(PATH), OK)
|
||||
var loaded: GameSettings = GameSettings.load_from(PATH)
|
||||
assert_near(loaded.mouse.mouse_sensitivity, 2.5, 0.0001)
|
||||
assert_true(loaded.mouse.invert_y)
|
||||
assert_eq(loaded.bindings.code_of("jump"), KEY_F)
|
||||
assert_eq(loaded.quality, GameSettings.QUALITY_LOW)
|
||||
assert_false(loaded.print_pass)
|
||||
assert_near(loaded.master_volume, 0.3, 0.0001)
|
||||
assert_near(loaded.music_volume, 0.0, 0.0001)
|
||||
assert_near(loaded.effects_volume, 0.55, 0.0001)
|
||||
assert_eq(loaded.window_mode, 1)
|
||||
assert_false(loaded.vsync)
|
||||
assert_eq(loaded.max_fps, 144)
|
||||
assert_eq(loaded.player_name, "Wren of the Point")
|
||||
assert_eq(loaded.last_server, "example.org:24650")
|
||||
assert_eq(loaded.practice_bots, 7)
|
||||
assert_eq(loaded.practice_difficulty, 2)
|
||||
assert_eq(loaded.shadow_distance(), 0.0, "low has no shadows")
|
||||
|
||||
|
||||
func test_a_missing_file_gives_defaults() -> void:
|
||||
var loaded: GameSettings = GameSettings.load_from("user://no_such_settings.cfg")
|
||||
_assert_defaults(loaded)
|
||||
|
||||
|
||||
func test_a_corrupt_file_gives_defaults() -> void:
|
||||
# The engine reports each file it can't parse; that's expected here.
|
||||
expect_error("ConfigFile parse error")
|
||||
expect_error("ConfigFile parse error")
|
||||
for garbage: PackedByteArray in [
|
||||
"[graphics\nquality=???\n".to_utf8_buffer() + PackedByteArray([0, 1]),
|
||||
PackedByteArray([0xFF, 0xFE, 0x00, 0x13, 0x37, 0x80, 0x81]),
|
||||
"quality = 2 = 3 [[[".to_utf8_buffer(),
|
||||
]:
|
||||
var file: FileAccess = FileAccess.open(PATH, FileAccess.WRITE)
|
||||
file.store_buffer(garbage)
|
||||
file.close()
|
||||
_assert_defaults(GameSettings.load_from(PATH))
|
||||
|
||||
|
||||
func test_wrong_types_and_ranges_fall_back_value_by_value() -> void:
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
config.set_value("graphics", "quality", 99)
|
||||
config.set_value("graphics", "print_pass", "yes")
|
||||
config.set_value("audio", "master", 7.0)
|
||||
config.set_value("audio", "music", NAN)
|
||||
config.set_value("audio", "effects", [1, 2])
|
||||
config.set_value("display", "window_mode", -4)
|
||||
config.set_value("display", "max_fps", 77)
|
||||
config.set_value("player", "name", 12)
|
||||
config.set_value("practice", "bots", 400)
|
||||
config.set_value("input", "mouse_sensitivity", INF)
|
||||
config.set_value("keys", "forward", KEY_UP)
|
||||
assert_eq(config.save(PATH), OK)
|
||||
var loaded: GameSettings = GameSettings.load_from(PATH)
|
||||
assert_eq(loaded.quality, GameSettings.QUALITY_HIGH, "clamped to the top preset")
|
||||
assert_true(loaded.print_pass, "not a bool: the default")
|
||||
assert_near(loaded.master_volume, 1.0, 0.0001, "clamped")
|
||||
assert_near(loaded.music_volume, GameSettings.new().music_volume, 0.0001, "NaN: the default")
|
||||
assert_near(loaded.effects_volume, GameSettings.new().effects_volume, 0.0001)
|
||||
assert_eq(loaded.window_mode, 0)
|
||||
assert_eq(loaded.max_fps, 0, "not an offered cap")
|
||||
assert_eq(loaded.player_name, ClientConfig.DEFAULT_NAME)
|
||||
assert_eq(loaded.practice_bots, Tuning.SOLO_PLAYERS - 1)
|
||||
assert_near(loaded.mouse.mouse_sensitivity, 1.0, 0.0001)
|
||||
assert_eq(loaded.bindings.code_of("forward"), KEY_UP, "the one good value is kept")
|
||||
|
||||
|
||||
func test_old_mouse_only_files_still_load() -> void:
|
||||
var old: InputSettings = InputSettings.new()
|
||||
old.mouse_sensitivity = 3.0
|
||||
assert_eq(old.save(PATH), OK)
|
||||
var loaded: GameSettings = GameSettings.load_from(PATH)
|
||||
assert_near(loaded.mouse.mouse_sensitivity, 3.0, 0.0001)
|
||||
assert_eq(loaded.bindings.code_of("jump"), KEY_SPACE)
|
||||
|
||||
|
||||
func test_applying_settings_sets_the_audio_buses() -> void:
|
||||
var settings: GameSettings = GameSettings.new()
|
||||
settings.music_volume = 0.0
|
||||
settings.effects_volume = 0.5
|
||||
settings.apply_to_program(null)
|
||||
var music: int = AudioServer.get_bus_index("Music")
|
||||
var effects: int = AudioServer.get_bus_index("Effects")
|
||||
assert_true(music > 0 and effects > 0, "made the buses")
|
||||
assert_true(AudioServer.is_bus_mute(music))
|
||||
assert_near(AudioServer.get_bus_volume_db(effects), linear_to_db(0.5), 0.01)
|
||||
settings.apply_to_program(null)
|
||||
assert_eq(AudioServer.bus_count, 3, "no extra buses the second time")
|
||||
|
||||
|
||||
func _assert_defaults(loaded: GameSettings) -> void:
|
||||
var fresh: GameSettings = GameSettings.new()
|
||||
assert_eq(loaded.quality, fresh.quality)
|
||||
assert_eq(loaded.print_pass, fresh.print_pass)
|
||||
assert_eq(loaded.master_volume, fresh.master_volume)
|
||||
assert_eq(loaded.window_mode, fresh.window_mode)
|
||||
assert_eq(loaded.player_name, fresh.player_name)
|
||||
assert_eq(loaded.mouse.mouse_sensitivity, fresh.mouse.mouse_sensitivity)
|
||||
for action: Dictionary in KeyBindings.ACTIONS:
|
||||
assert_eq(loaded.bindings.code_of(action["id"]), int(action["default"]))
|
||||
@@ -0,0 +1 @@
|
||||
uid://cta4a1dero8fu
|
||||
@@ -0,0 +1,85 @@
|
||||
extends TestCase
|
||||
|
||||
## A10: key bindings, rebinding and conflicts.
|
||||
|
||||
|
||||
func test_defaults_are_the_documented_keys_and_none_clash() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.code_of("forward"), KEY_W)
|
||||
assert_eq(bindings.code_of("build"), KEY_B)
|
||||
assert_eq(bindings.code_of("fire"), -MOUSE_BUTTON_LEFT)
|
||||
assert_eq(bindings.code_of("slot_0"), KEY_1)
|
||||
assert_eq(bindings.conflicts(), [] as Array[String])
|
||||
for action: Dictionary in KeyBindings.ACTIONS:
|
||||
assert_true(KeyBindings.is_valid_code(int(action["default"])), String(action["id"]))
|
||||
|
||||
|
||||
func test_rebinding_to_a_free_key_works() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.bind("jump", KEY_F), "")
|
||||
assert_eq(bindings.code_of("jump"), KEY_F)
|
||||
assert_eq(bindings.bind("aim", -MOUSE_BUTTON_MIDDLE), "")
|
||||
assert_eq(bindings.action_using(-MOUSE_BUTTON_MIDDLE), "aim")
|
||||
|
||||
|
||||
func test_rebinding_to_a_used_key_is_refused_and_names_the_clash() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.bind("jump", KEY_W), "forward")
|
||||
assert_eq(bindings.code_of("jump"), KEY_SPACE, "unchanged")
|
||||
assert_eq(bindings.bind("aim", -MOUSE_BUTTON_LEFT), "fire")
|
||||
# Binding an action to the key it already has is no clash.
|
||||
assert_eq(bindings.bind("forward", KEY_W), "")
|
||||
|
||||
|
||||
func test_escape_wheel_and_nonsense_cannot_be_bound() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.bind("jump", KEY_ESCAPE), "reserved")
|
||||
assert_eq(bindings.bind("jump", -MOUSE_BUTTON_WHEEL_UP), "not an input")
|
||||
assert_eq(bindings.bind("jump", 0), "not an input")
|
||||
assert_eq(bindings.bind("fly", KEY_F), "unknown action")
|
||||
|
||||
|
||||
func test_a_hand_edited_clash_is_repaired_on_load() -> void:
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
config.set_value("keys", "jump", KEY_W)
|
||||
config.set_value("keys", "sprint", "shift")
|
||||
config.set_value("keys", "reload", KEY_ESCAPE)
|
||||
var bindings: KeyBindings = KeyBindings.read(config)
|
||||
assert_eq(bindings.code_of("forward"), KEY_W, "the first in the list keeps it")
|
||||
assert_eq(bindings.code_of("jump"), KEY_SPACE, "the clashing one goes back to its default")
|
||||
assert_eq(bindings.code_of("sprint"), KEY_SHIFT)
|
||||
assert_eq(bindings.code_of("reload"), KEY_R)
|
||||
assert_eq(bindings.conflicts(), [] as Array[String])
|
||||
|
||||
|
||||
func test_events_find_their_action() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
var key: InputEventKey = InputEventKey.new()
|
||||
key.physical_keycode = KEY_B
|
||||
key.pressed = true
|
||||
assert_eq(bindings.action_for_event(key), "build")
|
||||
key.echo = true
|
||||
assert_eq(bindings.action_for_event(key), "", "a held key's repeats don't act")
|
||||
var click: InputEventMouseButton = InputEventMouseButton.new()
|
||||
click.button_index = MOUSE_BUTTON_RIGHT
|
||||
click.pressed = true
|
||||
assert_eq(bindings.action_for_event(click), "aim")
|
||||
|
||||
|
||||
func test_client_input_follows_rebound_keys() -> void:
|
||||
var input: ClientInput = ClientInput.new()
|
||||
assert_eq(input.bindings.bind("build", KEY_Q), "")
|
||||
var key: InputEventKey = InputEventKey.new()
|
||||
key.physical_keycode = KEY_Q
|
||||
key.pressed = true
|
||||
input.handle(key, true)
|
||||
assert_true(input.build_mode, "Q now toggles build mode")
|
||||
key.physical_keycode = KEY_B
|
||||
input.handle(key, true)
|
||||
assert_true(input.build_mode, "B no longer does")
|
||||
|
||||
|
||||
func test_describe_names_keys_and_buttons() -> void:
|
||||
assert_eq(KeyBindings.describe(KEY_W), "W")
|
||||
assert_eq(KeyBindings.describe(-MOUSE_BUTTON_LEFT), "Left mouse")
|
||||
assert_eq(KeyBindings.describe(0), "None")
|
||||
@@ -0,0 +1 @@
|
||||
uid://d0svqwutsfu5y
|
||||
@@ -18,6 +18,7 @@ func test_client_colours_come_from_the_palette() -> void:
|
||||
var named: RegEx = RegEx.create_from_string(NAMED)
|
||||
var paths: Array[String] = _scripts_under("res://src/client")
|
||||
paths.append_array(_scripts_under("res://src/app"))
|
||||
paths.append_array(_scripts_under("res://src/ui"))
|
||||
assert_true(paths.size() > 10, "expected client scripts")
|
||||
for path: String in paths:
|
||||
if ALLOWED.has(path):
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
extends TestCase
|
||||
|
||||
## A10: every menu reachable and navigable, key rebinding through the menu, and the
|
||||
## program's flow from the main menu into a practice match, the pause menu, the
|
||||
## results and back.
|
||||
|
||||
const PATH: String = "user://test_menus_settings.cfg"
|
||||
|
||||
var menus: Menus
|
||||
var tree: SceneTree
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
super.before_each()
|
||||
tree = Engine.get_main_loop() as SceneTree
|
||||
menus = Menus.new()
|
||||
menus.use_settings(GameSettings.new(), PATH)
|
||||
tree.root.add_child(menus)
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
super.after_each()
|
||||
if is_instance_valid(menus):
|
||||
menus.free()
|
||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH))
|
||||
|
||||
|
||||
func _press(screen: String, text: String) -> void:
|
||||
var buttons: Dictionary = menus.buttons_of(screen)
|
||||
assert_true(buttons.has(text), "%s has a '%s' button (has %s)" % [screen, text, buttons.keys()])
|
||||
if buttons.has(text):
|
||||
(buttons[text] as Button).pressed.emit()
|
||||
|
||||
|
||||
func _key(keycode: Key) -> InputEventKey:
|
||||
var key: InputEventKey = InputEventKey.new()
|
||||
key.physical_keycode = keycode
|
||||
key.keycode = keycode
|
||||
key.pressed = true
|
||||
return key
|
||||
|
||||
|
||||
func test_every_screen_is_reachable_from_the_main_menu_and_back() -> void:
|
||||
menus.show_screen("main", false)
|
||||
assert_eq(menus.current, "main")
|
||||
for pair: Array in [["Practice against bots", "practice"], ["Join a server", "join"], ["Settings", "settings"]]:
|
||||
_press("main", pair[0])
|
||||
assert_eq(menus.current, pair[1])
|
||||
assert_true((menus.screens[pair[1]] as Control).visible)
|
||||
assert_false((menus.screens["main"] as Control).visible, "one screen at a time")
|
||||
menus.back()
|
||||
assert_eq(menus.current, "main", "back from %s" % pair[1])
|
||||
var quit: Array[bool] = [false]
|
||||
menus.quit_requested.connect(func() -> void: quit[0] = true)
|
||||
_press("main", "Quit")
|
||||
assert_true(quit[0])
|
||||
|
||||
|
||||
func test_every_screen_takes_keyboard_focus_and_escape_goes_back() -> void:
|
||||
for screen: String in Menus.SCREENS:
|
||||
menus.show_screen(screen, false)
|
||||
await tree.process_frame
|
||||
var focused: Control = menus.get_viewport().gui_get_focus_owner()
|
||||
assert_not_null(focused, "%s focuses something" % screen)
|
||||
if focused != null:
|
||||
assert_true(menus.screens[screen].is_ancestor_of(focused), "%s's focus is on its own screen" % screen)
|
||||
menus.show_screen("main", false)
|
||||
_press("main", "Settings")
|
||||
await tree.process_frame
|
||||
var cancel: InputEventAction = InputEventAction.new()
|
||||
cancel.action = "ui_cancel"
|
||||
cancel.pressed = true
|
||||
menus._unhandled_input(cancel)
|
||||
assert_eq(menus.current, "main", "Escape went back")
|
||||
|
||||
|
||||
func test_focus_moves_through_the_main_menu_with_the_arrow_keys() -> void:
|
||||
menus.show_screen("main", false)
|
||||
await tree.process_frame
|
||||
var seen: Array[String] = []
|
||||
var focused: Control = menus.get_viewport().gui_get_focus_owner()
|
||||
for _step: int in 4:
|
||||
assert_not_null(focused)
|
||||
if focused == null:
|
||||
return
|
||||
seen.append((focused as Button).text)
|
||||
var next: Control = focused.find_valid_focus_neighbor(SIDE_BOTTOM)
|
||||
if next == null:
|
||||
break
|
||||
next.grab_focus()
|
||||
focused = next
|
||||
assert_eq(seen, ["Practice against bots", "Join a server", "Settings", "Quit"] as Array[String])
|
||||
|
||||
|
||||
func test_rebinding_in_the_menu_detects_conflicts() -> void:
|
||||
menus.show_screen("settings", false)
|
||||
menus.listen_for("jump")
|
||||
assert_eq(menus.listening_for, "jump")
|
||||
menus._unhandled_input(_key(KEY_W))
|
||||
assert_eq(menus.listening_for, "", "stopped listening")
|
||||
assert_eq(menus.settings.bindings.code_of("jump"), KEY_SPACE, "W is forward's: refused")
|
||||
menus.listen_for("jump")
|
||||
menus._unhandled_input(_key(KEY_F))
|
||||
assert_eq(menus.settings.bindings.code_of("jump"), KEY_F)
|
||||
assert_eq(GameSettings.load_from(PATH).bindings.code_of("jump"), KEY_F, "saved at once")
|
||||
menus.listen_for("jump")
|
||||
menus._unhandled_input(_key(KEY_ESCAPE))
|
||||
assert_eq(menus.settings.bindings.code_of("jump"), KEY_F, "Escape left it")
|
||||
assert_eq(menus.current, "settings", "and stayed on the screen")
|
||||
_press("settings", "Put every key back")
|
||||
assert_eq(menus.settings.bindings.code_of("jump"), KEY_SPACE)
|
||||
|
||||
|
||||
func test_settings_controls_change_and_save_the_settings() -> void:
|
||||
menus.show_screen("main", false)
|
||||
_press("main", "Settings")
|
||||
menus._sensitivity.value = 2.0
|
||||
menus._invert.button_pressed = true
|
||||
menus._quality.select(0)
|
||||
menus._quality.item_selected.emit(0)
|
||||
(menus._volumes["music"] as HSlider).value = 0.25
|
||||
menus._max_fps.select(2)
|
||||
menus._max_fps.item_selected.emit(2)
|
||||
menus._print_pass.button_pressed = false
|
||||
menus.back()
|
||||
var saved: GameSettings = GameSettings.load_from(PATH)
|
||||
assert_near(saved.mouse.mouse_sensitivity, 2.0, 0.0001)
|
||||
assert_true(saved.mouse.invert_y)
|
||||
assert_eq(saved.quality, 0)
|
||||
assert_near(saved.music_volume, 0.25, 0.0001)
|
||||
assert_eq(saved.max_fps, GameSettings.FRAME_CAPS[2])
|
||||
assert_false(saved.print_pass)
|
||||
# And the next time the screen opens, it shows them.
|
||||
var reopened: Menus = Menus.new()
|
||||
reopened.use_settings(saved, PATH)
|
||||
assert_near(reopened._sensitivity.value, 2.0, 0.0001)
|
||||
assert_eq(reopened._quality.selected, 0)
|
||||
reopened.free()
|
||||
|
||||
|
||||
func test_practice_and_join_say_what_was_asked() -> void:
|
||||
var asked: Array = []
|
||||
menus.practice_requested.connect(func(bots: int, difficulty: int) -> void: asked.append(["practice", bots, difficulty]))
|
||||
menus.join_requested.connect(func(host: String, port: int, player_name: String) -> void: asked.append(["join", host, port, player_name]))
|
||||
menus.show_screen("practice", false)
|
||||
menus._bots.value = 5
|
||||
menus._difficulty.select(1)
|
||||
_press("practice", "Set out")
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0])
|
||||
menus.show_screen("join", false)
|
||||
menus._name.text = "Wren"
|
||||
menus._address.text = "not a port:x"
|
||||
_press("join", "Join this address")
|
||||
assert_true(asked.is_empty(), "a bad address isn't joined")
|
||||
assert_true(menus._join_note.text.contains("isn't an address"))
|
||||
menus._address.text = "127.0.0.1:24999"
|
||||
_press("join", "Join this address")
|
||||
assert_eq(asked.pop_back(), ["join", "127.0.0.1", 24999, "Wren"])
|
||||
assert_eq(GameSettings.load_from(PATH).last_server, "127.0.0.1:24999")
|
||||
# A found server, chosen from the list.
|
||||
menus.show_servers([
|
||||
{"name": "Old", "players": 9, "max_players": 24, "address": "10.0.0.9", "port": 24650, "source": "lan", "compatible": false},
|
||||
{"name": "Harbour", "players": 3, "max_players": 24, "address": "127.0.0.1", "port": 24651, "source": "lan", "compatible": true},
|
||||
] as Array[Dictionary])
|
||||
menus._servers.select(0)
|
||||
_press("join", "Join the chosen server")
|
||||
assert_true(asked.is_empty(), "another version can't be joined")
|
||||
menus._servers.select(1)
|
||||
_press("join", "Join the chosen server")
|
||||
assert_eq(asked.pop_back(), ["join", "127.0.0.1", 24651, "Wren"])
|
||||
|
||||
|
||||
func test_results_say_where_you_placed() -> void:
|
||||
menus.show_results(1, 24, 3, ["Ada drowned"] as Array[String])
|
||||
assert_eq(menus.current, "results")
|
||||
assert_eq(menus._results_title.text, "Last on dry ground")
|
||||
assert_true(menus._results_body.text.contains("Eliminations: 3"))
|
||||
menus.show_results(7, 24, 0, [] as Array[String])
|
||||
assert_eq(menus._results_title.text, "Placed 7 of 24")
|
||||
|
||||
|
||||
func test_the_shell_goes_from_the_menu_to_a_match_and_back() -> void:
|
||||
menus.free()
|
||||
var shell: AppShell = AppShell.new(GameSettings.new(), PATH)
|
||||
shell.grab_mouse = false
|
||||
tree.root.add_child(shell)
|
||||
assert_eq(shell.menus.current, "main")
|
||||
shell.menus.settings.practice_bots = 3
|
||||
_press_in(shell.menus, "main", "Practice against bots")
|
||||
_press_in(shell.menus, "practice", "Set out")
|
||||
assert_not_null(shell.session, "a match began")
|
||||
assert_not_null(shell.session.local, "offline")
|
||||
assert_false(shell.menus.visible, "the menus are out of the way")
|
||||
for _frame: int in 30:
|
||||
shell.session.pump(1.0 / 30.0)
|
||||
shell.watch_match()
|
||||
assert_true(shell.session.game.world != null, "the world arrived")
|
||||
# Escape: the pause menu, and the player's keys stop.
|
||||
shell.session.pause_requested.emit()
|
||||
assert_eq(shell.menus.current, "pause")
|
||||
assert_true(shell.session.paused)
|
||||
_press_in(shell.menus, "pause", "Settings")
|
||||
assert_eq(shell.menus.current, "settings")
|
||||
shell.menus.back()
|
||||
assert_eq(shell.menus.current, "pause", "settings goes back to the pause menu")
|
||||
_press_in(shell.menus, "pause", "Back to the match")
|
||||
assert_false(shell.session.paused)
|
||||
assert_false(shell.menus.visible)
|
||||
# Leaving: back to the main menu with no match.
|
||||
shell.pause()
|
||||
_press_in(shell.menus, "pause", "Leave the match")
|
||||
assert_null(shell.session)
|
||||
assert_eq(shell.menus.current, "main")
|
||||
shell.free()
|
||||
|
||||
|
||||
func test_the_shell_shows_results_when_a_match_you_played_ends() -> void:
|
||||
menus.free()
|
||||
var shell: AppShell = AppShell.new(GameSettings.new(), PATH)
|
||||
shell.grab_mouse = false
|
||||
tree.root.add_child(shell)
|
||||
var rules: MatchRules = MatchRules.new()
|
||||
rules.max_players = 2
|
||||
rules.min_players = 1
|
||||
rules.lobby_ticks = 2
|
||||
rules.countdown_ticks = 2
|
||||
rules.results_ticks = 600
|
||||
var practice: ClientSession = ClientSession.new()
|
||||
practice.play_offline(4, 1, rules)
|
||||
shell.adopt(practice)
|
||||
var game: ClientGame = practice.game
|
||||
var server: Match = practice.local.loop.match_flow
|
||||
var frames: int = 0
|
||||
while not game.playing() and frames < 400:
|
||||
practice.pump(1.0 / 30.0)
|
||||
shell.watch_match()
|
||||
frames += 1
|
||||
assert_true(game.playing(), "in the match")
|
||||
# The bot falls to this player, and the match ends with them on top.
|
||||
var bot_handle: int = -1
|
||||
for handle: int in server.participants:
|
||||
if handle != LocalServer.HANDLE:
|
||||
bot_handle = handle
|
||||
var bot: SimEntity = server.sim.entities.find(int(server.entity_of[bot_handle]))
|
||||
bot.health = 0
|
||||
bot.last_attacker = int(server.entity_of[LocalServer.HANDLE])
|
||||
bot.last_cause = SimEntity.CAUSE_WEAPON
|
||||
while game.match_phase != Match.RESULTS and frames < 800:
|
||||
practice.pump(1.0 / 30.0)
|
||||
shell.watch_match()
|
||||
frames += 1
|
||||
assert_eq(game.match_phase, Match.RESULTS)
|
||||
assert_eq(shell.menus.current, "results")
|
||||
assert_eq(shell.menus._results_title.text, "Last on dry ground")
|
||||
assert_true(shell.menus._results_body.text.contains("Eliminations: 1"), shell.menus._results_body.text)
|
||||
_press_in(shell.menus, "results", "Back to the main menu")
|
||||
assert_eq(shell.menus.current, "main")
|
||||
shell.free()
|
||||
|
||||
|
||||
func _press_in(on: Menus, screen: String, text: String) -> void:
|
||||
var buttons: Dictionary = on.buttons_of(screen)
|
||||
assert_true(buttons.has(text), "%s has a '%s' button (has %s)" % [screen, text, buttons.keys()])
|
||||
if buttons.has(text):
|
||||
(buttons[text] as Button).pressed.emit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dlu5xen3omblh
|
||||
Reference in New Issue
Block a user