Mercurial > sypikslang
comparison gamelib/game_base.py @ 88:74ce25ec2073
Autosave & load support
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 09 May 2012 20:07:14 +0200 |
parents | b503ccb0a86e |
children | 245ef50de84d |
comparison
equal
deleted
inserted
replaced
87:d93e1ea2bd0d | 88:74ce25ec2073 |
---|---|
1 import sys | |
2 import os | |
1 | 3 |
2 | 4 |
3 def get_subclasses(base_class, leaf_only=True): | 5 def get_subclasses(base_class, leaf_only=True): |
4 subclasses = [] | 6 subclasses = [] |
5 for cls in base_class.__subclasses__(): | 7 for cls in base_class.__subclasses__(): |
6 if leaf_only and cls.__subclasses__(): | 8 if leaf_only and cls.__subclasses__(): |
7 # Not a leaf class, and only want leaves | 9 # Not a leaf class, and only want leaves |
8 continue | 10 continue |
9 subclasses.append(cls) | 11 subclasses.append(cls) |
10 return subclasses | 12 return subclasses |
13 | |
14 | |
15 def get_save_filename(): | |
16 """Determine the base filename for auto saves""" | |
17 app = "sypikslang" | |
18 if sys.platform.startswith('win'): | |
19 if "APPDATA" in os.environ: | |
20 base = os.path.join(os.environ["APPDATA"], app) | |
21 else: | |
22 base = os.path.join(os.path.expanduser("~"), "." + app) | |
23 elif 'XDG_DATA_HOME' in os.environ: | |
24 base = os.path.join(os.environ["XDG_DATA_HOME"], app) | |
25 else: | |
26 base = os.path.join(os.path.expanduser("~"), ".local", "share", app) | |
27 if not os.path.exists(base): | |
28 os.makedirs(base, mode=0770) | |
29 if os.path.isdir(base): | |
30 return os.path.join(base, 'gamestate.json') | |
31 print 'save game directory is not a directory %s' % base | |
32 return None | |
11 | 33 |
12 | 34 |
13 class Science(object): | 35 class Science(object): |
14 NAME = None | 36 NAME = None |
15 PREREQUISITES = () | 37 PREREQUISITES = () |