This repository has been archived on 2022-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
texty/lib/save.py

22 lines
823 B
Python
Raw Normal View History

2022-02-04 19:35:38 +01:00
from os import path
import yaml
class SaveManager: # manages save and configuration files
def __init__(self):
2022-02-27 12:02:46 +01:00
self.id = "" # game ID
self.currentPrompt = "" # Current prompt
self.inventory = [] # Items in inventory
2022-02-04 19:35:38 +01:00
def load(self):
if(path.exists(f"./saves/{self.id}.yml")):
with open(f"./saves/{self.id}.yml",encoding="utf-8") as f:
data = yaml.load(f,Loader=yaml.SafeLoader)
self.currentPrompt = data["currentPrompt"]
self.inventory = data["inventory"]
return True
return False
def save(self):
2022-04-06 10:03:21 +02:00
data = {"id":self.id,"currentPrompt":self.currentPrompt,"inventory":self.inventory}
2022-02-04 19:35:38 +01:00
with open(f"./saves/{self.id}.yml",mode="w",encoding="utf-8") as f:
yaml.dump(data,f)