A lot
This commit is contained in:
19
data/save.py
Normal file
19
data/save.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import json
|
||||
from data.cat import Cat
|
||||
|
||||
|
||||
class SaveData:
|
||||
def __init__(self, cat, money=100):
|
||||
self.cat = cat
|
||||
self.money = money
|
||||
|
||||
|
||||
def save(cat):
|
||||
with open(f"{cat.name}.kitten", "w") as f:
|
||||
json.dump(cat.to_dict(), f)
|
||||
|
||||
|
||||
def load(filepath):
|
||||
with open(filepath) as f:
|
||||
raw = json.load(f)
|
||||
return Cat(**raw)
|
||||
Reference in New Issue
Block a user