v0.9.0-alpha local build. Adds per-guest story vignettes, a scrollable Guest Book story section, live text scaling, Android haptics, a difficulty picker with descriptions, six repeating cosmetic hotel events, and isolated free play using verified symmetry variants. Save format v7 with automatic migration. QA is 9/9 including the free-play uniqueness suite.
380 lines
14 KiB
GDScript
380 lines
14 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless UI/save integration test.
|
|
## <godot> --headless --path . --script res://tools/ui_test.gd
|
|
|
|
var failures := 0
|
|
var frames = null
|
|
|
|
|
|
func _init() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures += 1
|
|
print("FAIL: ", message)
|
|
|
|
|
|
func _run() -> void:
|
|
var err := change_scene_to_file("res://scenes/Main.tscn")
|
|
if err != OK:
|
|
print("FAIL: could not load Main")
|
|
quit(1)
|
|
return
|
|
|
|
await process_frame
|
|
await process_frame
|
|
|
|
var main = current_scene
|
|
var save = root.get_node_or_null("SaveGame")
|
|
_check(save != null, "SaveGame autoload missing")
|
|
if save == null:
|
|
quit(1)
|
|
return
|
|
|
|
# Resolve at runtime so Frames.gd does not compile before autoloads exist.
|
|
frames = load("res://scripts/Frames.gd")
|
|
_check(frames != null, "Frames script missing")
|
|
if frames == null:
|
|
quit(1)
|
|
return
|
|
|
|
_test_save_defaults(save)
|
|
save.reset_progress()
|
|
await _test_daily_and_frames(save, main)
|
|
|
|
main.game.start_level(0)
|
|
await process_frame
|
|
|
|
save.set_setting("patterns", false)
|
|
_check(not main.game.board.show_patterns, "patterns setting did not reach Board")
|
|
save.set_setting("patterns", true)
|
|
_check(main.game.board.show_patterns, "patterns setting did not restore")
|
|
|
|
save.set_setting("show_timer", false)
|
|
main.show_screen("game")
|
|
await process_frame
|
|
_check(not main.game.timer_label.visible, "show_timer setting did not hide timer")
|
|
save.set_setting("show_timer", true)
|
|
|
|
save.set_setting("hold_seconds", 0.50)
|
|
_check(abs(main.game.board.hold_seconds - 0.50) < 0.001, "hold_seconds did not reach Board")
|
|
save.set_setting("hold_seconds", 0.35)
|
|
|
|
_test_placement_modes(save, main.game.board)
|
|
|
|
main.open_settings("home")
|
|
await process_frame
|
|
_check(
|
|
main.settings_sheet.toggles["double_tap_place"].mouse_filter == Control.MOUSE_FILTER_PASS,
|
|
"settings rows should pass swipes to the ScrollContainer"
|
|
)
|
|
main.close_settings()
|
|
|
|
var unlocked: String = save.complete_room("room-01", 1)
|
|
_check(unlocked == "pepper", "room 1 should unlock Pepper")
|
|
_check(save.is_guest_unlocked("pepper"), "Pepper should be unlocked")
|
|
_check(save.is_guest_unlocked("miso"), "Miso should be unlocked as a resident")
|
|
|
|
main.show_screen("guest_book")
|
|
await process_frame
|
|
await process_frame
|
|
_check(main.guest_book != null, "Guest Book missing")
|
|
if main.guest_book != null and main.guest_book.progress_label != null:
|
|
_check(main.guest_book.progress_label.text.find("6/25") >= 0, "Guest Book progress should be 6/25")
|
|
_test_guest_book_input(main.guest_book)
|
|
_check(main.guest_book.grid.mouse_filter == Control.MOUSE_FILTER_PASS, "guest grid should pass swipes")
|
|
var first_card = main.guest_book.grid.get_child(0)
|
|
_check(first_card.mouse_filter == Control.MOUSE_FILTER_PASS, "guest cards should pass swipes")
|
|
|
|
main.show_screen("rules")
|
|
await process_frame
|
|
var tutorial_board = main.rulebook.tutorial_board
|
|
_check(tutorial_board != null, "Tutorial board missing")
|
|
if tutorial_board != null:
|
|
var rule_scrolls = main.rulebook.find_children("*", "ScrollContainer", true, false)
|
|
_check(rule_scrolls.size() > 0, "Rules ScrollContainer missing")
|
|
if rule_scrolls.size() > 0:
|
|
var rules_content = rule_scrolls[0].get_child(0)
|
|
_check(rules_content.mouse_filter == Control.MOUSE_FILTER_PASS, "rules content should pass swipes")
|
|
_check(tutorial_board.mouse_filter == Control.MOUSE_FILTER_STOP, "tutorial board should keep its own input")
|
|
for i in range(8):
|
|
tutorial_board.hint()
|
|
await process_frame
|
|
_check(Rules.is_valid(tutorial_board.cells, tutorial_board.regions), "Tutorial puzzle did not solve")
|
|
|
|
save.reset_progress()
|
|
save.set_setting("patterns", true)
|
|
save.set_setting("show_timer", true)
|
|
save.set_setting("reduce_motion", false)
|
|
save.set_setting("hold_seconds", 0.35)
|
|
save.set_setting("double_tap_place", true)
|
|
|
|
print("UI TEST: ", "PASS" if failures == 0 else "FAIL (%d)" % failures)
|
|
quit(0 if failures == 0 else 1)
|
|
|
|
|
|
func _test_daily_and_frames(save, main) -> void:
|
|
var today := Daily.today_key()
|
|
var yesterday := Daily.key_from_day_number(Daily.day_number(today) - 1)
|
|
var daily: Dictionary = save._default_daily()
|
|
daily["last_completed"] = yesterday
|
|
daily["streak"] = 2
|
|
daily["best_streak"] = 2
|
|
save.data["daily"] = daily
|
|
|
|
_check(save.complete_daily(today), "today's daily should count")
|
|
_check(int(save.daily_data().get("streak", 0)) == 3, "consecutive daily should extend streak")
|
|
_check(save.daily_streak() == 3, "daily streak should be alive")
|
|
_check(save.best_streak() == 3, "best streak should update")
|
|
_check(not save.complete_daily(today), "same day should not count twice")
|
|
_check(int(save.daily_data().get("streak", 0)) == 3, "replay should not change streak")
|
|
|
|
var older := Daily.key_from_day_number(Daily.day_number(today) - 3)
|
|
daily = save._default_daily()
|
|
daily["last_completed"] = older
|
|
daily["streak"] = 9
|
|
daily["best_streak"] = 9
|
|
save.data["daily"] = daily
|
|
save.complete_daily(today)
|
|
_check(int(save.daily_data().get("streak", 0)) == 1, "a gap should reset the streak")
|
|
_check(save.best_streak() == 9, "best streak should survive a reset")
|
|
|
|
var index := Daily.level_index(30, today)
|
|
_check(index >= 0 and index < 30, "daily level index should be in range")
|
|
_check(index == Daily.level_index(30, today), "daily level index should be stable")
|
|
save.data["daily"] = save._default_daily()
|
|
save.save_game()
|
|
|
|
save.reset_progress()
|
|
_check(frames.is_unlocked("plain"), "plain frame should always be available")
|
|
_check(not frames.is_unlocked("paper"), "Paper should need rooms")
|
|
for i in range(5):
|
|
save.data["completed_rooms"].append("room-%02d" % i)
|
|
save.save_game()
|
|
_check(frames.is_unlocked("paper"), "five rooms should unlock Paper")
|
|
_check(not frames.is_unlocked("bell"), "Bellhop should still be locked")
|
|
var stats: Dictionary = save.daily_data()
|
|
stats["best_streak"] = 3
|
|
save.data["daily"] = stats
|
|
save.save_game()
|
|
_check(frames.is_unlocked("regular"), "a 3-day best streak should unlock Regular")
|
|
save.select_frame("regular")
|
|
save.load_game()
|
|
_check(save.selected_frame() == "regular", "frame selection should persist")
|
|
|
|
main.show_screen("profile")
|
|
await process_frame
|
|
_check(main.profile != null, "Profile screen missing")
|
|
if main.profile != null:
|
|
main.profile._set_tab("frame")
|
|
await process_frame
|
|
_check(
|
|
main.profile.frame_grid.get_child_count() == frames.all().size(),
|
|
"Profile should show every frame"
|
|
)
|
|
_check(
|
|
main.profile.frame_grid.get_child(0).mouse_filter == Control.MOUSE_FILTER_PASS,
|
|
"frame cards should pass swipes"
|
|
)
|
|
# Regression: pressing a card must not free that card while its
|
|
# `pressed` signal is still on the stack.
|
|
var regular_index := -1
|
|
for i in frames.all().size():
|
|
if str(frames.all()[i].get("id", "")) == "regular":
|
|
regular_index = i
|
|
if regular_index >= 0:
|
|
main.profile.frame_grid.get_child(regular_index).pressed.emit()
|
|
await process_frame
|
|
await process_frame
|
|
_check(main.profile.pending_frame == "regular", "frame card should update the preview")
|
|
main.profile._on_confirm()
|
|
await process_frame
|
|
_check(save.selected_frame() == "regular", "confirm should apply the frame")
|
|
_check(
|
|
main.profile.frame_grid.get_child_count() == frames.all().size(),
|
|
"frame grid should stay stable after selection"
|
|
)
|
|
main.profile._set_tab("avatar")
|
|
await process_frame
|
|
_check(main.profile.frame_grid.get_child_count() > 10, "avatar tab should list portraits")
|
|
main.home.streak_pressed.emit()
|
|
await process_frame
|
|
_check(main.current == "streak", "streak button should open the streak screen")
|
|
main.show_screen("home")
|
|
main.home.daily_pressed.emit()
|
|
await process_frame
|
|
_check(main.game.daily_mode, "daily button should start daily mode")
|
|
_check(main.game.level_label.text == "Daily room", "daily mode should label the room")
|
|
main.show_screen("home", false)
|
|
|
|
save.data["completed_rooms"] = []
|
|
save.data["daily"] = save._default_daily()
|
|
save.select_frame("plain")
|
|
|
|
|
|
func _test_save_defaults(save) -> void:
|
|
# A fresh save starts in double-tap mode at version 7.
|
|
var abs_path := ProjectSettings.globalize_path(save.PATH)
|
|
if FileAccess.file_exists(save.PATH):
|
|
DirAccess.remove_absolute(abs_path)
|
|
save.load_game()
|
|
_check(int(save.data.get("version", 0)) == 7, "fresh saves should be version 7")
|
|
_check(bool(save.get_setting("double_tap_place")), "fresh saves should default to double-tap")
|
|
|
|
# A version 1 save with hold selected migrates to double-tap once.
|
|
var old: Dictionary = save._default_data()
|
|
old["version"] = 1
|
|
old["settings"]["double_tap_place"] = false
|
|
var file := FileAccess.open(save.PATH, FileAccess.WRITE)
|
|
file.store_string(JSON.stringify(old, "\t"))
|
|
file.close()
|
|
|
|
save.load_game()
|
|
_check(int(save.data.get("version", 0)) == 7, "version 1 saves should migrate to version 7")
|
|
_check(bool(save.get_setting("double_tap_place")), "version 1 saves should migrate to double-tap")
|
|
|
|
|
|
func _find_empty(board: Board) -> Vector2i:
|
|
for r in board.n:
|
|
for c in board.n:
|
|
if (
|
|
int(board.cells[r][c]) == Board.EMPTY
|
|
and not board.fixed.has(Vector2i(r, c))
|
|
and not board.auto_x[r][c]
|
|
):
|
|
return Vector2i(r, c)
|
|
return Vector2i(-1, -1)
|
|
|
|
|
|
func _test_placement_modes(save, board: Board) -> void:
|
|
board.restart()
|
|
save.set_setting("double_tap_place", true)
|
|
_check(board.double_tap_place, "double_tap_place did not reach Board")
|
|
|
|
# A first tap waits; a second tap on the same cell checks a guest in.
|
|
var cell := _find_empty(board)
|
|
board._handle_tap(cell)
|
|
_check(int(board.cells[cell.x][cell.y]) == Board.EMPTY, "first tap should wait in double-tap mode")
|
|
board._handle_tap(cell)
|
|
_check(int(board.cells[cell.x][cell.y]) == Board.RAT, "double tap should check a guest in")
|
|
board._handle_tap(cell)
|
|
board._handle_tap(cell)
|
|
_check(int(board.cells[cell.x][cell.y]) == Board.EMPTY, "double tap on a guest should check them out")
|
|
|
|
# A lone tap still marks an X once the double-tap window passes.
|
|
var cell2 := _find_empty(board)
|
|
board._handle_tap(cell2)
|
|
board.pending_tap_at -= Board.DOUBLE_TAP_MS + 1
|
|
board._process(0.0)
|
|
_check(int(board.cells[cell2.x][cell2.y]) == Board.X, "single tap should mark X after the window")
|
|
|
|
# Holding must not place a guest while double-tap mode is on.
|
|
board.press_cell = cell2
|
|
board.press_elapsed = 0.0
|
|
board.hold_fired = false
|
|
board._process(1.0)
|
|
_check(int(board.cells[cell2.x][cell2.y]) == Board.X, "hold should not place in double-tap mode")
|
|
board.press_cell = Vector2i(-1, -1)
|
|
board.hold_fired = false
|
|
|
|
# Right-click still checks a guest in and out in double-tap mode.
|
|
board.size = Vector2(320, 320)
|
|
board._update_layout()
|
|
var cell3 := _find_empty(board)
|
|
_right_click(board, cell3)
|
|
_check(int(board.cells[cell3.x][cell3.y]) == Board.RAT, "right-click should check in during double-tap mode")
|
|
_right_click(board, cell3)
|
|
_check(int(board.cells[cell3.x][cell3.y]) == Board.EMPTY, "right-click should check out during double-tap mode")
|
|
|
|
# Hold mode still works when the setting is off.
|
|
save.set_setting("double_tap_place", false)
|
|
_check(not board.double_tap_place, "double_tap_place did not turn off")
|
|
board.restart()
|
|
var cell4 := _find_empty(board)
|
|
board.press_cell = cell4
|
|
board.press_elapsed = 0.0
|
|
board.hold_fired = false
|
|
board._process(0.60)
|
|
_check(int(board.cells[cell4.x][cell4.y]) == Board.RAT, "hold should place in hold mode")
|
|
board.press_cell = Vector2i(-1, -1)
|
|
board.hold_fired = false
|
|
|
|
# Single tap marks X in hold mode.
|
|
var cell5 := _find_empty(board)
|
|
board.size = Vector2(320, 320)
|
|
board._update_layout()
|
|
_left_tap(board, cell5)
|
|
_check(int(board.cells[cell5.x][cell5.y]) == Board.X, "single tap should mark X in hold mode")
|
|
|
|
# The setting survives a save/load round trip.
|
|
save.set_setting("double_tap_place", true)
|
|
save.load_game()
|
|
_check(bool(save.get_setting("double_tap_place")), "double_tap_place should persist")
|
|
save.set_setting("double_tap_place", true)
|
|
board.restart()
|
|
|
|
|
|
func _left_tap(board: Board, cell: Vector2i) -> void:
|
|
var pos := board._cell_rect(cell.x, cell.y).get_center()
|
|
var down := InputEventMouseButton.new()
|
|
down.button_index = MOUSE_BUTTON_LEFT
|
|
down.pressed = true
|
|
down.position = pos
|
|
board._gui_input(down)
|
|
var up := InputEventMouseButton.new()
|
|
up.button_index = MOUSE_BUTTON_LEFT
|
|
up.pressed = false
|
|
up.position = pos
|
|
board._gui_input(up)
|
|
|
|
|
|
func _right_click(board: Board, cell: Vector2i) -> void:
|
|
var event := InputEventMouseButton.new()
|
|
event.button_index = MOUSE_BUTTON_RIGHT
|
|
event.pressed = true
|
|
event.position = board._cell_rect(cell.x, cell.y).get_center()
|
|
board._gui_input(event)
|
|
|
|
|
|
func _test_guest_book_input(book) -> void:
|
|
var guest: Dictionary = Guests.all()[0]
|
|
book.detail_layer.visible = false
|
|
|
|
# Dragging across a card is a scroll, not a tap.
|
|
_mouse(book, guest, Vector2(100, 300), true)
|
|
var motion := InputEventMouseMotion.new()
|
|
motion.global_position = Vector2(170, 300)
|
|
book._on_card_input(motion, guest, false)
|
|
_mouse(book, guest, Vector2(170, 300), false)
|
|
_check(not book.detail_layer.visible, "dragging should not open a guest card")
|
|
|
|
# A fling settling must not turn into a tap either.
|
|
book._suppress_until = Time.get_ticks_msec() + 1000
|
|
_mouse(book, guest, Vector2(100, 300), true)
|
|
_mouse(book, guest, Vector2(100, 300), false)
|
|
_check(not book.detail_layer.visible, "post-scroll tap should be ignored")
|
|
|
|
# A short, stationary tap opens the card.
|
|
book._suppress_until = 0
|
|
_mouse(book, guest, Vector2(100, 300), true)
|
|
_mouse(book, guest, Vector2(100, 300), false)
|
|
_check(book.detail_layer.visible, "a clean tap should open a guest card")
|
|
|
|
# The opening tap must not immediately close the sheet.
|
|
book._try_close_detail()
|
|
_check(book.detail_layer.visible, "close should be guarded right after opening")
|
|
book._detail_opened_at -= 300
|
|
book._try_close_detail()
|
|
_check(not book.detail_layer.visible, "close should work after the guard")
|
|
|
|
|
|
func _mouse(book, guest: Dictionary, pos: Vector2, pressed: bool) -> void:
|
|
var event := InputEventMouseButton.new()
|
|
event.button_index = MOUSE_BUTTON_LEFT
|
|
event.pressed = pressed
|
|
event.global_position = pos
|
|
book._on_card_input(event, guest, false)
|