Mercurial > rinkhals
comparison gamelib/toolbar.py @ 466:3d173ea43ad5
Add version number to saved games.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Tue, 24 Nov 2009 20:53:54 +0000 |
parents | 279caa00f3fa |
children | 67574723427e |
comparison
equal
deleted
inserted
replaced
465:263dea6d226b | 466:3d173ea43ad5 |
---|---|
6 import constants | 6 import constants |
7 import buildings | 7 import buildings |
8 import equipment | 8 import equipment |
9 import cursors | 9 import cursors |
10 import engine | 10 import engine |
11 import version | |
11 | 12 |
12 class OpaqueLabel(gui.Label): | 13 class OpaqueLabel(gui.Label): |
13 def __init__(self, value, **params): | 14 def __init__(self, value, **params): |
14 gui.Label.__init__(self, value, **params) | 15 gui.Label.__init__(self, value, **params) |
15 if 'width' in params: | 16 if 'width' in params: |
166 | 167 |
167 def save(): | 168 def save(): |
168 if dialog.value is None: | 169 if dialog.value is None: |
169 return | 170 return |
170 data = self.gameboard.save_game() | 171 data = self.gameboard.save_game() |
171 xml = xmlrpclib.dumps((data,), "foxassault") | 172 params = (version.SAVE_GAME_VERSION, data) |
173 xml = xmlrpclib.dumps(params, "foxassault") | |
172 try: | 174 try: |
173 open(dialog.value, "wb").write(xml) | 175 open(dialog.value, "wb").write(xml) |
174 except Exception, e: | 176 except Exception, e: |
175 print "Failed to save game: %s" % (e,) | 177 print "Failed to save game: %s" % (e,) |
176 | 178 |
186 return | 188 return |
187 try: | 189 try: |
188 xml = open(dialog.value, "rb").read() | 190 xml = open(dialog.value, "rb").read() |
189 params, methodname = xmlrpclib.loads(xml) | 191 params, methodname = xmlrpclib.loads(xml) |
190 if methodname != "foxassault": | 192 if methodname != "foxassault": |
191 raise ValueError("Bad XML save game.") | 193 raise ValueError("File does not appear to be a " |
192 data = params[0] | 194 "Fox Assault save game.") |
195 save_version = params[0] | |
196 if save_version != version.SAVE_GAME_VERSION: | |
197 raise ValueError("Incompatible save game version.") | |
198 data = params[1] | |
193 except Exception, e: | 199 except Exception, e: |
194 "Failed to load game: %s" % (e,) | 200 "Failed to load game: %s" % (e,) |
195 return | 201 return |
196 | 202 |
197 self.gameboard.restore_game(data) | 203 self.gameboard.restore_game(data) |