Stamp migration ledger entries with the real time
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
656693cc84
commit
568e61799d
2 changed files with 5 additions and 4 deletions
3
app.py
3
app.py
|
|
@ -56,7 +56,8 @@ class Store:
|
|||
db.execute("CREATE TABLE IF NOT EXISTS world (id INTEGER PRIMARY KEY CHECK (id = 1), data TEXT NOT NULL)")
|
||||
row = db.execute("SELECT data FROM world WHERE id = 1").fetchone()
|
||||
if row:
|
||||
self.world = game.migrate(json.loads(row[0]))
|
||||
world = json.loads(row[0])
|
||||
self.world = game.migrate(world, time.time() + world["config"].get("clock_offset", 0))
|
||||
self.world["config"]["speed"] = speed
|
||||
else:
|
||||
self.world = game.new_world(time.time(), speed)
|
||||
|
|
|
|||
6
game.py
6
game.py
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue