X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Futils.py;h=b237467ded10e499d5b8f4b69c76816d87a6c25e;hb=94ca43faf86e1ee6ab6e15b6da84eaa2d62a0c44;hp=6f9e133cb999cd57b20dd64f65f251f4516415e3;hpb=9825966c393bb5924fbb9f2d0776c90cc0e6f785;p=tabakrolletjie.git diff --git a/tabakrolletjie/utils.py b/tabakrolletjie/utils.py index 6f9e133..b237467 100644 --- a/tabakrolletjie/utils.py +++ b/tabakrolletjie/utils.py @@ -6,6 +6,7 @@ import pygame.surface import pygame.locals as pgl import os import sys +import json from .constants import DEBUG from .loader import loader @@ -92,3 +93,19 @@ def get_save_file_name(): def save_file_exists(): savefile = get_save_file_name() return os.path.isfile(savefile) + + +def get_save_data(): + savefile = get_save_file_name() + with open(savefile, 'rb') as f: + data = json.load(f) + return data + + +def write_save_file(json_data): + save_dir = save_location() + if not os.path.exists(save_dir): + os.makedirs(save_dir) + savefile = get_save_file_name() + with open(savefile, 'wb') as f: + json.dump(json_data, f, indent=3)