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)")
|
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()
|
row = db.execute("SELECT data FROM world WHERE id = 1").fetchone()
|
||||||
if row:
|
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
|
self.world["config"]["speed"] = speed
|
||||||
else:
|
else:
|
||||||
self.world = game.new_world(time.time(), speed)
|
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."""
|
"""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:
|
if world.get("version", 1) < 2:
|
||||||
city = world["city"]
|
city = world["city"]
|
||||||
for building in city["buildings"].values():
|
for building in city["buildings"].values():
|
||||||
|
|
@ -419,7 +420,6 @@ def migrate(world: dict) -> dict:
|
||||||
city.setdefault("tier", 0)
|
city.setdefault("tier", 0)
|
||||||
world["version"] = 2
|
world["version"] = 2
|
||||||
if world["version"] < 3:
|
if world["version"] < 3:
|
||||||
now = world["city"]["last_tick"]
|
|
||||||
for player in world["players"].values():
|
for player in world["players"].values():
|
||||||
for skill in SKILL_IDS:
|
for skill in SKILL_IDS:
|
||||||
player["xp"].setdefault(skill, 0)
|
player["xp"].setdefault(skill, 0)
|
||||||
|
|
@ -430,7 +430,7 @@ def migrate(world: dict) -> dict:
|
||||||
player.setdefault("hp_at", now)
|
player.setdefault("hp_at", now)
|
||||||
world["version"] = 3
|
world["version"] = 3
|
||||||
if world["version"] < 4:
|
if world["version"] < 4:
|
||||||
_sell_useless_stock(world, world["city"]["last_tick"])
|
_sell_useless_stock(world, now)
|
||||||
world["version"] = 4
|
world["version"] = 4
|
||||||
return world
|
return world
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue