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.
614 lines
24 KiB
GDScript
614 lines
24 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless core QA: save migration, daily logic, frames, and game data.
|
|
## <godot> --headless --path . --script res://tools/qa_core.gd --quit-after 1200
|
|
##
|
|
## This suite only ever replaces the game's own save file (SaveGame.PATH).
|
|
## It leaves every other file alone and restores a clean save before it exits.
|
|
|
|
var failures := 0
|
|
var frames = null
|
|
var avatars = null
|
|
|
|
|
|
func _init() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures += 1
|
|
print("FAIL: ", message)
|
|
|
|
|
|
func _note(message: String) -> void:
|
|
print("QA CORE: ", message)
|
|
|
|
|
|
func _run() -> void:
|
|
var save = root.get_node_or_null("SaveGame")
|
|
_check(save != null, "SaveGame autoload missing")
|
|
if save == null:
|
|
_finish()
|
|
return
|
|
|
|
# Resolve Frames at runtime: a static reference compiles it before the
|
|
# SaveGame autoload is registered when launched with --script.
|
|
frames = load("res://scripts/Frames.gd")
|
|
_check(frames != null, "Frames script missing")
|
|
avatars = load("res://scripts/Avatars.gd")
|
|
_check(avatars != null, "Avatars script missing")
|
|
if frames == null or avatars == null:
|
|
_finish()
|
|
return
|
|
|
|
_test_save_migrations(save)
|
|
_test_daily(save)
|
|
_test_frames(save)
|
|
_test_avatars_and_streak(save)
|
|
_test_v6_features(save)
|
|
_test_game_data(save)
|
|
_test_icons()
|
|
|
|
_reset_to_clean(save)
|
|
_finish()
|
|
|
|
|
|
func _test_avatars_and_streak(save) -> void:
|
|
_note("5. avatars and streak view")
|
|
var list: Array = avatars.all()
|
|
_check(list.size() == 26, "Crumb plus 25 guests should be selectable")
|
|
_check(avatars.is_unlocked("crumb"), "Crumb should always be available")
|
|
_check(avatars.by_id("does-not-exist").is_empty(), "unknown avatar should resolve to nothing")
|
|
var locked_id := ""
|
|
for entry in list:
|
|
var id := str(entry.get("id", ""))
|
|
if id != "crumb" and not avatars.is_unlocked(id):
|
|
locked_id = id
|
|
break
|
|
_check(locked_id != "", "a guest avatar should be locked with no progress")
|
|
_check(not avatars.requirement_text(locked_id).is_empty(), "locked avatar should show a requirement")
|
|
|
|
save.reset_progress()
|
|
save.select_avatar("crumb")
|
|
save.load_game()
|
|
_check(save.selected_avatar() == "crumb", "avatar selection should persist")
|
|
|
|
save.apply_profile("crumb", "gold")
|
|
save.load_game()
|
|
_check(save.selected_avatar() == "crumb" and save.selected_frame() == "gold", "profile should save both choices at once")
|
|
|
|
var keys: Array = Daily.week_keys()
|
|
_check(keys.size() == 7, "the streak week should have seven days")
|
|
_check(Daily.weekday_labels().size() == 7, "the streak week should have seven labels")
|
|
_check(Daily.goal_text(0).find("Regular") >= 0, "early streak goal should point to Regular")
|
|
_check(Daily.goal_text(4).find("Night Owl") >= 0, "mid streak goal should point to Night Owl")
|
|
_check(Daily.goal_text(7).find("gift") >= 0, "completed week should show the gift goal")
|
|
|
|
var today := Daily.today_key()
|
|
save.data["daily"] = save._default_daily()
|
|
save.complete_daily(today)
|
|
_check(save.daily_history().has(today), "completing a daily should record history")
|
|
save.complete_daily(today)
|
|
_check(save.daily_history().size() == 1, "replaying a day should not duplicate history")
|
|
_reset_to_clean(save)
|
|
|
|
|
|
func _test_icons() -> void:
|
|
_note("6. icon assets")
|
|
# Load at runtime so UI.gd does not compile before the autoload exists.
|
|
var ui_script = load("res://scripts/UI.gd")
|
|
_check(ui_script != null, "UI script missing")
|
|
if ui_script == null:
|
|
return
|
|
|
|
var dir := DirAccess.open("res://assets/icons")
|
|
_check(dir != null, "icons directory missing")
|
|
if dir == null:
|
|
return
|
|
|
|
var count := 0
|
|
for file in dir.get_files():
|
|
if not file.ends_with(".svg"):
|
|
continue
|
|
count += 1
|
|
var texture = load("res://assets/icons/" + file)
|
|
_check(texture != null, "icon failed to load: %s" % file)
|
|
if texture != null:
|
|
var size: Vector2 = texture.get_size()
|
|
_check(size.x >= 96 and size.y >= 96, "icon too small: %s (%dx%d)" % [file, size.x, size.y])
|
|
_check(count >= 10, "expected the full icon set")
|
|
|
|
var button = ui_script.round_button("res://assets/icons/arrow-left.svg", 44)
|
|
_check(button.expand_icon, "round buttons should expand high-res icons")
|
|
var style := button.get_theme_stylebox("normal") as StyleBoxFlat
|
|
_check(style != null and style.content_margin_left >= 8, "round buttons should use margins to keep icon size")
|
|
var small_icon = ui_script.icon("res://assets/icons/settings.svg", 18)
|
|
_check(small_icon.texture.get_size().x >= 96, "UI.icon should use high-res textures")
|
|
button.free()
|
|
small_icon.free()
|
|
|
|
|
|
func _finish() -> void:
|
|
if failures == 0:
|
|
print("QA CORE: PASS")
|
|
quit(0)
|
|
else:
|
|
print("QA CORE: FAIL (%d)" % failures)
|
|
quit(1)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Helpers
|
|
# ---------------------------------------------------------------------------
|
|
|
|
func _write_save(save, dict: Dictionary) -> void:
|
|
var file := FileAccess.open(save.PATH, FileAccess.WRITE)
|
|
if file == null:
|
|
_check(false, "could not open save path for writing: %s" % save.PATH)
|
|
return
|
|
file.store_string(JSON.stringify(dict, "\t"))
|
|
file.close()
|
|
|
|
|
|
func _remove_save(save) -> void:
|
|
if FileAccess.file_exists(save.PATH):
|
|
var err := DirAccess.remove_absolute(ProjectSettings.globalize_path(save.PATH))
|
|
if err != OK:
|
|
_check(false, "could not remove test save file")
|
|
|
|
|
|
func _reset_to_clean(save) -> void:
|
|
save.data = save._default_data()
|
|
save.save_game()
|
|
save.load_game()
|
|
|
|
|
|
func _same_value(a, b) -> bool:
|
|
if typeof(a) == TYPE_INT or typeof(a) == TYPE_FLOAT:
|
|
if typeof(b) == TYPE_INT or typeof(b) == TYPE_FLOAT:
|
|
return absf(float(a) - float(b)) < 0.0001
|
|
return false
|
|
if typeof(a) == TYPE_BOOL or typeof(b) == TYPE_BOOL:
|
|
return typeof(a) == TYPE_BOOL and typeof(b) == TYPE_BOOL and bool(a) == bool(b)
|
|
return str(a) == str(b)
|
|
|
|
|
|
func _is_default_daily(save, daily: Dictionary) -> bool:
|
|
var defaults: Dictionary = save._default_daily()
|
|
return (
|
|
str(daily.get("last_completed", "")) == str(defaults["last_completed"])
|
|
and _same_value(daily.get("streak", -1), defaults["streak"])
|
|
and _same_value(daily.get("best_streak", -1), defaults["best_streak"])
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 1. Save migration matrix
|
|
# ---------------------------------------------------------------------------
|
|
|
|
func _test_save_migrations(save) -> void:
|
|
_note("1. save migration matrix")
|
|
|
|
# (a) No save file at all -> fresh version-4 defaults.
|
|
_remove_save(save)
|
|
save.load_game()
|
|
_check(int(save.data.get("version", 0)) == 7, "fresh save should be version 7")
|
|
_check(bool(save.get_setting("double_tap_place")), "fresh save should default to double-tap")
|
|
_check(_is_default_daily(save, save.daily_data()), "fresh save should have default daily stats")
|
|
_check(save.selected_frame() == "plain", "fresh save should select the plain frame")
|
|
_check((save.data.get("completed_rooms") as Array).is_empty(), "fresh save should have no rooms")
|
|
_check((save.data.get("unlocked_guests") as Array).is_empty(), "fresh save should have no guests")
|
|
|
|
# (b) Version 1 with hold-to-place and no daily/frame keys -> migrate to v3.
|
|
var v1: Dictionary = save._default_data()
|
|
v1["version"] = 1
|
|
v1["settings"]["double_tap_place"] = false
|
|
v1.erase("daily")
|
|
v1.erase("profile_frame")
|
|
_write_save(save, v1)
|
|
save.load_game()
|
|
_check(int(save.data.get("version", 0)) == 7, "version 1 should migrate to version 7")
|
|
_check(bool(save.get_setting("double_tap_place")), "version 1 should migrate to double-tap")
|
|
_check(_is_default_daily(save, save.daily_data()), "version 1 missing daily should become defaults")
|
|
_check(save.selected_frame() == "plain", "version 1 missing frame should become plain")
|
|
|
|
# (c) Version 2 with hold-to-place -> stay on hold, gain v3 daily/frame data.
|
|
var v2: Dictionary = save._default_data()
|
|
v2["version"] = 2
|
|
v2["settings"]["double_tap_place"] = false
|
|
v2.erase("daily")
|
|
v2.erase("profile_frame")
|
|
_write_save(save, v2)
|
|
save.load_game()
|
|
_check(int(save.data.get("version", 0)) == 7, "version 2 should migrate to version 7")
|
|
_check(not bool(save.get_setting("double_tap_place")), "version 2 double_tap=false should stay false")
|
|
_check(_is_default_daily(save, save.daily_data()), "version 2 missing daily should become defaults")
|
|
_check(save.selected_frame() == "plain", "version 2 missing frame should become plain")
|
|
|
|
# (d) Valid JSON with the wrong top-level shape -> no crash, defaults restored.
|
|
var broken := FileAccess.open(save.PATH, FileAccess.WRITE)
|
|
if broken != null:
|
|
broken.store_string("[]")
|
|
broken.close()
|
|
else:
|
|
_check(false, "could not write wrong-shape save")
|
|
save.load_game()
|
|
_check(int(save.data.get("version", 0)) == 7, "wrong-shape save should restore version 7 defaults")
|
|
_check(bool(save.get_setting("double_tap_place")), "wrong-shape save should restore double-tap default")
|
|
_check(_is_default_daily(save, save.daily_data()), "wrong-shape save should restore daily defaults")
|
|
_check(save.selected_frame() == "plain", "wrong-shape save should restore plain frame")
|
|
_check((save.data.get("completed_rooms") as Array).is_empty(), "malformed JSON should have no rooms")
|
|
|
|
# (e) Missing individual setting keys are filled from DEFAULTS.
|
|
var partial: Dictionary = save._default_data()
|
|
partial["version"] = 4
|
|
partial["settings"] = {}
|
|
_write_save(save, partial)
|
|
save.load_game()
|
|
for key in save.DEFAULTS:
|
|
_check(save.data["settings"].has(key), "missing setting '%s' should be filled" % key)
|
|
_check(
|
|
_same_value(save.get_setting(key), save.DEFAULTS[key]),
|
|
"filled setting '%s' should match DEFAULTS" % key
|
|
)
|
|
|
|
# A version-4 save's explicit false must not be overwritten by a default.
|
|
var explicit_false: Dictionary = save._default_data()
|
|
explicit_false["version"] = 4
|
|
explicit_false["settings"]["double_tap_place"] = false
|
|
_write_save(save, explicit_false)
|
|
save.load_game()
|
|
_check(not bool(save.get_setting("double_tap_place")), "an explicit false should not be overwritten")
|
|
_check(bool(save.get_setting("patterns")), "unlisted settings should still be filled from DEFAULTS")
|
|
|
|
_reset_to_clean(save)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 2. Daily logic
|
|
# ---------------------------------------------------------------------------
|
|
|
|
func _test_daily(save) -> void:
|
|
_note("2. daily logic")
|
|
|
|
var today: String = Daily.today_key()
|
|
_check(today.length() == 10, "today key should be YYYY-MM-DD (10 chars)")
|
|
_check(today.substr(4, 1) == "-" and today.substr(7, 1) == "-", "today key separators should be dashes")
|
|
_check(
|
|
today.substr(0, 4).is_valid_int()
|
|
and today.substr(5, 2).is_valid_int()
|
|
and today.substr(8, 2).is_valid_int(),
|
|
"today key date parts should be numeric"
|
|
)
|
|
var now: Dictionary = Time.get_date_dict_from_system()
|
|
_check(
|
|
today == "%04d-%02d-%02d" % [int(now["year"]), int(now["month"]), int(now["day"])],
|
|
"today key should match the system's local date"
|
|
)
|
|
_check(Daily.day_number("") == 0, "an empty key should map to day 0")
|
|
_check(Daily.day_number("bad-key") == 0, "a malformed key should map to day 0")
|
|
|
|
# Round trip between date keys and day numbers.
|
|
var base: int = Daily.day_number(today)
|
|
_note(
|
|
"day_number(%s)=%d, key_from_day_number=%s"
|
|
% [today, base, Daily.key_from_day_number(base)]
|
|
)
|
|
_check(Daily.key_from_day_number(base) == today, "key_from_day_number(day_number(today)) should be today")
|
|
for delta in [1, 7, 30, 100, 400]:
|
|
var key: String = Daily.key_from_day_number(base + delta)
|
|
_check(
|
|
Daily.day_number(key) == base + delta,
|
|
"day_number(key_from_day_number(%d)) should round trip" % delta
|
|
)
|
|
|
|
# Level selection: stable, in range, and valid on 30 consecutive dates.
|
|
_check(Daily.level_index(0, today) == -1, "level_index should be -1 with no levels")
|
|
_check(Daily.level_index(-5, today) == -1, "level_index should be -1 with a negative level count")
|
|
var idx: int = Daily.level_index(30, today)
|
|
_check(idx >= 0 and idx < 30, "level_index(30) should be in range")
|
|
_check(idx == Daily.level_index(30, today), "level_index should be stable for the same date")
|
|
var all_valid := true
|
|
var distinct := {}
|
|
for d in range(30):
|
|
var key: String = Daily.key_from_day_number(base + d)
|
|
var i: int = Daily.level_index(30, key)
|
|
if i < 0 or i >= 30:
|
|
all_valid = false
|
|
distinct[i] = true
|
|
_check(all_valid, "30 consecutive dates should all produce valid daily indices")
|
|
_check(distinct.size() == 30, "30 consecutive dates should visit all 30 rooms")
|
|
_note("distinct daily levels across 30 consecutive days: %d" % distinct.size())
|
|
|
|
_reset_to_clean(save)
|
|
|
|
# Consecutive days extend the streak and mark today complete.
|
|
var yesterday: String = 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
|
|
var rooms_before: Array = (save.data["completed_rooms"] as Array).duplicate()
|
|
var guests_before: Array = (save.data["unlocked_guests"] as Array).duplicate()
|
|
_check(Daily.day_number(yesterday) == Daily.day_number(today) - 1, "yesterday key should be one day before today")
|
|
_check(save.complete_daily(today), "completing today's daily should count")
|
|
_check(int(save.daily_data().get("streak", 0)) == 3, "consecutive daily should extend the streak to 3")
|
|
_check(save.daily_streak() == 3, "daily_streak should report a live streak of 3")
|
|
_check(save.best_streak() == 3, "best_streak should rise to 3")
|
|
_check(save.daily_completed_today(), "daily_completed_today should be true")
|
|
_check((save.data["completed_rooms"] as Array) == rooms_before, "daily must not change completed_rooms")
|
|
_check((save.data["unlocked_guests"] as Array) == guests_before, "daily must not change unlocked_guests")
|
|
|
|
# Same-day replay and wrong dates do nothing.
|
|
_check(not save.complete_daily(today), "same-day replay should return false")
|
|
_check(int(save.daily_data().get("streak", 0)) == 3, "same-day replay should not change the streak")
|
|
_check(not save.complete_daily(yesterday), "an older date should not count")
|
|
_check(not save.complete_daily(""), "an empty key should not count")
|
|
_check(int(save.daily_data().get("streak", 0)) == 3, "rejected dates should not change the streak")
|
|
|
|
# A gap resets the current streak but keeps the best.
|
|
_reset_to_clean(save)
|
|
var older: String = 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
|
|
_check(save.complete_daily(today), "a daily after a gap should still count")
|
|
_check(int(save.daily_data().get("streak", 0)) == 1, "a gap should reset the streak to 1")
|
|
_check(save.best_streak() == 9, "best_streak should survive a gap")
|
|
|
|
# Best streak persists; a stale streak is reported as dead.
|
|
var best: int = save.best_streak()
|
|
save.data["daily"]["streak"] = 0
|
|
save.save_game()
|
|
save.load_game()
|
|
_check(save.best_streak() == best, "best_streak should persist through save/load")
|
|
_check(save.daily_streak() == 0, "a zero streak should be reported as 0")
|
|
save.data["daily"] = save._default_daily()
|
|
_check(not save.daily_completed_today(), "a fresh daily state should not be complete today")
|
|
_check(save.daily_streak() == 0, "a fresh daily state should have no live streak")
|
|
|
|
_reset_to_clean(save)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 3. Frames
|
|
# ---------------------------------------------------------------------------
|
|
|
|
func _test_frames(save) -> void:
|
|
_note("3. frames")
|
|
|
|
_reset_to_clean(save)
|
|
_check(frames.all().size() == 13, "there should be thirteen profile frames")
|
|
_check(frames.is_unlocked("plain"), "plain frame should always be unlocked")
|
|
_check(not frames.requirement_text("plain").is_empty(), "plain frame should have requirement text")
|
|
|
|
var locked_at_zero: Array = ["paper", "gold", "bell", "star", "regular", "night"]
|
|
for id in locked_at_zero:
|
|
_check(not frames.is_unlocked(str(id)), "%s should be locked with no progress" % id)
|
|
_check(not frames.requirement_text(str(id)).is_empty(), "%s should show a requirement while locked" % id)
|
|
_check(frames.by_id("does-not-exist").is_empty(), "unknown frame id should resolve to nothing")
|
|
_check(not frames.is_unlocked("does-not-exist"), "unknown frame should never be unlocked")
|
|
_check(frames.requirement_text("does-not-exist").is_empty(), "unknown frame should have empty requirement text")
|
|
|
|
var room_thresholds := {"paper": 5, "gold": 10, "bell": 20, "star": 30}
|
|
for id in room_thresholds:
|
|
var need: int = int(room_thresholds[id])
|
|
save.data["completed_rooms"] = []
|
|
for i in range(need - 1):
|
|
save.data["completed_rooms"].append("room-probe-%d" % i)
|
|
_check(not frames.is_unlocked(str(id)), "%s should be locked at %d rooms" % [id, need - 1])
|
|
save.data["completed_rooms"].append("room-probe-last")
|
|
_check(frames.is_unlocked(str(id)), "%s should unlock at %d rooms" % [id, need])
|
|
|
|
_reset_to_clean(save)
|
|
var streak_thresholds := {"regular": 3, "night": 7}
|
|
for id in streak_thresholds:
|
|
var need: int = int(streak_thresholds[id])
|
|
save.data["daily"]["best_streak"] = need - 1
|
|
_check(not frames.is_unlocked(str(id)), "%s should be locked at a %d-day best streak" % [id, need - 1])
|
|
save.data["daily"]["best_streak"] = need
|
|
_check(frames.is_unlocked(str(id)), "%s should unlock at a %d-day best streak" % [id, need])
|
|
|
|
# Selecting a locked frame must not make it unlocked.
|
|
_reset_to_clean(save)
|
|
save.select_frame("star")
|
|
save.save_game()
|
|
save.load_game()
|
|
_check(save.selected_frame() == "star", "selection itself should persist")
|
|
_check(not frames.is_unlocked("star"), "selecting a locked frame must not unlock it")
|
|
|
|
# A legitimately unlocked selection survives save/load.
|
|
_reset_to_clean(save)
|
|
for i in range(5):
|
|
save.data["completed_rooms"].append("room-%02d" % i)
|
|
save.select_frame("paper")
|
|
save.save_game()
|
|
save.load_game()
|
|
_check(frames.is_unlocked("paper"), "five-room unlock should survive save/load")
|
|
_check(save.selected_frame() == "paper", "frame selection should persist through save/load")
|
|
|
|
# Document reset_progress()'s actual behaviour instead of guessing.
|
|
_reset_to_clean(save)
|
|
save.data["completed_rooms"] = ["room-a", "room-b", "room-c"]
|
|
save.data["unlocked_guests"] = ["pepper", "miso"]
|
|
save.data["last_room"] = 3
|
|
save.data["daily"]["best_streak"] = 5
|
|
save.data["daily"]["streak"] = 2
|
|
save.data["daily"]["last_completed"] = Daily.today_key()
|
|
save.select_frame("regular")
|
|
save.reset_progress()
|
|
_note(
|
|
"reset_progress -> rooms=%d guests=%d last_room=%d best_streak=%d streak=%d last_completed=%s frame=%s"
|
|
% [
|
|
save.rooms_completed(),
|
|
(save.data["unlocked_guests"] as Array).size(),
|
|
int(save.data["last_room"]),
|
|
save.best_streak(),
|
|
int(save.daily_data().get("streak", -1)),
|
|
str(save.daily_data().get("last_completed", "")),
|
|
save.selected_frame()
|
|
]
|
|
)
|
|
_check(save.rooms_completed() == 0, "reset_progress should clear completed_rooms")
|
|
_check((save.data["unlocked_guests"] as Array).is_empty(), "reset_progress should clear unlocked_guests")
|
|
_check(int(save.data["last_room"]) == 0, "reset_progress should clear last_room")
|
|
_check(save.best_streak() == 5, "reset_progress should leave best_streak alone")
|
|
_check(int(save.daily_data().get("streak", 0)) == 2, "reset_progress should leave the daily streak alone")
|
|
_check(
|
|
str(save.daily_data().get("last_completed", "")) == Daily.today_key(),
|
|
"reset_progress should leave last_completed alone"
|
|
)
|
|
_check(save.selected_frame() == "regular", "reset_progress should leave the selected frame alone")
|
|
|
|
_reset_to_clean(save)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 4. Level and guest data
|
|
# ---------------------------------------------------------------------------
|
|
|
|
func _test_v6_features(save) -> void:
|
|
_note("6. v6 systems")
|
|
_check(save.player_name() == "Innkeeper", "default player name should be Innkeeper")
|
|
_check(save.player_id().begins_with("RAT-"), "player ID should be generated")
|
|
save.set_player_name("Ahri")
|
|
_check(save.player_name() == "Ahri", "player name should save")
|
|
_check(bool(save.get_setting("music")), "music should default on")
|
|
_check(absf(float(save.get_setting("music_volume")) - 0.7) < 0.001, "music volume should default to 0.7")
|
|
_check(bool(save.get_setting("sfx")), "sfx should default on")
|
|
_check(save.theme_id() == "cream", "default wallpaper should be cream")
|
|
_check(not save.is_theme_unlocked("gold"), "gold wallpaper should start locked")
|
|
save.data["daily"]["best_streak"] = 7
|
|
save.save_game()
|
|
_check(save.claim_gift(), "7-day gift should be claimable")
|
|
_check(not save.claim_gift(), "7-day gift should not double claim")
|
|
_check(save.is_theme_unlocked("gold"), "gift should unlock gold wallpaper")
|
|
save.select_theme("gold")
|
|
_check(save.theme_id() == "gold", "gold wallpaper should be selectable")
|
|
var snap := {"level_id": "probe", "n": 8, "cells": [], "auto_x": [], "history": []}
|
|
save.save_board("campaign", snap)
|
|
_check(save.load_board("campaign") == snap, "board snapshot should round trip")
|
|
save.clear_board("campaign")
|
|
_check(save.load_board("campaign").is_empty(), "board snapshot should clear")
|
|
var state: Dictionary = save.achievements()
|
|
_check(bool(state.get("streak_7", false)), "achievements should reflect streak")
|
|
_reset_to_clean(save)
|
|
|
|
|
|
func _test_game_data(save) -> void:
|
|
_note("4. level/guest data")
|
|
|
|
var levels: Array = Levels.load_all()
|
|
_check(levels.size() == 30, "there should be 30 levels")
|
|
if levels.is_empty():
|
|
return
|
|
|
|
var board := Board.new()
|
|
root.add_child(board)
|
|
|
|
var bad_shape := 0
|
|
var bad_solution := 0
|
|
var bad_clues := 0
|
|
var bad_regions := 0
|
|
var bad_rats := 0
|
|
var bad_region_rats := 0
|
|
var valid_guests: Dictionary = {}
|
|
for guest in Guests.all():
|
|
valid_guests[str(guest.get("id", ""))] = true
|
|
|
|
for level_variant in levels:
|
|
if typeof(level_variant) != TYPE_DICTIONARY:
|
|
bad_shape += 1
|
|
continue
|
|
var level: Dictionary = level_variant
|
|
var n: int = int(level.get("n", 0))
|
|
var regions: Array = level.get("regions", [])
|
|
var solution: Array = level.get("solution", [])
|
|
var clues: Array = level.get("clues", [])
|
|
var label: String = str(level.get("id", "?"))
|
|
|
|
if n != 8:
|
|
bad_shape += 1
|
|
if regions.size() != n:
|
|
bad_regions += 1
|
|
else:
|
|
for row in regions:
|
|
if (row as Array).size() != n:
|
|
bad_regions += 1
|
|
var region_ids := {}
|
|
for row in regions:
|
|
for value in row:
|
|
region_ids[int(value)] = true
|
|
if region_ids.size() != n:
|
|
bad_regions += 1
|
|
|
|
if solution.size() != n:
|
|
bad_solution += 1
|
|
else:
|
|
var cells := []
|
|
for r in n:
|
|
var row := []
|
|
for c in n:
|
|
row.append(Rules.EMPTY)
|
|
cells.append(row)
|
|
for r in n:
|
|
var c: int = int(solution[r])
|
|
if c >= 0 and c < n:
|
|
cells[r][c] = Rules.RAT
|
|
if not Rules.is_valid(cells, regions):
|
|
bad_solution += 1
|
|
if Rules.count_rats(cells) != n:
|
|
bad_solution += 1
|
|
|
|
if clues.size() != 3:
|
|
bad_clues += 1
|
|
else:
|
|
for clue in clues:
|
|
var cr: int = int(clue[0])
|
|
var cc: int = int(clue[1])
|
|
if cr < 0 or cr >= n or cc < 0 or cc >= n or int(solution[cr]) != cc:
|
|
bad_clues += 1
|
|
|
|
board.set_level(level)
|
|
if board.region_rats.size() != 8:
|
|
bad_region_rats += 1
|
|
var seen := {}
|
|
for id_variant in board.region_rats:
|
|
var id: String = str(id_variant)
|
|
if seen.has(id) or not valid_guests.has(id):
|
|
bad_region_rats += 1
|
|
seen[id] = true
|
|
if seen.size() != 8:
|
|
bad_region_rats += 1
|
|
if board.fixed.size() != 3:
|
|
bad_rats += 1
|
|
|
|
_check(bad_shape == 0, "every level should have n=8 (%d bad)" % bad_shape)
|
|
_check(bad_regions == 0, "every level should have an 8x8 region grid with 8 regions (%d bad)" % bad_regions)
|
|
_check(bad_solution == 0, "every solution should be a legal board under Rules (%d bad)" % bad_solution)
|
|
_check(bad_clues == 0, "every level should have 3 clues matching its solution (%d bad)" % bad_clues)
|
|
_check(bad_region_rats == 0, "every level should carry 8 unique guest ids in Board.region_rats (%d bad)" % bad_region_rats)
|
|
_check(bad_rats == 0, "every level should fix 3 clue rats on its board (%d bad)" % bad_rats)
|
|
|
|
board.free()
|
|
|
|
var guests: Array = Guests.all()
|
|
_check(guests.size() == 25, "guest manifest should contain 25 guests")
|
|
var guest_ids := {}
|
|
var duplicate_guests := 0
|
|
for guest in guests:
|
|
var id: String = str(guest.get("id", ""))
|
|
if guest_ids.has(id) or id.is_empty():
|
|
duplicate_guests += 1
|
|
guest_ids[id] = true
|
|
_check(FileAccess.file_exists(Guests.portrait(id, "thumbs")), "missing thumb portrait for '%s'" % id)
|
|
_check(FileAccess.file_exists(Guests.portrait(id, "full")), "missing card portrait for '%s'" % id)
|
|
_check(duplicate_guests == 0, "guest ids should be non-empty and unique (%d bad)" % duplicate_guests)
|
|
|
|
_check(FileAccess.file_exists("res://art/crumb_head.png"), "Crumb head art should exist")
|
|
_check(FileAccess.file_exists("res://art/crumb.png"), "Crumb art should exist")
|