From: Neil Date: Sat, 10 Sep 2016 20:36:07 +0000 (+0200) Subject: Add more save file helpers X-Git-Tag: tabakrolletjie-v1.0.0~41^2~1 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=1460205d8be5271a1e9d7abc5b24fb5157b4a9ae;p=tabakrolletjie.git Add more save file helpers --- 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)