From 1460205d8be5271a1e9d7abc5b24fb5157b4a9ae Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 10 Sep 2016 22:36:07 +0200 Subject: [PATCH] Add more save file helpers --- tabakrolletjie/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tabakrolletjie/utils.py b/tabakrolletjie/utils.py index 6be4469..6f9e133 100644 --- a/tabakrolletjie/utils.py +++ b/tabakrolletjie/utils.py @@ -4,6 +4,8 @@ import functools import time import pygame.surface import pygame.locals as pgl +import os +import sys from .constants import DEBUG from .loader import loader @@ -69,3 +71,24 @@ def shadowed_text(text, font_name, size, offset=4): base.blit(background, (offset, offset), None) base.blit(foreground, (0, 0), None) return base + + +def save_location(): + """Return the directory for the save location.""" + app = "tabakrolletjie" + if sys.platform.startswith('win'): + if 'APPDATA' in os.environ: + return os.path.join(os.environ['APPDATA'], app) + return os.path.join(os.path.expanduser('~'), '.' + app) + elif 'XDG_DATA_HOME' in os.environ: + return os.path.join(os.environ['XDG_DATA_HOME'], app) + return os.path.join(os.path.expanduser('~'), '.local', 'share', app) + + +def get_save_file_name(): + return os.path.join(save_location(), 'savegame.json') + + +def save_file_exists(): + savefile = get_save_file_name() + return os.path.isfile(savefile) -- 2.34.1