23 lines
424 B
Python
23 lines
424 B
Python
import json
|
|
from data.cat import Cat
|
|
import os
|
|
|
|
|
|
class SaveData:
|
|
def __init__(self, cat, money=100):
|
|
self.cat = cat
|
|
self.money = money
|
|
|
|
|
|
def save(cat):
|
|
if not os.path.exists("saves"):
|
|
os.mkdir("saves")
|
|
with open(f"saves/{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)
|