Add a world-state edit mode for overriding live RPG values
Players/authors can now directly correct the live values of stats the
schema already defines (health, trust, flags, milestones, etc.) without
waiting for the AI to emit a delta. New apply_override() sets values
absolutely rather than adding deltas, and — unlike the AI-facing
apply_delta() — bypasses cooldown/max_delta_per_turn and lets
milestones be un-set, since this is a deliberate correction rather
than a turn to police. Exposed via PUT /adventures/{id}/world-state
and an edit toggle in the World State drawer. Also fixes the
schema-editor stat-kind dropdown and free-text initial-value input
to size consistently with the numeric fields next to them.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
8c02fe30d7
commit
141eec7c64
@@ -163,6 +163,22 @@ def test_world_state_endpoint(client):
|
||||
assert body["state"]["player"]["hp"] == 70
|
||||
|
||||
|
||||
def test_override_world_state_endpoint(client):
|
||||
r = client.put(f"/api/adventures/{client.adv_id}/world-state",
|
||||
json={"player.hp": 5, "flags.alarm": True, "npc.bogus.trust": 1})
|
||||
assert r.status_code == 200, r.text
|
||||
body = r.json()
|
||||
assert body["state"]["player"]["hp"] == 5
|
||||
assert body["state"]["flags"]["alarm"] is True
|
||||
assert body["report"]["rejected"][0]["reason"] == "unknown npc"
|
||||
# persisted to the DB, not just the response.
|
||||
assert _world(client.adv_id)["player"]["hp"] == 5
|
||||
|
||||
# bypasses max_delta_per_turn (30) — a direct correction, not a turn.
|
||||
r = client.put(f"/api/adventures/{client.adv_id}/world-state", json={"player.hp": 100})
|
||||
assert r.json()["state"]["player"]["hp"] == 100
|
||||
|
||||
|
||||
def test_undo_reverts_world_state(client):
|
||||
_play(client)
|
||||
assert _world(client.adv_id)["player"]["hp"] == 70
|
||||
|
||||
Reference in New Issue
Block a user