Add free-text stat type to the world-state RPG layer

Numeric stats couldn't represent things like worn armor or held items.
A stat can now be marked type: "text" — the AI reports the new full
value instead of a delta, with no clamping/bands (cooldown still
applies). Updated the scenario editor's stat kind selector, the
World State drawer's stat display, and the emit-rule prompt; added
tests and an outfit stat to the RPG demo scenario.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parththakkar106
2026-07-21 17:35:57 +05:30
co-authored by Claude Sonnet 5
parent db1170d0db
commit 42073d5d89
5 changed files with 142 additions and 33 deletions
+19 -1
View File
@@ -12,6 +12,7 @@ SCHEMA = {
"bands": [[0, 20, "very weak"], [20, 40, "hurt"],
[40, 60, "minor damage"], [60, 90, "healthy"],
[90, 100, "full health"]]},
"outfit": {"type": "text", "initial": "traveling clothes", "desc": "What the player is wearing"},
},
"npcs": {
"gwen": {
@@ -40,12 +41,29 @@ def fresh():
def test_instantiate_uses_initials():
ws = fresh()
assert ws["world"] == {"day": 1}
assert ws["player"] == {"hp": 100}
assert ws["player"] == {"hp": 100, "outfit": "traveling clothes"}
# Each defined NPC is instantiated up front with its own stats.
assert ws["npc"] == {"gwen": {"trust": 0}, "drake": {"ferocity": 50}}
assert ws["milestones"] == {}
def test_text_stat_replaces_value():
ws, report = w.apply_delta(fresh(), SCHEMA, {"player.outfit": "muddy cloak"}, 1)
assert ws["player"]["outfit"] == "muddy cloak"
assert report["applied"][0] == {"path": "player.outfit", "old": "traveling clothes", "new": "muddy cloak"}
def test_text_stat_rejects_non_string():
ws, report = w.apply_delta(fresh(), SCHEMA, {"player.outfit": 5}, 1)
assert ws["player"]["outfit"] == "traveling clothes"
assert report["rejected"][0]["reason"] == "not a string"
def test_text_stat_noop_when_unchanged():
ws, report = w.apply_delta(fresh(), SCHEMA, {"player.outfit": "traveling clothes"}, 1)
assert report["applied"] == []
def test_per_npc_distinct_stats():
ws, _ = w.apply_delta(fresh(), SCHEMA, {"npc.drake.ferocity": 20}, 1)
assert ws["npc"]["drake"]["ferocity"] == 70