Mercurial > boomslang
comparison pyntnclick/gamescreen.py @ 792:bdaffaa8b6bf pyntnclick
Loading and saving! (Plus a bunch of other stuff to make it possible.)
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 27 Jan 2013 12:43:28 +0200 |
parents | 43b49f1de828 |
children | bcc9277a23e6 |
comparison
equal
deleted
inserted
replaced
791:56ec01e51f3d | 792:bdaffaa8b6bf |
---|---|
121 else: | 121 else: |
122 self.down_button.enable() | 122 self.down_button.enable() |
123 | 123 |
124 @property | 124 @property |
125 def slot_items(self): | 125 def slot_items(self): |
126 return self.game.inventory()[self.inv_offset:][:len(self.slots)] | 126 item_names = self.game.inventory()[self.inv_offset:][:len(self.slots)] |
127 return [self.game.items[name] for name in item_names] | |
127 | 128 |
128 def mouse_down(self, event, widget): | 129 def mouse_down(self, event, widget): |
129 if event.button != 1: | 130 if event.button != 1: |
130 self.game.set_tool(None) | 131 self.game.set_tool(None) |
131 | 132 |
255 | 256 |
256 def process_event(self, event_name, data): | 257 def process_event(self, event_name, data): |
257 getattr(self, 'game_event_%s' % event_name, lambda d: None)(data) | 258 getattr(self, 'game_event_%s' % event_name, lambda d: None)(data) |
258 | 259 |
259 def game_event_restart(self, data): | 260 def game_event_restart(self, data): |
260 self.reset_game(self.create_initial_state()) | 261 self.reset_game() |
262 | |
263 def get_save_dir(self): | |
264 return self.gd.get_default_save_location() | |
265 | |
266 def game_event_load(self, data): | |
267 state = self.gd.game_state_class().load_game( | |
268 self.get_save_dir(), 'savegame') | |
269 # TODO: Handle this better. | |
270 if state is not None: | |
271 self.reset_game(state) | |
272 | |
273 def game_event_save(self, data): | |
274 self.game.data.save_game(self.get_save_dir(), 'savegame') | |
261 | 275 |
262 def reset_game(self, game_state=None): | 276 def reset_game(self, game_state=None): |
263 self._clear_all() | 277 self._clear_all() |
264 self.game = self.create_initial_state() | 278 self.game = self.create_initial_state(game_state) |
265 | 279 |
266 self.screen_modal = self.container.add( | 280 self.screen_modal = self.container.add( |
267 ModalStackContainer(self.container.rect.copy(), self.gd)) | 281 ModalStackContainer(self.container.rect.copy(), self.gd)) |
268 self.inner_container = self.screen_modal.add( | 282 self.inner_container = self.screen_modal.add( |
269 Container(self.container.rect.copy(), self.gd)) | 283 Container(self.container.rect.copy(), self.gd)) |
292 | 306 |
293 def change_scene(self, scene_name): | 307 def change_scene(self, scene_name): |
294 for scene_widget in reversed(self.scene_modal.children[:]): | 308 for scene_widget in reversed(self.scene_modal.children[:]): |
295 self.scene_modal.remove(scene_widget) | 309 self.scene_modal.remove(scene_widget) |
296 scene_widget.scene.leave() | 310 scene_widget.scene.leave() |
297 scene = self.game.scenes[scene_name] | 311 self.game.data.set_current_scene(scene_name) |
298 self.game.current_scene = scene | 312 self._add_scene(self.game.scenes[scene_name]) |
299 self._add_scene(scene) | |
300 | 313 |
301 def show_detail(self, detail_name): | 314 def show_detail(self, detail_name): |
302 self._add_scene(self.game.detail_views[detail_name], True) | 315 self._add_scene(self.game.detail_views[detail_name], True) |
303 | 316 |
304 def _add_scene(self, scene, detail=False): | 317 def _add_scene(self, scene, detail=False): |