Stamp migration ledger entries with the real time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-18 22:49:45 +01:00
parent 656693cc84
commit 568e61799d
2 changed files with 5 additions and 4 deletions

View file

@ -409,8 +409,9 @@ def new_world(now: float, speed: float = 1.0) -> dict:
}
def migrate(world: dict) -> dict:
def migrate(world: dict, now: float | None = None) -> dict:
"""Bring a saved world up to the current shape. Never loses anything."""
now = now or world["city"]["last_tick"]
if world.get("version", 1) < 2:
city = world["city"]
for building in city["buildings"].values():
@ -419,7 +420,6 @@ def migrate(world: dict) -> dict:
city.setdefault("tier", 0)
world["version"] = 2
if world["version"] < 3:
now = world["city"]["last_tick"]
for player in world["players"].values():
for skill in SKILL_IDS:
player["xp"].setdefault(skill, 0)
@ -430,7 +430,7 @@ def migrate(world: dict) -> dict:
player.setdefault("hp_at", now)
world["version"] = 3
if world["version"] < 4:
_sell_useless_stock(world, world["city"]["last_tick"])
_sell_useless_stock(world, now)
world["version"] = 4
return world