migration system
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
@@ -67,7 +68,7 @@ class App:
|
||||
continue
|
||||
try:
|
||||
save = persistence.load(save_name)
|
||||
except persistence.json.JSONDecodeError:
|
||||
except (json.JSONDecodeError, KeyError):
|
||||
print(
|
||||
"There was an error loading your savefile, it may be corrupt :("
|
||||
)
|
||||
|
||||
7
untitled/migration.py
Normal file
7
untitled/migration.py
Normal file
@@ -0,0 +1,7 @@
|
||||
_MIGRATIONS = {}
|
||||
|
||||
|
||||
def migrate(data):
|
||||
while data["version"] in _MIGRATIONS:
|
||||
data = _MIGRATIONS[data["version"]](data)
|
||||
return data
|
||||
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from untitled import PACKAGE_ROOT, model
|
||||
from untitled import PACKAGE_ROOT, migration, model
|
||||
|
||||
SAVE_FOLDER = PACKAGE_ROOT / "saves"
|
||||
|
||||
@@ -26,7 +26,7 @@ def load(name, folder=None):
|
||||
|
||||
with open(save_file) as f:
|
||||
data = json.load(f)
|
||||
|
||||
data = migration.migrate(data)
|
||||
save = model.Save.from_dict(data)
|
||||
|
||||
return save
|
||||
|
||||
Reference in New Issue
Block a user