1 """ Tabakutilities. """
6 import pygame.locals as pgl
10 from .constants import DEBUG
11 from .loader import loader
14 def debug_timer(label, debug=False):
15 """ A decorator for printing how long a function took if debug is true.
19 def wrapper(*args, **kw):
20 start_time = time.time()
24 duration = time.time() - start_time
26 print "%s [%g seconds]" % (label, duration)
31 class DetailedTimer(object):
32 """ A detailed timer for overly complex functions.
34 def __init__(self, title, debug=False):
39 # fast funtions with the correct signature
46 print "---- %s ----" % self.title
47 self.times.append(time.time())
51 print " %s: %s" % (label, now - self.times[-1])
52 self.times.append(now)
58 print " %s: %s" % ("total", time.time() - self.times[0])
62 def shadowed_text(text, font_name, size, offset=4):
63 font_black = loader.load_font(font_name, size=size)
64 font_white = loader.load_font(font_name, size=size)
65 background = font_black.render(text, True, (0, 0, 0))
66 foreground = font_white.render(text, True, (255, 255, 255))
67 new_size = (background.get_width() + offset,
68 background.get_height() + offset)
69 base = pygame.surface.Surface(new_size, pgl.SWSURFACE).convert_alpha()
70 base.fill((0, 0, 0, 0))
71 base.blit(background, (offset, offset), None)
72 base.blit(foreground, (0, 0), None)
77 """Return the directory for the save location."""
78 app = "tabakrolletjie"
79 if sys.platform.startswith('win'):
80 if 'APPDATA' in os.environ:
81 return os.path.join(os.environ['APPDATA'], app)
82 return os.path.join(os.path.expanduser('~'), '.' + app)
83 elif 'XDG_DATA_HOME' in os.environ:
84 return os.path.join(os.environ['XDG_DATA_HOME'], app)
85 return os.path.join(os.path.expanduser('~'), '.local', 'share', app)
88 def get_save_file_name():
89 return os.path.join(save_location(), 'savegame.json')
92 def save_file_exists():
93 savefile = get_save_file_name()
94 return os.path.isfile(savefile)