Mercurial > fife-parpg
comparison demos/rpg/scripts/gamecontroller.py @ 546:8fee2d2286e9
Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 03 Jun 2010 21:35:06 +0000 |
parents | bc7e3c3122d7 |
children | e59ece21ab3e |
comparison
equal
deleted
inserted
replaced
545:bc7e3c3122d7 | 546:8fee2d2286e9 |
---|---|
216 arg = arg.strip() | 216 arg = arg.strip() |
217 if arg != "": | 217 if arg != "": |
218 cmd.append(arg) | 218 cmd.append(arg) |
219 | 219 |
220 if cmd[0] == "spawn": | 220 if cmd[0] == "spawn": |
221 result = "Usage: spawn [item|actor] [object id] [posx] [posy]" | 221 result = "Usage: spawn [object template] [posx] [posy]" |
222 if len(cmd) != 5: | 222 if len(cmd) != 4: |
223 return result | 223 return result |
224 else: | 224 else: |
225 try: | 225 try: |
226 if cmd[1] == "item": | 226 obj = self._scene.loadObject(cmd[1]) |
227 obj = self._scene.loadItem(cmd[2]) | |
228 elif cmd[1] == "actor": | |
229 obj = self._scene.loadActor(cmd[2]) | |
230 else: | |
231 return result | |
232 except ObjectNotFoundError, e: | 227 except ObjectNotFoundError, e: |
233 result = "Error: Cannot load [" + cmd[2] + "]. It could not be found!" | 228 result = "Error: Cannot load [" + cmd[1] + "]. It could not be found!" |
234 obj = None | 229 obj = None |
235 | 230 |
236 if obj: | 231 if obj: |
237 try: | 232 try: |
238 self._scene.addObjectToScene(obj) | 233 self._scene.addObjectToScene(obj) |
239 obj.position = (float(cmd[3]), float(cmd[4])) | 234 obj.position = (float(cmd[2]), float(cmd[3])) |
240 result = "--OK--" | 235 result = "--OK--" |
241 except ObjectAlreadyInSceneError, e: | 236 except ObjectAlreadyInSceneError, e: |
242 result = "Error: [" + cmd[2] + "] is already on the scene." | 237 result = "Error: [" + cmd[1] + "] is already on the scene." |
243 | 238 |
244 elif cmd[0] == "move": | 239 elif cmd[0] == "move": |
245 result = "Usage: move [object id] [posx] [posy]" | 240 result = "Usage: move [object id] [posx] [posy]" |
246 if len(cmd) != 4: | 241 if len(cmd) != 4: |
247 return result | 242 return result |
250 if obj: | 245 if obj: |
251 obj.position = (float(cmd[2]), float(cmd[3])) | 246 obj.position = (float(cmd[2]), float(cmd[3])) |
252 result = "--OK--" | 247 result = "--OK--" |
253 else: | 248 else: |
254 result = "Error: [" + cmd[1] + "] does not exist on the scene." | 249 result = "Error: [" + cmd[1] + "] does not exist on the scene." |
250 | |
251 elif cmd[0] == "loadmap": | |
252 result = "Usage: loadmap [map name]" | |
253 | |
255 | 254 |
256 return result | 255 return result |
257 | 256 |
258 def newGame(self): | 257 def newGame(self): |
259 self._guicontroller.hideMainMenu() | 258 self._guicontroller.hideMainMenu() |
288 | 287 |
289 def switchMap(self, newmapname): | 288 def switchMap(self, newmapname): |
290 self._switchmaprequested = True | 289 self._switchmaprequested = True |
291 self._newmap = newmapname | 290 self._newmap = newmapname |
292 | 291 |
292 #save before switching scenes | |
293 self._scene.serialize() | 293 self._scene.serialize() |
294 | 294 |
295 def endGame(self): | 295 def endGame(self): |
296 if self._scene: | 296 if self._scene: |
297 self._scene.serialize() | 297 self._scene.serialize() |