Task #5: generic hidden/reveal shop item system

An item definition in GameConfig.upgrades can set "hidden": true
(optionally its own "reveal_goop", else the new config-tunable
hidden_reveal_goop) so the workbench shows only a bare "?" (no name,
text, or cost), disabled, until the player has collected that much
Alien Goop in total. Upgrades.goop_collected()/revealed() derive this
from FarmState.totals() (completed nights) plus night_events (the
current cycle), so it persists through save and retry without any new
stored state. blocker() and buy() both gate on it (covering the co-op
buy-request path too), and UpgradePanel.refresh() shows the "?" row.

No real upgrade ships hidden yet; #7/#8 (Alien Ray, Radar) will use
this mechanism. Test flags a duplicated long_range/sticky_tar hidden
to exercise it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 14:38:42 -04:00
parent 30e64ebeec
commit 45f3e83e54
4 changed files with 111 additions and 2 deletions

View file

@ -4,9 +4,11 @@ extends RefCounted
## through JSON, and on the real farm (FarmSim stepped by hand): the gather points' layout,
## gathering by day only (charges, rooted, cancelled by letting go / a hit / fear, a full pouch,
## nightfall), the shed drop-off, overnight regrowth, retry restoring the morning's materials,
## patching's straw cost, buying the Straw Stuffing upgrade from the workbench's menu, and Alien
## patching's straw cost, buying the Straw Stuffing upgrade from the workbench's menu, Alien
## Goop (#4): dropped only by killed Aliens (thieves) at a config-tunable rate, credited like a
## gathered material, stealable from the shed once it's the stock on top, and surviving retry.
## gathered material, stealable from the shed once it's the stock on top, and surviving retry,
## and hidden/reveal shop items (#5): an item flagged "hidden" shows only "?" and can't be bought
## until enough Alien Goop has been collected in total, then shows and buys normally.
const P := CampaignController.Phase
const DT := 1.0 / 60.0
@ -16,6 +18,7 @@ func run(r: GameTestRunner) -> void:
_store(r)
_state(r)
_goop_persistence(r)
await _hidden_items(r)
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
r.root.add_child(farm)
await r.process_frame
@ -102,6 +105,78 @@ func _goop_persistence(r: GameTestRunner) -> void:
r.check(back != null and back.resources.shed.get("alien_goop", -1) == 0, "the morning snapshot (what's saved) round-trips Alien Goop through JSON")
## Hidden shop items (#5): an item definition can set "hidden": true (optionally its own
## "reveal_goop", else GameConfig.hidden_reveal_goop) so the workbench shows only a bare "?" (no
## name, text, or cost) and refuses the purchase (blocker()/buy(), so this also covers the co-op
## buy-request path) until Upgrades.goop_collected() reaches the threshold; then it shows and buys
## normally for its defined cost. No real upgrade ships hidden yet (#7/#8 will add Alien Ray and
## Radar), so this flags a duplicated long_range/sticky_tar to exercise the mechanism.
func _hidden_items(r: GameTestRunner) -> void:
var seed_cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig
var c := r.make_campaign(seed_cfg)
var cfg := c.config # what blocker()/buy()/refresh() actually read (CampaignController._ready duplicates it)
cfg.upgrades = cfg.upgrades.duplicate(true)
cfg.upgrades["long_range"] = cfg.upgrades["long_range"].duplicate(true)
cfg.upgrades["long_range"]["hidden"] = true
cfg.hidden_reveal_goop = 5
var s := c.state
c.begin_day()
s.resources.shed = cfg.costs["long_range"].duplicate()
r.check(Upgrades.goop_collected(s) == 0 and not Upgrades.revealed(s, cfg, "long_range"),
"a hidden item starts undiscovered (0 Alien Goop collected)")
r.check(Upgrades.blocker(c, "long_range") == "Not discovered yet", "its blocker reason doesn't describe it")
r.check(Upgrades.buy(c, "long_range") == "Long-range defenses: not discovered yet" and not Upgrades.owned(s, "long_range"),
"buy() refuses a hidden item below threshold too (also covers the co-op buy-request path)")
var panel := UpgradePanel.new()
r.root.add_child(panel)
await r.process_frame
panel.setup(c, null, null)
panel.refresh()
var row := panel._rows["long_range"] as Button
r.check(row.text == "?" and row.disabled, "the panel shows a bare '?' for a hidden item, disabled")
s.record_event("gathered_alien_goop", 4)
r.check(Upgrades.goop_collected(s) == 4 and not Upgrades.revealed(s, cfg, "long_range"), "still hidden one goop short of the threshold")
panel.refresh()
r.check(row.text == "?", "still just '?' one goop short")
s.record_event("gathered_alien_goop", 1)
r.check(Upgrades.goop_collected(s) == 5 and Upgrades.revealed(s, cfg, "long_range"), "revealed once goop collected reaches the threshold")
r.check(Upgrades.blocker(c, "long_range") == "", "no longer blocked once revealed (affordable, daytime)")
panel.refresh()
r.check(row.text.contains("Long-range defenses") and row.text.contains("Turrets reach 30% farther") and not row.disabled,
"the panel shows the normal name/text/cost once revealed: '%s'" % row.text)
var msg := Upgrades.buy(c, "long_range")
r.check(Upgrades.owned(s, "long_range") and msg.contains("done:"), "revealed, it buys normally for its defined cost")
panel.queue_free()
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(s.to_dict())))
r.check(back != null and Upgrades.revealed(back, cfg, "long_range") and Upgrades.owned(back, "long_range"),
"reveal and ownership both survive a save (JSON) round-trip")
# A second item, with its own reveal_goop: a completed night's goop (night_log, via totals())
# and the current cycle's own (night_events) both count toward it, and a retry (which restores
# the morning snapshot) drops only the failed night's own, keeping the completed night's.
cfg.upgrades["sticky_tar"] = cfg.upgrades["sticky_tar"].duplicate(true)
cfg.upgrades["sticky_tar"]["hidden"] = true
cfg.upgrades["sticky_tar"]["reveal_goop"] = 3
s.night_events.clear() # isolate night 1's remaining goop from the 5 already recorded above
s.record_event("gathered_alien_goop", 2)
c.advance_phase() # DAY -> DUSK
c.advance_phase() # DUSK -> NIGHT
c.advance_phase() # NIGHT -> DAWN
c.advance_phase() # DAWN -> MORNING of night 2 (closes night 1's log; night_events clears)
r.check(Upgrades.goop_collected(s) == 2 and not Upgrades.revealed(s, cfg, "sticky_tar"),
"a completed night's goop (night_log, via totals()) counts toward a different item's own reveal_goop threshold")
s.record_event("gathered_alien_goop", 1)
r.check(Upgrades.revealed(s, cfg, "sticky_tar"), "the current cycle's own goop (night_events) also counts, revealing it")
var retry_ok := c.retry_night()
r.check(retry_ok and not Upgrades.revealed(c.state, cfg, "sticky_tar") and Upgrades.goop_collected(c.state) == 2,
"a retry (restoring the morning snapshot) drops the failed night's own goop, un-revealing it, but keeps the earlier completed night's")
func _layout(r: GameTestRunner, sim: FarmSim) -> void:
var by_material := {}
var names := {}