Mercurial > mamba
comparison mamba/gamestate.py @ 167:ce30befccc94
Missing files
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Wed, 14 Sep 2011 00:56:44 +0200 |
parents | |
children | 321f2eef40e3 |
comparison
equal
deleted
inserted
replaced
166:bea4857487de | 167:ce30befccc94 |
---|---|
1 import os | |
2 | |
3 try: | |
4 import json | |
5 except ImportError: | |
6 import simplejson as json # pyflakes:ignore | |
7 | |
8 from mamba.data import filepath | |
9 from mamba.options import options | |
10 | |
11 | |
12 levels = [] | |
13 unlocked_levels = set() | |
14 done_levels = set() | |
15 | |
16 | |
17 def load_state(): | |
18 global unlocked_levels, done_levels | |
19 fn = os.path.join(options.save_location, 'gamestate.json') | |
20 if os.access(fn, os.R_OK): | |
21 f = open(fn, 'r') | |
22 state = json.load(f) | |
23 f.close() | |
24 unlocked_levels = set(state['unlocked_levels']) | |
25 done_levels = set(state['done_levels']) | |
26 else: | |
27 unlocked_levels = set((0,)) | |
28 | |
29 | |
30 def save_state(): | |
31 fn = os.path.join(options.save_location, 'gamestate.json') | |
32 if not os.path.isdir(options.save_location): | |
33 os.mkedirs(options.save_location) | |
34 f = open(fn, 'w') | |
35 json.dump({ | |
36 'unlocked_levels': list(unlocked_levels), | |
37 'done_levels': list(done_levels), | |
38 }, f) | |
39 f.close() | |
40 | |
41 | |
42 def load_levels(): | |
43 global levels | |
44 f = open(filepath('levels/index.txt')) | |
45 levels = [] | |
46 for line in f.readlines(): | |
47 line = line.strip() | |
48 if line and line[0] != '#': | |
49 levels.append(line) |