UI and other changes

This commit is contained in:
Forrest 2026-10-07 13:41:38 -04:00
parent 87b5c11fcf
commit 215e24e246
79 changed files with 70023 additions and 2201 deletions

View file

@ -23,6 +23,7 @@ const SUITES := [
"res://game/tests/test_cycle.gd",
"res://game/tests/test_flow.gd",
"res://game/tests/test_coop.gd",
"res://game/tests/test_look.gd",
]
const TICK := 1.0 / 60.0
## Points on the farm's edge (FarmZones.edge) for tests that send an enemy in from a known side:

View file

@ -28,9 +28,8 @@ func run(r: GameTestRunner) -> void:
# counts this test tracks across night 1 (it isn't about the Workbench itself)
var review := farm.get_node("Hud/ReviewPanel") as ReviewPanel
var hud := farm.get_node("Hud/PhaseHud") as PhaseHud
var assets := farm.get_node("Hud/AssetHud") as AssetHud
assets._process(0.0)
r.check(assets.describe() == "Crops 30/30 · Animals 8/8 · Supplies 10", "the asset HUD reads '%s'" % assets.describe())
var assets := " · ".join(PauseMenu.asset_counts(sim.campaign.state))
r.check(assets == "Crops 30/30 · Animals 8/8 · Supplies 10", "the pause menu's assets read '%s'" % assets)
sim.structures.destroyed.connect(func(_id: int, _t: String, _at: Vector3) -> void: _broken.append(1))
_morning(r, sim, review, hud)
_day(r, sim, player, hud)
@ -47,7 +46,7 @@ func _morning(r: GameTestRunner, sim: FarmSim, review: ReviewPanel, hud: PhaseHu
r.check(sim.campaign.state.phase == P.MORNING and review.visible and review._title.text == "The farmers are away",
"the first morning shows the review panel with the introduction")
hud._process(0.0)
r.check(hud.describe() == "Night 1 of %d · Morning" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
r.check(hud.describe() == "Day 1 of %d · Morning" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
sim.day_night.snap()
var day_energy := sim.sun.light_energy
r.check(sim.day_night.lantern.light_energy < 0.6 and day_energy > 0.8, "morning light: bright sun, lantern nearly off")
@ -59,7 +58,7 @@ func _day(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: PhaseHu
var c := sim.campaign
var s := c.state
hud._process(0.0)
r.check(hud.describe() == "Night 1 of %d · Day · 3:00 left" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
r.check(hud.describe() == "Day 1 of %d · 3:00 until Dusk" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
sim.day_night.snap()
r.check(is_equal_approx(sim.day_night.lantern.light_energy, 0.0) and sim.sun.light_energy > 1.0, "daylight: full sun, no lantern")
# A day's work: gather into the pouch, build, take some damage, patch up.
@ -96,7 +95,7 @@ func _dusk(r: GameTestRunner, sim: FarmSim, hud: PhaseHud) -> void:
r.check(w.warning_active() and w.tonight_entries() == [[EnemySystem.TYPE_CROW, LootSystem.Category.CROP]], "dusk warns of what tonight brings: %s" % [w.tonight_entries()])
hud._process(0.0)
var warning := "Tonight, from every side: crows"
r.check(hud._hint.text == warning, "the HUD warns, by target: '%s'" % hud._hint.text.replace("\n", " / "))
r.check(hud.hint == warning, "the HUD warns, by target: '%s'" % hud.hint.replace("\n", " / "))
var marked := w.get_children().filter(func(n: Node) -> bool: return n is Node3D and (n as Node3D).visible)
r.check(marked.is_empty() and sim.alerts.collect().is_empty(), "nothing marks tonight's arrivals on the farm or at the screen edge")
r.check(hud._dusk_hint.visible and hud._dusk_hint.text == plan.dusk_hint and hud._banner.text == "Dusk: %s" % plan.title,

View file

@ -12,7 +12,8 @@ extends RefCounted
## supply shed's own shop (#6): weapons (corn_shooter, pumpkin_bomb) bought at its counter
## (ShedCounter), not the workbench, with the walk-in pouch deposit unaffected. And a pouch per
## scarecrow (#16): filled, deposited, and spent from by its own avatar slot, one shared capacity.
## And upgrade levels and timed shed stock (#26, _tiers and _stock).
## And upgrade levels and timed shed stock (#26, _tiers and _stock). And the HUD's backpack and
## pouch panel (ResourceHud).
const P := CampaignController.Phase
const DT := 1.0 / 60.0
@ -38,6 +39,7 @@ func run(r: GameTestRunner) -> void:
sim.waves.enabled = false
var player := farm.get_node("Player") as PlayerCharacter
_layout(r, sim)
_pouch_hud(r, farm, sim)
_gathering(r, sim, player)
_deposit_and_night(r, sim, player)
_patch_cost(r, sim)
@ -384,7 +386,7 @@ func _tiers(r: GameTestRunner) -> void:
## Timed shed stock (#26): each shed item arrives on its day ("from_day"; day N is the day before
## night N) and can't be bought before it. Its row shows just its name, greyed, and "Arrives on
## day N"; a hidden one shows "?" and its day until it arrives, then the bare "?" until revealed.
## Debug F8 (CampaignDebug.unlock_all): on day 1, every upgrade and shop item goes to its last
## Debug F4 (CampaignDebug.unlock_all): on day 1, every upgrade and shop item goes to its last
## level for free, each level's effect applied; a retry from the morning review keeps it, one from
## later in the day goes back to the morning without it.
func _unlock_all(r: GameTestRunner) -> void:
@ -400,14 +402,14 @@ func _unlock_all(r: GameTestRunner) -> void:
var shed: Dictionary = s.resources.shed.duplicate()
var damage := Upgrades.value(cfg, s, "shot_damage")
var key := InputEventKey.new()
key.physical_keycode = KEY_F8
key.physical_keycode = KEY_F4
key.pressed = true
debug._unhandled_input(key)
var all_max := true
for id: String in cfg.upgrades:
all_max = all_max and Upgrades.maxed(cfg, s, id) and Upgrades.blocker(c, id) == "Done"
r.check(all_max and s.night == 1 and Upgrades.levels_bought(cfg, s) == Upgrades.levels_total(cfg),
"F8 on the first morning: every upgrade and shop item at its last level (%d levels), hidden and not-yet-arrived ones too"
"F4 on the first morning: every upgrade and shop item at its last level (%d levels), hidden and not-yet-arrived ones too"
% Upgrades.levels_bought(cfg, s))
r.check(s.resources.shed == shed and int(s.night_events.get("upgrades_bought", 0)) == 0, "free, and not counted as bought")
r.check(s.scarecrow_max_hp == hp + 6 and s.scarecrow_hp == hp + 6 and s.resources.pouch_capacity == pouch + 16
@ -576,6 +578,44 @@ func _gathering(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> voi
_step(sim, 1)
## The HUD's backpack: "used/capacity", a red dot once something new is carried (gone once the pouch
## is opened, or emptied), and the pouch panel (I / R3) with what's carried and what the shed holds.
func _pouch_hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var hud := farm.get_node("Hud/ResourceHud") as ResourceHud
var res := sim.campaign.state.resources
var keep_shed: Dictionary = res.shed.duplicate()
var keep_pouch: Dictionary = res.pouch.duplicate()
for m in ResourceStore.MATERIALS:
res.pouch[m] = 0
hud._process(0.0)
hud.open = false
r.check(not hud.new_items and hud.count_text() == "0/%d" % res.pouch_capacity, "an empty pouch: '%s', no dot" % hud.count_text())
res.add_to_pouch("wood", 3)
res.shed["scrap"] = 7
hud._process(0.0)
r.check(hud.count_text() == "3/%d" % res.pouch_capacity and hud.new_items, "the backpack counts what's carried ('%s'), with a dot for the new wood" % hud.count_text())
var press := InputEventAction.new()
press.action = &"pouch"
press.pressed = true
hud._unhandled_input(press)
var rows := hud.rows()
r.check(hud.open and not hud.new_items and rows.size() == ResourceStore.MATERIALS.size()
and rows[0] == {"material": "wood", "pouch": 3, "shed": int(res.shed["wood"])} and int(rows[1]["shed"]) == 7,
"I opens the pouch: what's carried and the shed's stock of each, and the dot goes: %s" % [rows])
hud._unhandled_input(press)
r.check(not hud.open, "and closes it again")
res.add_to_pouch("straw", 1)
hud._process(0.0)
var dot := hud.new_items
res.deposit()
hud._process(0.0)
r.check(dot and not hud.new_items, "emptying the pouch clears the dot")
for m in ResourceStore.MATERIALS:
res.shed[m] = int(keep_shed.get(m, 0))
res.pouch[m] = int(keep_pouch.get(m, 0))
hud._process(0.0)
func _deposit_and_night(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
var c := sim.campaign
var res := c.state.resources

View file

@ -81,15 +81,15 @@ func _zones(r: GameTestRunner, zones: FarmZones) -> void:
r.check(not o.rect().intersects(z.rect()), "%s and %s don't overlap" % [o.display_name, z.display_name])
## #13: 20 more crop units in two later-sprouting fields (lettuce/cabbage, corn), 10 each, ids
## 31..40 and 41..50, continuing the original field's plot numbering (7..10). GameConfig.start_crops
## #13: 60 more crop units in two later-sprouting fields (lettuce/cabbage, corn), 30 each, ids
## 31..60 and 61..90, continuing the original field's plot numbering (7..18). GameConfig.start_crops
## (30) only counts the original, always-grown field; the later fields grow FarmState.crops_total
## when they sprout (LootSystem), so it's not part of this static count.
func _crops(r: GameTestRunner, zones: FarmZones) -> void:
var cfg := load("res://game/resources/game_config.tres") as GameConfig
var units := zones.crop_units()
var fields := zones.zones_of(FarmZone.Kind.CROP_FIELD)
r.check(units.size() == cfg.start_crops + 20, "%d crop units: %d in the original field, 20 in the two later ones" % [units.size(), cfg.start_crops])
r.check(units.size() == cfg.start_crops + 60, "%d crop units: %d in the original field, 60 in the two later ones" % [units.size(), cfg.start_crops])
var ids := {}
var per_plot := {}
var fewest := 1 << 30
@ -104,14 +104,14 @@ func _crops(r: GameTestRunner, zones: FarmZones) -> void:
g["count"] = int(g["count"]) + 1
by_crop[u.crop] = g
r.check(ids.size() == units.size() and ids.has(1) and ids.has(units.size()), "crop unit ids are unique, 1..%d" % units.size())
r.check(per_plot.size() == 10 and per_plot.values().all(func(n: int) -> bool: return n == 5), "10 plots of 5 units (%s)" % [per_plot])
r.check(per_plot.size() == 18 and per_plot.values().all(func(n: int) -> bool: return n == 5), "18 plots of 5 units (%s)" % [per_plot])
r.check(fewest >= 8, "every unit is a visible cluster (fewest plants: %d)" % fewest)
r.check(by_crop.get("sunflower", {}).get("count", 0) == cfg.start_crops and by_crop["sunflower"]["sprout_night"] == 0,
"the original field's %d units are sunflowers, already grown" % cfg.start_crops)
r.check(by_crop.get("lettuce", {}).get("count", 0) == 10 and by_crop["lettuce"]["sprout_night"] == 2,
"10 lettuce/cabbage units sprout after night 2")
r.check(by_crop.get("corn", {}).get("count", 0) == 10 and by_crop["corn"]["sprout_night"] == 4,
"10 corn units sprout after night 4")
r.check(by_crop.get("lettuce", {}).get("count", 0) == 30 and by_crop["lettuce"]["sprout_night"] == 2,
"30 lettuce/cabbage units sprout after night 2")
r.check(by_crop.get("corn", {}).get("count", 0) == 30 and by_crop["corn"]["sprout_night"] == 4,
"30 corn units sprout after night 4")
## #20: the lettuce/cabbage and corn fields grow on the bare plowed soil south of the original map

194
game/tests/test_look.gd Normal file
View file

@ -0,0 +1,194 @@
extends RefCounted
## The toon look (ToonLook): lit, opaque StandardMaterial3Ds become toon ShaderMaterials with the
## same color, texture, and vertex-color use (double-sided ones get the double-sided shader), one
## per source material; unshaded, transparent, billboard, and no-depth-test materials stay. Nodes
## added later are swapped by the end of their frame, after their builder tinted them (the
## co-op partner's blue scarecrow). On the real farm no lit StandardMaterial3D is left showing,
## and the outline quad never casts a shadow and draws under the transparent effects. Label3Ds
## stop rendering in 3D (they'd be pixelated) and ScreenLabels draws them as flat text where they
## project, at least MIN_SIZE tall, only while shown and in front of the camera, and nudged apart
## where they'd overlap.
const TOON := "res://game/resources/toon.gdshader"
const TOON_DOUBLE_SIDED := "res://game/resources/toon_double_sided.gdshader"
func run(r: GameTestRunner) -> void:
_materials(r)
await _farm(r)
func _materials(r: GameTestRunner) -> void:
var look := ToonLook.new()
var lit := StandardMaterial3D.new()
lit.albedo_color = Color(0.8, 0.3, 0.1)
var tex := PlaceholderTexture2D.new()
lit.albedo_texture = tex
lit.vertex_color_use_as_albedo = true
var toon := look.toon_material(lit) as ShaderMaterial
r.check(toon != null and toon.shader.resource_path == TOON, "a lit, opaque material becomes a toon ShaderMaterial")
r.check(toon != null and toon.get_shader_parameter("albedo") == lit.albedo_color
and toon.get_shader_parameter("albedo_texture") == tex and toon.get_shader_parameter("use_vertex_color") == true,
"with the same color, texture, and vertex-color use")
r.check(look.toon_material(lit) == toon and look.toon_material(toon) == toon,
"one toon material per source (and swapping again changes nothing)")
var two_sided := StandardMaterial3D.new()
two_sided.cull_mode = BaseMaterial3D.CULL_DISABLED
r.check((look.toon_material(two_sided) as ShaderMaterial).shader.resource_path == TOON_DOUBLE_SIDED,
"a double-sided material gets the double-sided toon shader")
var unshaded := StandardMaterial3D.new()
unshaded.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
var glass := StandardMaterial3D.new()
glass.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
var facing := StandardMaterial3D.new()
facing.billboard_mode = BaseMaterial3D.BILLBOARD_ENABLED
var overlay := StandardMaterial3D.new()
overlay.no_depth_test = true
var kept := 0
for m: StandardMaterial3D in [unshaded, glass, facing, overlay]:
if look.toon_material(m) == m:
kept += 1
r.check(kept == 4, "unshaded, transparent, billboard, and no-depth-test materials stay (%d of 4)" % kept)
var mesh := BoxMesh.new()
mesh.material = lit
var mi := MeshInstance3D.new()
mi.mesh = mesh
look.swap_node(mi)
r.check(mi.get_surface_override_material(0) == toon and mesh.material == lit,
"a mesh's own material is swapped with a surface override (the mesh resource is untouched)")
var over := MeshInstance3D.new()
over.mesh = mesh
over.material_override = two_sided
look.swap_node(over)
r.check(over.material_override == look.toon_material(two_sided), "a material override is swapped in place")
var debris := CPUParticles3D.new()
debris.mesh = mesh
look.swap_node(debris)
r.check(debris.material_override == toon, "particles swap their mesh's material through an override")
mi.free()
over.free()
debris.free()
look.free()
func _farm(r: GameTestRunner) -> void:
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
r.root.add_child(farm)
await r.process_frame
var sim := farm.get_node("FarmSim") as FarmSim
sim.set_physics_process(false)
var look := ToonLook.new()
r.root.add_child(look)
var left := _lit_left(farm)
r.check(left.is_empty(), "no lit StandardMaterial3D is left showing on the farm (%d left: %s)" % [left.size(), ", ".join(left.slice(0, 5))])
r.check(_toon_count(farm) > 100, "the farm's props, characters, and weapons are toon-shaded (%d surfaces)" % _toon_count(farm))
var a := sim.add_partner(false, "Ben")
var body := a.body
r.check(not _lit_left(body).is_empty(), "the partner's scarecrow arrives with lit materials (tinted blue)")
await r.process_frame
await r.process_frame
r.check(_lit_left(body).is_empty(), "and is toon-shaded by the end of the frame it arrived in")
var blue := false
for mi in body.find_children("*", "MeshInstance3D", true, false):
var m := (mi as MeshInstance3D).material_override as ShaderMaterial
if m != null and m.get_shader_parameter("albedo") == Color(0.55, 0.75, 1.0):
blue = true
r.check(blue, "keeping its blue tint")
var label3ds := farm.find_children("*", "Label3D", true, false)
r.check(label3ds.size() >= 5 and label3ds.all(func(l: Node) -> bool: return (l as Label3D).layers == 0),
"the farm's %d Label3Ds don't render in 3D (ScreenLabels draws them)" % label3ds.size())
var cam := r.root.get_camera_3d()
var sign := Label3D.new()
sign.text = "Wood 4"
sign.font_size = 40
sign.pixel_size = 0.0075
sign.outline_size = 10
sign.modulate = Color(1.0, 0.8, 0.3)
farm.add_child(sign)
sign.global_position = cam.global_position - cam.global_basis.z * 12.0
sign.reset_physics_interpolation() # drawn where it's displayed, as in 3D
await r.process_frame
var drawn := look.labels.entries().filter(func(e: Dictionary) -> bool: return e["label"] == sign)
r.check(drawn.size() == 1 and drawn[0]["text"] == "Wood 4" and drawn[0]["color"] == sign.modulate
and drawn[0]["font_size"] >= ScreenLabels.MIN_SIZE and drawn[0]["outline_size"] > 0
and r.root.get_visible_rect().encloses(drawn[0]["rect"]),
"a label added later is drawn flat on screen with its text, color, and outline, readable size (%s)"
% [drawn[0]["font_size"] if drawn.size() == 1 else "not drawn"])
var twin := sign.duplicate() as Label3D
twin.text = "Alien Goop 0"
farm.add_child(twin)
twin.global_position = sign.global_position
twin.reset_physics_interpolation()
await r.process_frame
var pair := look.labels.entries().filter(func(e: Dictionary) -> bool: return e["label"] in [sign, twin])
r.check(pair.size() == 2 and not (pair[0]["rect"] as Rect2).intersects(pair[1]["rect"]),
"two labels at the same spot are nudged apart, so both can be read")
twin.queue_free()
sign.visible = false
r.check(not look.labels.entries().any(func(e: Dictionary) -> bool: return e["label"] == sign), "but not while hidden")
sign.visible = true
sign.global_position = cam.global_position + cam.global_basis.z * 12.0
sign.reset_physics_interpolation()
await r.process_frame # (the displayed position moves with the frame)
r.check(not look.labels.entries().any(func(e: Dictionary) -> bool: return e["label"] == sign), "or behind the camera")
var outline := look.outline
var outline_mat := outline.material_override as ShaderMaterial
r.check(outline.is_inside_tree() and outline_mat.shader.resource_path == "res://game/resources/pixel_outline.gdshader"
and outline.cast_shadow == GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
and outline_mat.render_priority == Material.RENDER_PRIORITY_MIN,
"the outline quad is in the world, casts no shadow, and draws under the transparent effects")
look.queue_free()
farm.queue_free()
await r.process_frame
## The nodes under root still showing a lit StandardMaterial3D, by name.
static func _lit_left(root: Node) -> Array[String]:
var out: Array[String] = []
for node in [root] + root.find_children("*", "GeometryInstance3D", true, false):
var g := node as GeometryInstance3D
if g == null:
continue
for m in _shown(g):
if m is BaseMaterial3D and ToonLook.swappable(m as BaseMaterial3D):
out.append(String(g.name))
return out
static func _toon_count(root: Node) -> int:
var n := 0
for node in root.find_children("*", "GeometryInstance3D", true, false):
for m in _shown(node as GeometryInstance3D):
var s := m as ShaderMaterial
if s != null and s.shader != null and s.shader.resource_path in [TOON, TOON_DOUBLE_SIDED]:
n += 1
return n
## The materials a node draws with.
static func _shown(g: GeometryInstance3D) -> Array[Material]:
var out: Array[Material] = []
if g.material_override != null:
out.append(g.material_override)
return out
var mesh: Mesh = null
if g is MeshInstance3D:
var mi := g as MeshInstance3D
if mi.mesh != null:
for i in mi.get_surface_override_material_count():
if mi.get_active_material(i) != null:
out.append(mi.get_active_material(i))
return out
if g is CPUParticles3D:
mesh = (g as CPUParticles3D).mesh
elif g is MultiMeshInstance3D and (g as MultiMeshInstance3D).multimesh != null:
mesh = (g as MultiMeshInstance3D).multimesh.mesh
if mesh != null:
for i in mesh.get_surface_count():
if mesh.surface_get_material(i) != null:
out.append(mesh.surface_get_material(i))
return out

View file

@ -0,0 +1 @@
uid://8pt5we4ip4pk

View file

@ -406,7 +406,7 @@ func _night_jump(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
r.check(c.morning_snapshot() == s.to_dict() and sim.review_panel.visible and body.contains("Tonight: %s." % tonight),
"the retry snapshot and the review panel are day 2's")
debug._unhandled_input(f3)
r.check(s.night == 3 and s.nights_survived == 2 and s.crops_total == crops + 10 and sim.loot.count(LootSystem.Status.DORMANT) == dormant - 10,
r.check(s.night == 3 and s.nights_survived == 2 and s.crops_total == crops + 30 and sim.loot.count(LootSystem.Status.DORMANT) == dormant - 30,
"F3 again: day 3, and the field due after night 2 sprouts (%d crops)" % s.crops_total)
var back := f3.duplicate() as InputEventKey
back.shift_pressed = true

View file

@ -195,7 +195,7 @@ func _settings(r: GameTestRunner) -> void:
_clean()
var fresh := GameSettings.load_from(SETTINGS)
r.check(fresh.volume == GameSettings.DEFAULT_VOLUME and fresh.show_tips and fresh.vsync and not fresh.fullscreen
and fresh.resolution_scale == 1.0, "no settings file: the defaults")
and fresh.resolution_scale == 1.0 and fresh.pixel_size == 4, "no settings file: the defaults")
var g := GameSettings.new()
g.volume = {"Master": 0.5, "Music": 0.25, "SFX": 0.0, "Ambience": 1.0, "Voice": 0.6}
g.move_dead_zone = 0.35
@ -203,6 +203,7 @@ func _settings(r: GameTestRunner) -> void:
g.fullscreen = true
g.vsync = false
g.resolution_scale = 0.75
g.pixel_size = 2
g.show_tips = false
g.player_name = "Ana"
g.microphone = false
@ -210,16 +211,27 @@ func _settings(r: GameTestRunner) -> void:
var back := GameSettings.load_from(SETTINGS)
r.check(back.volume == g.volume and back.move_dead_zone == 0.35 and back.aim_dead_zone == 0.15 and back.fullscreen
and not back.vsync and back.resolution_scale == 0.75 and not back.show_tips and back.player_name == "Ana"
and not back.microphone, "and load back unchanged (co-op name and microphone too)")
and not back.microphone and back.pixel_size == 2, "and load back unchanged (co-op name, microphone, pixel size too)")
var f := ConfigFile.new()
f.set_value("audio", "master", 7.0)
f.set_value("audio", "music", "loud")
f.set_value("display", "fullscreen", "yes")
f.set_value("display", "resolution_scale", 0.1)
f.set_value("display", "pixel_size", 40)
f.save(SETTINGS)
var odd := GameSettings.load_from(SETTINGS)
r.check(odd.volume["Master"] == 1.0 and odd.volume["Music"] == GameSettings.DEFAULT_VOLUME["Music"] and not odd.fullscreen
and odd.resolution_scale == 0.5, "out-of-range and wrong-typed values are clamped or fall back")
and odd.resolution_scale == 0.5 and odd.pixel_size == GameSettings.MAX_PIXEL_SIZE,
"out-of-range and wrong-typed values are clamped or fall back")
var view := SubViewport.new()
g.apply_pixels(view)
r.check(view.scaling_3d_mode == Viewport.SCALING_3D_MODE_NEAREST and is_equal_approx(view.scaling_3d_scale, 0.5)
and view.msaa_3d == Viewport.MSAA_DISABLED, "pixel size 2 renders the 3D view at half size, sharp-scaled, no MSAA")
g.pixel_size = 1
g.apply_pixels(view)
r.check(view.scaling_3d_mode == Viewport.SCALING_3D_MODE_BILINEAR and is_equal_approx(view.scaling_3d_scale, 0.75),
"pixel size 1 turns that off and uses the resolution scale")
view.free()
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
g.apply(null, cfg)
var music := AudioServer.get_bus_index("Music")

View file

@ -189,7 +189,7 @@ func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: Scar
var s := sim.campaign.state
s.upgrades.erase("sprint")
hud._process(0.0)
r.check(not player.can_sprint() and not hud._sprint_label.visible, "no sprint (and no sprint line on the HUD) before the upgrade")
r.check(not player.can_sprint() and not hud.stamina_shown(), "no sprint before the upgrade (and no stamina bar on the HUD)")
# On the real body, over physics frames: the open ground south-west of the pen.
player.global_position = Vector3(0.0, 0.0, 6.0)
player.velocity = Vector3.ZERO
@ -206,13 +206,12 @@ func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: Scar
r.check(player.animation_player.current_animation == player.run_animation and player.animation_player.speed_scale > 1.5,
"the run clip plays faster (x%.2f)" % player.animation_player.speed_scale)
r.check(player.move_strength() > 1.5, "the partner's machine is told it's sprinting (strength %.2f)" % player.move_strength())
hud._process(0.0)
r.check(hud._sprint_label.visible and hud._sprint_label.text.begins_with("Sprinting"), "the HUD shows the sprint running: '%s'" % hud._sprint_label.text)
r.check(hud.stamina_shown() and hud.stamina() < 1.0 and is_equal_approx(hud.stamina(), player.sprint_left / cfg.sprint_time),
"the HUD's stamina bar appears, and drains while sprinting (%.2f)" % hud.stamina())
Input.action_release("move_right")
await _frames(r, 2)
r.check(not player.sprinting and player.sprint_recharge > cfg.sprint_cooldown - 0.1, "stopping ends it, and the recharge starts")
hud._process(0.0)
r.check(hud._sprint_label.text == "Sprint %.0f s" % ceilf(player.sprint_recharge), "the HUD counts the recharge down: '%s'" % hud._sprint_label.text)
r.check(hud.stamina() < 0.1, "and starts filling back as it recharges (%.2f)" % hud.stamina())
Input.action_release("sprint")
await _frames(r, 30)
player.velocity = Vector3.ZERO
@ -236,8 +235,7 @@ func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: Scar
player.step_sprint(DT, true, false)
r.check(not player.sprinting, "and it doesn't start standing still")
sim.scarecrow.reset_for_morning()
hud._process(0.0)
r.check(player.sprint_recharge == 0.0 and hud._sprint_label.text == "Sprint hold Shift / L3", "a new morning has it ready: '%s'" % hud._sprint_label.text)
r.check(player.sprint_recharge == 0.0 and hud.stamina() == 1.0, "a new morning has it ready (a full bar)")
s.upgrades.erase("sprint")

View file

@ -553,15 +553,13 @@ func _fallback(r: GameTestRunner, sim: FarmSim) -> void:
sim.animals.sync_from_state()
func _hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var hud := farm.get_node("Hud/AssetHud") as AssetHud
func _hud(r: GameTestRunner, _farm: Node3D, sim: FarmSim) -> void:
var s := sim.campaign.state
hud._process(0.0)
var before := hud.describe()
var before := " · ".join(PauseMenu.asset_counts(s))
s.lose_animal(s.animals_total if not s.is_animal_lost(s.animals_total) else 1)
hud._process(0.05)
r.check(hud.describe() == "Crops %d/%d · Animals %d/%d · Supplies %d" % [s.crops, s.crops_total, s.animals, s.animals_total, s.supplies]
and hud.describe() != before and hud._flash[1] > 0.0 and hud._flash_color[1] == AssetHud.LOSS, "the asset HUD updates and flashes red on a loss: '%s'" % hud.describe())
var after := " · ".join(PauseMenu.asset_counts(s))
r.check(after == "Crops %d/%d · Animals %d/%d · Supplies %d" % [s.crops, s.crops_total, s.animals, s.animals_total, s.supplies]
and after != before, "the pause menu's assets count the loss: '%s'" % after)
## The farm is stripped when the last supplies are carried off with every crop and animal gone.

View file

@ -29,16 +29,16 @@ func run(r: GameTestRunner) -> void:
sim.loot.loot_event.connect(func(kind: StringName, _id: int, _p: Vector3) -> void:
_events[kind] = int(_events.get(kind, 0)) + 1)
r.info("farm sim loaded in %d ms (nav %d cells)" % [sim.load_msec, sim.nav.cell_count()])
r.check(sim.loot.unit_count == 50 and sim.loot.count(S.HOME, LootSystem.Category.CROP) == 30 and sim.campaign.state.crops == 30
and sim.loot.count(S.DORMANT, LootSystem.Category.CROP) == 20,
"30 crop units start at home, 20 more dormant in the two later fields (#13)")
r.check(sim.loot.unit_count == 90 and sim.loot.count(S.HOME, LootSystem.Category.CROP) == 30 and sim.campaign.state.crops == 30
and sim.loot.count(S.DORMANT, LootSystem.Category.CROP) == 60,
"30 crop units start at home, 60 more dormant in the two later fields (#13)")
# #20: the map reaches z 35 now, so its south edge (3 m out) is at z 38; z 18 is inside the map.
var edge_cells := [Vector2(-16.0, -6.0), Vector2(20.0, 38.0), Vector2(50.0, 0.0), Vector2(-16.0, 10.0)].filter(func(p: Vector2) -> bool:
return sim.escape_field[sim.nav.cell_of(p.x, p.y)] == 0)
r.check(edge_cells.size() == 4 and sim.escape_field[sim.nav.cell_of(10.0, -8.0)] > 0, "the farm's edge, all around, is where carriers escape")
r.check(sim.escape_field[sim.nav.cell_of(20.0, 18.0)] > 0, "(20, 18), where the south edge used to be, is inside the map now")
# #20: a carried or dropped crop shows the plant of its own field.
var tokens := [1, 31, 41].map(func(id: int) -> String: return sim.loot._tokens[id].scene_file_path.get_file().get_basename())
var tokens := [1, 31, 61].map(func(id: int) -> String: return sim.loot._tokens[id].scene_file_path.get_file().get_basename())
r.check(tokens == ["plant_007", "plant_004", "plant_001"], "crop tokens match their crop: sunflower, cabbage, corn (%s)" % [tokens])
_steal_and_drop(r, sim, player)
@ -302,7 +302,7 @@ func _night_arrivals(r: GameTestRunner, sim: FarmSim) -> void:
sim.waves.enabled = false
## #13: the two later fields (lettuce/cabbage, ids 31-40; corn, 41-50) start dormant -- hidden,
## #13: the two later fields (lettuce/cabbage, ids 31-60; corn, 61-90) start dormant -- hidden,
## not claimable, not scored -- and sprout on schedule: field A the morning after night 2, field B
## the morning after night 4. Once sprouted a unit is a crop like any other: visible, stealable by
## a crow, and counted in crops_total and the score.
@ -314,15 +314,15 @@ func _staged_fields(r: GameTestRunner, sim: FarmSim) -> void:
_play_to_next_morning(sim)
r.check(c.state.phase == P.MORNING and c.state.nights_survived == 2, "played to the morning after night 2")
var a_ok := true
for id in range(31, 41):
for id in range(31, 61):
a_ok = a_ok and loot.status[id] == S.HOME and loot._units[id].visible
r.check(a_ok, "field A (lettuce/cabbage, 31..40) sprouted after night 2: visible and home")
r.check(a_ok, "field A (lettuce/cabbage, 31..60) sprouted after night 2: visible and home")
var b_dormant := true
for id in range(41, 51):
for id in range(61, 91):
b_dormant = b_dormant and loot.status[id] == S.DORMANT and not loot._units[id].visible
r.check(b_dormant, "field B (corn, 41..50) is still dormant: hidden, not home")
r.check(c.state.crops_total == 30 + 10, "crops_total grew by field A's 10 units")
r.check(not loot.recover(41) and not loot.is_claimed_by(41, -1), "a dormant unit can't be recovered or claimed")
r.check(b_dormant, "field B (corn, 61..90) is still dormant: hidden, not home")
r.check(c.state.crops_total == 30 + 30, "crops_total grew by field A's 30 units")
r.check(not loot.recover(61) and not loot.is_claimed_by(61, -1), "a dormant unit can't be recovered or claimed")
# A crow can claim (by hand, as other tests here do), steal, and carry off a field-A crop: it
# counts exactly like any other crop.
@ -343,19 +343,19 @@ func _staged_fields(r: GameTestRunner, sim: FarmSim) -> void:
_play_to_next_morning(sim)
r.check(c.state.phase == P.MORNING and c.state.nights_survived == 4, "played to the morning after night 4")
var b_ok := true
for id in range(41, 51):
for id in range(61, 91):
b_ok = b_ok and loot.status[id] == S.HOME and loot._units[id].visible
r.check(b_ok, "field B (corn, 41..50) sprouted after night 4: visible and home")
r.check(c.state.crops_total == 30 + 10 + 10, "crops_total grew by field B's 10 units too")
r.check(b_ok, "field B (corn, 61..90) sprouted after night 4: visible and home")
r.check(c.state.crops_total == 30 + 30 + 30, "crops_total grew by field B's 30 units too")
var before2 := c.state.crops
var h2 := es.spawn(EnemySystem.TYPE_CROW, -20.0, 0.0, Vector2.RIGHT)
var d2 := es.resolve_handle(h2)
loot.holder[41] = h2
r.check(loot.pick_up(41, h2), "field B crop 41 can be claimed and picked up")
es.carry[d2] = 41
loot.escape(41, h2)
r.check(c.state.is_crop_lost(41) and loot.status[41] == S.LOST and c.state.crops == before2 - 1,
loot.holder[61] = h2
r.check(loot.pick_up(61, h2), "field B crop 61 can be claimed and picked up")
es.carry[d2] = 61
loot.escape(61, h2)
r.check(c.state.is_crop_lost(61) and loot.status[61] == S.LOST and c.state.crops == before2 - 1,
"a stolen field-B crop is lost and scored like any other")
es.apply_hit(d2, 99)
_step(sim, 1)
@ -368,7 +368,7 @@ func _staged_fields(r: GameTestRunner, sim: FarmSim) -> void:
r.check(restored.crops_total == c.state.crops_total and restored.nights_survived == c.state.nights_survived,
"crops_total and nights_survived survive a save/JSON round trip")
loot.sync_from_state() # as a real load or retry would trigger
r.check(c.state.crops_total == 50, "sync_from_state() repairs crops_total to the same, fully-sprouted total")
r.check(c.state.crops_total == 90, "sync_from_state() repairs crops_total to the same, fully-sprouted total")
## Advances from wherever the campaign is now to the next morning (one full day/night/dawn cycle),

View file

@ -5,12 +5,12 @@ extends RefCounted
## shooter and pumpkin bombs bought at the supply shed, not the workbench (rapid fire and heavy
## seeds, bought at the workbench, need the corn shooter first; a weapon bought goes into its
## hand, bombs into the off-hand); switching the main
## weapon (Tab / 1-2, owned ones only, not in build mode, never the bombs; one no longer owned
## weapon (Tab / the number keys, owned ones only, not in build mode, never the bombs; one no longer owned
## falls back to the pitchfork); the off-hand on its own button (right mouse / LT: with the main
## weapon in hand, both at once, held, not with the right click that leaves build mode); a bomb's
## throw (at the aim, its range clamped), flight, and burst (everything in its radius, crows too,
## nothing beyond, not the scarecrow), its recharge and the morning refill; the models on the
## scarecrow; the HUD's weapon panel; the shed's other weapons; the Propane Torch's band of
## scarecrow; the HUD's hotbar; the shed's other weapons; the Propane Torch's band of
## fire and its flame (#17); and the Alien Ray's beam (#18).
const DT := 1.0 / 60.0
@ -172,8 +172,15 @@ func _switching(r: GameTestRunner, sim: FarmSim) -> void:
var first := c.weapon
_tap(sim, "weapon_2")
r.check(first == W.PITCHFORK and c.weapon == W.CORN_SHOOTER, "1-2 pick one")
r.check(c.equip(W.PUMPKIN_BOMB) and c.weapon == W.CORN_SHOOTER and not InputMap.has_action("weapon_3"),
"the bombs never take the main hand (and there's no third weapon key)")
r.check(c.equip(W.PUMPKIN_BOMB) and c.weapon == W.CORN_SHOOTER, "the bombs never take the main hand")
s.upgrades["shurikens"] = 1 # owned: pitchfork, corn shooter, shurikens (no potato cannon)
_tap(sim, "weapon_3")
var third := c.weapon
_tap(sim, "weapon_4")
r.check(c.owned_main() == [W.PITCHFORK, W.CORN_SHOOTER, W.SHURIKENS] and third == W.SHURIKENS and c.weapon == W.SHURIKENS,
"a number key picks that slot of the weapons owned (3: the shurikens), one past them does nothing")
s.upgrades.erase("shurikens")
_step(sim, 1)
c.equip(W.PITCHFORK)
var east := AT + Vector2(5.0, 0.0)
_step(sim, c.stab_ticks())
@ -310,24 +317,28 @@ func _bombs(r: GameTestRunner, sim: FarmSim) -> void:
func _hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var hud := farm.get_node("Hud/ScarecrowHud") as ScarecrowHud
var c := sim.combat
var cfg := sim.config
var s := sim.campaign.state
var shown := func() -> Array:
return hud.slots().map(func(d: Dictionary) -> Array: return [d["weapon"], d["key"], d["offhand"], d["selected"]])
s.upgrades.erase("corn_shooter")
c.ready_for_morning()
_step(sim, 1)
hud._process(0.0)
var charged: Array = hud._offhand_rows.map(func(l: Label) -> String: return l.text)
var start: Array = shown.call()
r.check(start == [[W.PITCHFORK, 1, false, true], [W.PUMPKIN_BOMB, 0, true, true]],
"the hotbar shows only what's owned: the pitchfork on 1, in hand, then the bombs, ready: %s" % [start])
c.offhand_toward(AT + Vector2(6.0, 0.0))
hud._process(0.0)
var rows: Array = hud._weapon_rows.map(func(l: Label) -> String: return l.text)
var off: Array = hud._offhand_rows.map(func(l: Label) -> String: return l.text)
r.check(rows == ["1 Pitchfork", "2 Corn shooter (supply shed)", "Potato cannon (supply shed)",
"Shurikens (supply shed)", "Propane torch (supply shed)", "Alien ray (supply shed)"],
"the HUD lists the main weapons, the first two by number (no more number keys): %s" % [rows])
r.check(charged == ["Pumpkin bombs"] and off == ["Pumpkin bombs %.0f s" % ceilf(cfg.bomb_cooldown)],
"and the off-hand's bombs, with their recharge: %s, %s" % [charged, off])
r.check(hud._weapon_title.visible and hud._weapon_hint.text.contains("Tab") and hud._offhand_title.text.contains("right mouse"),
"with how to switch, and the off-hand's button")
r.check(not hud.slots()[1]["selected"], "a bomb recharging isn't lit")
s.upgrades["corn_shooter"] = 1
s.upgrades["propane_torch"] = 1
c.equip(W.PROPANE_TORCH)
var mains: Array = shown.call().filter(func(a: Array) -> bool: return not a[2])
r.check(mains == [[W.PITCHFORK, 1, false, false], [W.CORN_SHOOTER, 2, false, false], [W.PROPANE_TORCH, 3, false, true]],
"bought weapons join it in order, numbered by their key, the one in hand lit: %s" % [mains])
sim.build.set_active(true)
r.check(hud.slots().is_empty(), "it gives way to the build hotbar in build mode")
sim.build.set_active(false)
s.upgrades.erase("propane_torch")
s.upgrades.erase("corn_shooter")
s.upgrades.erase("pumpkin_bomb")
_step(sim, 1)
sim.bombs.clear()