harvest/game/tests/test_flow.gd
Forrest 8146567aac Enemy roster reskin: thief -> Alien, breaker -> Alien Robot display names
Renames player-visible text only (toasts, HUD hints, wave labels, night
and scenario titles, tutorial tips, review/end panel text): thief/thieves
display as alien/aliens, fence breaker/fence breakers display as alien
robot/alien robots. Crows keep their name; night 1's dusk hint and night
3's hint get brief alien-mind-control framing. All TYPE_* ids, "thief"/
"breaker"/"crow" data keys, class/function/variable names, and code
comments are unchanged. Adds EnemySystem.ARTICLES so "a"/"an" still
agrees with the new names. Updates the two tests that assert the old
display strings (test_flow.gd, test_save.gd); test_roster.gd and
test_theft.gd are untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-05 13:48:00 -04:00

406 lines
20 KiB
GDScript

extends RefCounted
## The whole game through its entry scene (main.tscn, with test save and settings paths): the
## main menu over the paused farm; New vacation, Continue, and their questions; pausing freezes
## the simulation tick; settings apply and persist from the pause menu; Restart the night and
## Save & quit to menu put the farm back at the saved morning without touching the save; a
## damaged save can't be continued; quitting a hosted co-op game from the pause menu leaves the
## scarecrow unfrozen; the failure screen and Retry; the farmers' return and the final
## assessment; the first day's and night's tips; and the sounds hooked to the game.
const P := CampaignController.Phase
const SAVE := "user://test_flow_save.json"
const SETTINGS := "user://test_flow_settings.cfg"
const DT := 1.0 / 60.0
var r: GameTestRunner
var main: Main
var sim: FarmSim
var c: CampaignController
func run(p_r: GameTestRunner) -> void:
r = p_r
_clean()
main = (load("res://game/scenes/main.tscn") as PackedScene).instantiate() as Main
main.save_path = SAVE
main.settings_path = SETTINGS
r.root.add_child(main)
await r.process_frame
await r.physics_frame
sim = main.sim
c = sim.campaign
await _title_screen()
await _pause()
await _settings()
await _restart_and_quit_to_menu()
await _continue_and_new()
await _coop_quit_to_menu()
await _tutorial()
await _failure()
await _ending()
_audio()
main.queue_free()
r.paused = false
await r.process_frame
_clean()
func _clean() -> void:
for p in [SAVE, SAVE + ".tmp", SETTINGS]:
if FileAccess.file_exists(p):
DirAccess.remove_absolute(ProjectSettings.globalize_path(p))
func _press(action: String) -> void:
for pressed in [true, false]:
var e := InputEventAction.new()
e.action = StringName(action)
e.pressed = pressed
Input.parse_input_event(e)
await r.process_frame
await r.process_frame
func _hud_visible() -> bool:
return (main.farm.get_node("Hud") as CanvasLayer).visible
func _same(a: Dictionary, b: Dictionary) -> bool:
return JSON.stringify(a, "", true, true) == JSON.stringify(b, "", true, true)
func _title_screen() -> void:
r.check(main.screen == Main.Screen.MENU and r.paused and main.main_menu.visible and not _hud_visible()
and main.get_viewport().get_camera_3d() == main._menu_camera, "the game starts at the main menu: the farm paused behind it, no HUD")
r.check(main.main_menu.continue_button.disabled and main.main_menu.save_note.text == "No saved vacation",
"with nothing to continue, Continue is off and says so")
await r.process_frame
r.check(main.main_menu.new_button.has_focus(), "and New vacation has the focus (keyboard and gamepad)")
r.check(sim.audio.music_track == "farm" and (sim.audio._music["farm"] as AudioStreamPlayer).playing,
"\"On the Farm\" plays on the title screen (the paused farm's morning)")
r.check(not SaveGame.exists(SAVE), "the farm behind the menu isn't saved")
r.check(ProjectSettings.get_setting("gui/theme/custom") == "res://game/resources/ui_theme.tres"
and load("res://game/resources/ui_theme.tres") is Theme and main.main_menu.new_button.has_theme_stylebox("focus"),
"the UI theme is the project's default")
main.main_menu.new_button.pressed.emit()
var saved := SaveGame.read(SAVE)
r.check(main.screen == Main.Screen.PLAYING and not r.paused and _hud_visible() and c.state.phase == P.MORNING
and sim.review_panel.visible and main.get_viewport().get_camera_3d() == sim.camera,
"New vacation (no save to replace) starts at once: the morning screen, the HUD, the follow camera")
r.check(saved.status == SaveGame.Status.OK and saved.state.night == 1, "and saves the new vacation's first morning")
func _pause() -> void:
c.begin_day()
for i in 3:
await r.physics_frame
r.check(c.state.phase == P.DAY and c.state.phase_time_left < c.phase_length(P.DAY), "the day's clock runs while playing")
await _press("pause")
r.check(main.screen == Main.Screen.PAUSED and r.paused and main.pause_menu.visible, "Escape / Start pauses")
var t := c.state.phase_time_left
var player := sim.player.global_position
for i in 10:
await r.physics_frame
r.check(c.state.phase_time_left == t and sim.player.global_position == player, "pausing freezes the simulation tick")
r.check(main.pause_menu._where.text == "Night 1 of 5 · Day" and main.pause_menu._note.text.contains("morning of day 1"),
"the pause menu says where you are and what Continue picks up ('%s')" % main.pause_menu._where.text)
r.check(main.pause_menu.resume_button.has_focus(), "with Resume focused")
await _press("pause")
r.check(main.screen == Main.Screen.PLAYING and not r.paused and not main.pause_menu.visible, "Escape / Start again resumes")
await r.physics_frame
await r.physics_frame
r.check(c.state.phase_time_left < t, "and the clock runs again")
func _settings() -> void:
main.pause()
main.pause_menu.settings_button.pressed.emit()
var menu := main.settings_menu
r.check(menu.visible and menu.is_open, "Settings opens from the pause menu")
await r.process_frame
(menu.controls["volume/Music"] as HSlider).value = 0.3
var music := AudioServer.get_bus_index("Music")
r.check(is_equal_approx(GameSettings.load_from(SETTINGS).volume["Music"], 0.3)
and is_equal_approx(AudioServer.get_bus_volume_db(music), linear_to_db(0.3)), "a change applies and is saved at once")
(menu.controls["show_tips"] as CheckBox).button_pressed = false
r.check(not sim.tutorial.enabled and not GameSettings.load_from(SETTINGS).show_tips, "turning tips off reaches the tutorial")
(menu.controls["show_tips"] as CheckBox).button_pressed = true
(menu.controls["aim_dead_zone"] as HSlider).value = 0.4
r.check(is_equal_approx(sim.config.aim_dead_zone, 0.4), "the aim dead zone reaches the gun's config")
r.check(SettingsMenu.describe_keys(["fear"]) == "Q" and SettingsMenu.describe_pad(["fear"]) == "LB"
and SettingsMenu.describe_keys(["fire"]) == "Left mouse" and SettingsMenu.describe_pad(["fire"]).contains("RT")
and SettingsMenu.describe_keys(["hide_tips"]) == "Backspace" and SettingsMenu.describe_pad(["pause"]) == "Start",
"the bindings list reads the real input map")
await _press("ui_cancel")
r.check(not menu.visible and main.screen == Main.Screen.PAUSED and r.paused, "Escape / B closes Settings back to the pause menu")
await r.process_frame
r.check(main.pause_menu.settings_button.has_focus(), "with the focus back on Settings")
main.settings_menu.open(main.settings)
var reset := menu.back_button.get_parent().get_child(1) as Button
reset.pressed.emit()
r.check(is_equal_approx(GameSettings.load_from(SETTINGS).volume["Music"], GameSettings.DEFAULT_VOLUME["Music"])
and is_equal_approx((menu.controls["volume/Music"] as HSlider).value, GameSettings.DEFAULT_VOLUME["Music"]),
"Reset to defaults resets and saves")
menu.back_button.pressed.emit()
main.resume()
func _restart_and_quit_to_menu() -> void:
var morning := SaveGame.read(SAVE).state.to_dict()
c.state.resources.pouch["wood"] = 4
main.pause()
main.pause_menu.restart_button.pressed.emit()
r.check(main.confirm.is_open and main.confirm.message.text.contains("Restart night 1") and main.screen == Main.Screen.PAUSED,
"Restart the night asks first")
await r.process_frame
r.check(main.confirm.no_button.has_focus(), "with Cancel focused")
main.confirm.yes_button.pressed.emit()
r.check(main.screen == Main.Screen.PLAYING and not r.paused and c.state.phase == P.MORNING and _same(c.state.to_dict(), morning),
"and restarts from the saved morning")
c.begin_day()
c.state.resources.pouch["scrap"] = 3
var file := FileAccess.get_file_as_string(SAVE)
main.pause()
main.pause_menu.menu_button.pressed.emit()
r.check(main.screen == Main.Screen.MENU and r.paused and main.main_menu.visible and not _hud_visible()
and c.state.phase == P.MORNING and c.state.resources.pouch["scrap"] == 0,
"Save & quit to menu: back at the menu, the farm at the saved morning")
r.check(FileAccess.get_file_as_string(SAVE) == file, "and the save itself is untouched")
r.check(not main.main_menu.continue_button.disabled and main.main_menu.save_note.text.begins_with("Morning of day 1 of 5"),
"Continue now offers that morning ('%s')" % main.main_menu.save_note.text)
await r.process_frame
r.check(main.main_menu.continue_button.has_focus(), "and has the focus")
func _continue_and_new() -> void:
main.main_menu.continue_button.pressed.emit()
r.check(main.screen == Main.Screen.PLAYING and _hud_visible() and c.state.phase == P.MORNING
and _same(c.state.to_dict(), SaveGame.read(SAVE).state.to_dict()), "Continue resumes at the saved morning")
main.to_menu()
main.main_menu.new_button.pressed.emit()
r.check(main.confirm.is_open and main.confirm.message.text.contains("replaces your saved one") and main.screen == Main.Screen.MENU,
"New vacation over a save asks first")
await _press("ui_cancel")
r.check(not main.confirm.is_open and main.screen == Main.Screen.MENU, "Escape / B cancels")
main.main_menu.new_button.pressed.emit()
main.confirm.yes_button.pressed.emit()
r.check(main.screen == Main.Screen.PLAYING and c.state.night == 1 and c.state.night_log.is_empty(), "confirming starts the new vacation")
main.to_menu()
var f := FileAccess.open(SAVE, FileAccess.WRITE)
f.store_string("{\"game\": \"harvest-season\", \"state\": {\"version\": 3}}")
f.close()
main.show_main_menu()
r.check(main.main_menu.continue_button.disabled and main.main_menu.save_note.text.contains("damaged"),
"a damaged save can't be continued, and the menu says why")
r.check(not main.continue_vacation() and main.screen == Main.Screen.MENU, "Continue refuses it")
main.main_menu.new_button.pressed.emit()
r.check(main.screen == Main.Screen.PLAYING and SaveGame.read(SAVE).status == SaveGame.Status.OK,
"New vacation doesn't ask about a damaged save and replaces it")
## Hosting co-op, the pause menu freezes only this scarecrow; quitting to the menu from it must
## unfreeze it, or the next game (hosting again, or joining a friend's) has no aim or buttons.
func _coop_quit_to_menu() -> void:
var links := CoopLink.pair()
sim.coop.start_host(sim, links[0], "Ana", "Ben")
main.pause()
r.check(sim.local_frozen and not r.paused and sim.combat.remote != null, "hosting co-op, the pause menu freezes the scarecrow, not the farm")
main.pause_menu.menu_button.pressed.emit()
r.check(main.screen == Main.Screen.MENU and not sim.coop.is_active() and not sim.local_frozen and sim.combat.remote == null
and sim.scarecrow.remote == null and sim.interactions.remote == null and sim.player.input_enabled,
"quitting co-op to the menu unfreezes it")
links[1].close()
main.main_menu.continue_button.pressed.emit()
sim.combat.aim_point = Vector3.ZERO
await r.physics_frame
await r.physics_frame
r.check(main.screen == Main.Screen.PLAYING and sim.combat.aim_point != Vector3.ZERO, "and in the next game the aim follows the mouse again")
func _tutorial() -> void:
var t := sim.tutorial
t.done = {}
t.dismissed = false
t._process(0.0)
r.check(t.current == "" and not t._box.visible, "no tips during the morning screen")
c.begin_day()
t._process(0.0)
r.check(t.current == "move" and t._box.visible and t._text.text.contains("[W A S D]"), "day 1 starts with how to move")
sim.player.global_position += Vector3(5.0, 0.0, 0.0)
t._process(0.0)
r.check(t.done.has("move") and t._text.text.begins_with("Done!"), "moving finishes it (and says so)")
t._process(1.0)
t._process(0.0)
r.check(t.current == "gather", "then gathering")
c.state.resources.pouch["wood"] = 2
c.state.record_event("gathered_wood", 2)
t._process(0.0)
t._process(1.0)
t._process(0.0)
r.check(t.current == "store", "then storing at the shed, once the pouch has something")
sim.interactions.deposited.emit({"wood": 2})
c.state.resources.pouch["wood"] = 0
t._process(1.0)
t._process(0.0)
r.check(t.current == "build", "then building")
c.state.record_event("structures_built")
t._process(0.0)
t._process(1.0)
t._process(0.0)
r.check(t.current == "" and not t._box.visible, "and nothing more by day")
c.advance_phase()
t._process(0.0)
r.check(t.current == "dusk" and t._text.text.contains("nightfall"), "dusk says when and where the thieves come")
c.advance_phase()
sim.spawn_enemy(EnemySystem.TYPE_CROW)
t._process(0.0)
t._process(1.0)
t._process(0.0)
r.check(t.current == "shoot", "with an enemy in at night: how to shoot")
c.state.scarecrow_hp -= 1
t._process(0.0)
r.check(t.current == "patch", "hurt: how to patch up (more urgent than shooting)")
c.state.scarecrow_hp += 1
await _press("hide_tips")
t._process(0.0)
r.check(t.dismissed and not t._box.visible, "[Backspace / Back] hides the tips")
t.dismissed = false
t.enabled = false
t._process(0.0)
r.check(not t._box.visible, "and with tips off in Settings there are none")
t.enabled = true
c.retry_night()
func _failure() -> void:
var morning := SaveGame.read(SAVE).state.to_dict()
var panel := sim.end_panel
c.begin_day()
c.advance_phase()
c.advance_phase()
r.check(c.state.phase == P.NIGHT, "night 1")
c.state.scarecrow_hp = 0
c.tick(DT)
panel._process(EndPanel.DELAY + 0.1)
r.check(c.state.phase == P.GAME_OVER and panel.is_visible_in_tree() and panel.mode == "failure" and panel._title.text == "The scarecrow has fallen"
and panel._rating.text.begins_with("Night 1 of 5: Crows at the crops"), "the failure screen gives the cause and the night ('%s')" % panel._rating.text)
r.check(panel._detail.text.contains("You kept the farm for 0 nights.") and panel._detail.text.contains("Left: 30 of 30 crops")
and panel._detail.text.contains("Tonight: "), "what was kept, what's left, and what tonight cost")
r.check(panel._retry.visible and panel._retry.has_focus() and panel._menu.visible and not panel._new.visible
and panel._retry.text.contains("morning of day 1"), "Retry the night (focused) and Main menu")
panel._retry.pressed.emit()
r.check(c.state.phase == P.MORNING and not panel.visible and _same(c.state.to_dict(), morning), "Retry restores the saved morning")
c.begin_day()
c.state.strip()
c.tick(DT)
panel._process(EndPanel.DELAY + 0.1)
r.check(panel.mode == "failure" and panel._title.text == "The farm was stripped bare", "a stripped farm says so")
panel._menu.pressed.emit()
r.check(main.screen == Main.Screen.MENU and main.main_menu.visible and c.state.phase == P.MORNING and not panel.visible,
"Main menu goes back to the menu")
main.main_menu.continue_button.pressed.emit()
r.check(main.screen == Main.Screen.PLAYING and _same(c.state.to_dict(), morning), "and Continue retries the failed night's morning")
func _ending() -> void:
var cfg := c.config
var s := FarmState.create(cfg)
s.night = cfg.campaign_nights
s.nights_survived = cfg.campaign_nights - 1
GameTestRunner.lose_crops(s, 2)
for n in range(1, cfg.campaign_nights):
var e := {"night": n, "crops_lost": 1 if n <= 2 else 0, "animals_lost": 0}
for k in FarmState.EVENTS:
e[k] = 0
e["killed_crow"] = 10
e["killed_thief"] = 2
e["gathered_wood"] = 12
s.night_log.append(e)
c.load_state(s)
r.check(SaveGame.read(SAVE).state.night == cfg.campaign_nights, "the last morning is saved")
c.begin_day()
for i in 4: # dusk, night, dawn, and the end of the dawn grace
c.advance_phase()
var ending := sim.ending
r.check(c.state.phase == P.FARMERS_RETURN and not SaveGame.exists(SAVE), "the last dawn ends the vacation and deletes the save")
r.check(ending.running and ending.stage == "drive" and main.get_viewport().get_camera_3d() == ending._camera and not _hud_visible(),
"the farmers' return starts: the cutscene camera, no HUD")
var horn := int(sim.audio.played.get("horn", 0))
var steps := 0
while ending.stage == "drive" and steps < 3000:
ending.step(DT)
steps += 1
var park: Vector3 = FarmersReturn.ROUTE[FarmersReturn.ROUTE.size() - 1]
var car := ending._car.global_position
r.check(ending.stage == "walk" and Vector2(car.x - park.x, car.z - park.z).length() < 0.3 and steps * DT > 4.0 and steps * DT < 20.0,
"the car drives in by the driveway and parks by the house (%.1f s)" % (steps * DT))
r.check(int(sim.audio.played.get("horn", 0)) == horn + 1 and ending._farmers[0].visible and ending._farmers[1].visible,
"with a honk, and the farmers get out")
while not ending.done and steps < 9000:
ending.step(DT)
steps += 1
var at := true
for i in 2:
at = at and ending._farmers[i].global_position.distance_to(FarmersReturn.FARMER_SPOTS[i]) < 0.1 \
and ending._anims[i].current_animation == &"Cheering"
r.check(ending.done and ending.stage == "end" and at and steps * DT < 35.0,
"they walk to the door, wave, and cheer (%.1f s in all)" % (steps * DT))
r.info("farmers' return: %.1f s in all" % (steps * DT))
var panel := sim.end_panel
panel._process(0.1)
r.check(panel.is_visible_in_tree() and _hud_visible() and panel.mode == "assessment" and panel._title.text == "The farmers are home!"
and panel._rating.text.contains("points") and panel._bars.visible and panel._menu.visible and panel._menu.has_focus()
and not panel._retry.visible, "then the final assessment ('%s')" % panel._rating.text)
var a := Assessment.of(c.state, cfg)
r.check(panel._rating.text == "%s · %d points" % [a["tier"], a["score"]] and panel._stats.text.contains("Enemies defeated: 40 crows and 8 aliens")
and panel._stats.text.contains("Gathered 48 wood"), "with the rating, the shares kept, and the vacation's totals")
r.info("assessment: %s\n%s\n%s" % [panel._rating.text, panel._detail.text, panel._stats.text])
ending.clear()
ending.start()
ending.skip()
r.check(ending.done and ending._farmers[0].global_position.distance_to(FarmersReturn.FARMER_SPOTS[0]) < 0.01
and ending._car.global_position.distance_to(park) < 0.3, "skipping jumps to the end")
panel._menu.pressed.emit()
r.check(main.screen == Main.Screen.MENU and c.state.night == 1 and not ending.running and not SaveGame.exists(SAVE)
and main.main_menu.continue_button.disabled, "Main menu after the ending: a fresh farm behind the menu, nothing to continue")
func _audio() -> void:
var audio := sim.audio
var missing: Array[String] = []
for cue: String in FarmAudio.CUES:
var bus := String(FarmAudio.CUES[cue].get("bus", "SFX"))
if (audio.streams.get(cue, []) as Array).is_empty() or AudioServer.get_bus_index(bus) < 0:
missing.append(cue)
r.check(missing.is_empty(), "every sound cue has its sounds and its bus (%d cues; missing: %s)" % [FarmAudio.CUES.size(), missing])
r.check(audio._day.playing and audio._night.playing and (audio._day.stream as AudioStreamWAV).loop_mode == AudioStreamWAV.LOOP_FORWARD
and audio._day.bus == &"Ambience", "the day and night ambience loop on the Ambience bus")
main.new_vacation()
var before := audio.played.duplicate()
var count := func(cue: String) -> int: return int(audio.played.get(cue, 0)) - int(before.get(cue, 0))
sim.combat.fired.emit()
c.begin_day()
var day_music := audio.music_track
c.advance_phase()
var dusk_music := audio.music_track
r.check(count.call("shot") == 1 and count.call("bell") == 1 and count.call("dusk") == 1, "the gun, the dusk bell, and the dusk stinger play")
var id := sim.structures.place("fence", 2.0, 8.0, 0)
sim.structures.damage(id, 3)
sim.structures.damage(id, 999)
r.check(count.call("build") == 1 and count.call("structure_hit") == 1 and count.call("smash") == 1 and count.call("breach") == 1,
"building, a hit, and a broken fence (with the breach alarm)")
sim.scarecrow.try_damage(1)
r.check(count.call("hurt") == 1, "the scarecrow's hurt sound")
c.advance_phase()
var night_music := audio.music_track
c.advance_phase()
r.check(day_music == "farm" and dusk_music == "" and night_music == "night" and audio.music_track == "",
"music by phase: the farm tune by day, Purgatory at night, only ambience at dusk and dawn")
r.check((audio._music["farm"] as AudioStreamPlayer).bus == &"Music" and ((audio._music["night"] as AudioStreamPlayer).stream as AudioStreamOggVorbis).loop
and ((audio._music["farm"] as AudioStreamPlayer).stream as AudioStreamWAV).loop_mode == AudioStreamWAV.LOOP_FORWARD,
"both tracks loop on the Music bus")
audio._last.erase("crow_arrive")
r.check(audio.play("crow_arrive") and not audio.play("crow_arrive"), "a cue rests for its gap (no caw pile-ups)")
r.check(main.main_menu.new_button.has_meta(&"sounds") and sim.review_panel._start.has_meta(&"sounds"),
"menu and panel buttons have hover and click sounds")
main.to_menu()