From 45f3e83e5418f2098fd76976e0ad1045d8556173 Mon Sep 17 00:00:00 2001 From: Forrest Date: Mon, 5 Oct 2026 14:38:42 -0400 Subject: [PATCH] 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 --- game/scripts/game_config.gd | 6 +++ game/scripts/upgrade_panel.gd | 5 +++ game/scripts/upgrades.gd | 23 ++++++++++ game/tests/test_economy.gd | 79 ++++++++++++++++++++++++++++++++++- 4 files changed, 111 insertions(+), 2 deletions(-) diff --git a/game/scripts/game_config.gd b/game/scripts/game_config.gd index b6b2896..3eb6d2a 100644 --- a/game/scripts/game_config.gd +++ b/game/scripts/game_config.gd @@ -140,6 +140,12 @@ extends Resource "long_range": {"name": "Long-range defenses", "text": "Turrets reach 30% farther", "track": "Defenses", "stat": "turret_range", "mult": 1.3}, "sticky_tar": {"name": "Sticky tar", "text": "Tar patches hold 50% longer", "track": "Defenses", "stat": "trap_slow_time", "mult": 1.5}, } +## An upgrade with "hidden": true (e.g. Alien Ray, Radar, #7/#8) shows only a "?" (no name, text, +## or cost) and can't be bought until the player has collected this much Alien Goop in total +## (Upgrades.goop_collected); then it shows and buys normally for its defined cost. Overridable +## per item with its own "reveal_goop". 5 is about 15 Alien kills at the default 33% drop chance +## (alien_goop_drop_chance) — a few kills in, not instant and not a grind. +@export_range(0, 999) var hidden_reveal_goop: int = 5 @export_group("Assessment") ## The final assessment's weight per category (Assessment): the score is the weighted share of diff --git a/game/scripts/upgrade_panel.gd b/game/scripts/upgrade_panel.gd index 6c597a4..0661f89 100644 --- a/game/scripts/upgrade_panel.gd +++ b/game/scripts/upgrade_panel.gd @@ -112,6 +112,11 @@ func refresh() -> void: var why := Upgrades.blocker(campaign, id) if Upgrades.owned(s, id): done += 1 + if not Upgrades.revealed(s, cfg, id): + # Hidden: no name, description, or cost until its reveal condition is met. + b.text = "?" + b.disabled = true + continue var price := "Done" if Upgrades.owned(s, id) else ResourceStore.describe(Upgrades.cost(cfg, id)) b.text = "%s — %s (%s)" % [u["name"], u["text"], price] if why != "" and why != "Done": diff --git a/game/scripts/upgrades.gd b/game/scripts/upgrades.gd index bbbc574..76c5f1a 100644 --- a/game/scripts/upgrades.gd +++ b/game/scripts/upgrades.gd @@ -23,6 +23,27 @@ static func cost(cfg: GameConfig, id: String) -> Dictionary: return cfg.costs.get(id, {}) +## Total Alien Goop collected this vacation so far: every completed night's "gathered_alien_goop" +## (FarmState.totals(), from night_log) plus the current cycle's own count (night_events). This is +## a running total, not a current balance (spending or being robbed of goop doesn't un-reveal +## anything), so it's unaffected by the shed/pouch and persists through save (night_log is saved) +## and retry (retry restores the morning snapshot, dropping the failed night's own goop). +static func goop_collected(state: FarmState) -> int: + if state == null: + return 0 + return int(state.totals().get("gathered_alien_goop", 0)) + int(state.night_events.get("gathered_alien_goop", 0)) + + +## Whether a shop item's reveal condition is met (always true unless its definition sets +## "hidden": true). A hidden item reveals once goop_collected() reaches its "reveal_goop" (falls +## back to GameConfig.hidden_reveal_goop). +static func revealed(state: FarmState, cfg: GameConfig, id: String) -> bool: + var u: Dictionary = cfg.upgrades.get(id, {}) + if not bool(u.get("hidden", false)): + return true + return goop_collected(state) >= int(u.get("reveal_goop", cfg.hidden_reveal_goop)) + + ## A stat with every owned upgrade applied (barrier_hp is a multiplier, 1 without upgrades). static func value(cfg: GameConfig, state: FarmState, stat: String) -> float: var v := 1.0 if stat == "barrier_hp" else float(cfg.get(stat)) @@ -47,6 +68,8 @@ static func blocker(campaign: CampaignController, id: String) -> String: return "No such upgrade" if owned(s, id): return "Done" + if not revealed(s, cfg, id): + return "Not discovered yet" var needs := String(cfg.upgrades[id].get("requires", "")) if needs != "" and not owned(s, needs): return "Needs the %s first" % String(cfg.upgrades.get(needs, {}).get("name", needs)).to_lower() diff --git a/game/tests/test_economy.gd b/game/tests/test_economy.gd index d9bbee5..54f2db0 100644 --- a/game/tests/test_economy.gd +++ b/game/tests/test_economy.gd @@ -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 := {}