Mercurial > rinkhals
comparison gamelib/savegame.py @ 510:3e4bb2c9556c
Lazy loading of save game snapshots.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Thu, 26 Nov 2009 23:15:04 +0000 |
parents | 77a3f7f1c856 |
children | b112bcf4d435 |
comparison
equal
deleted
inserted
replaced
509:77a3f7f1c856 | 510:3e4bb2c9556c |
---|---|
134 body.td(button_cancel, style=td_style, align=1) | 134 body.td(button_cancel, style=td_style, align=1) |
135 | 135 |
136 title = gui.Label(title_txt, cls=cls + ".title.label") | 136 title = gui.Label(title_txt, cls=cls + ".title.label") |
137 gui.Dialog.__init__(self, title, body) | 137 gui.Dialog.__init__(self, title, body) |
138 | 138 |
139 if games: | |
140 self.save_list.group.value = games[0] | |
141 | |
139 def get_fullpath(self): | 142 def get_fullpath(self): |
140 """Return the fullpath of the select save game file or None.""" | 143 """Return the fullpath of the select save game file or None.""" |
141 if self.value is None: | 144 if self.value is None: |
142 return None | 145 return None |
143 return os.path.join(self.save_folder, self.value + ".xml") | 146 return os.path.join(self.save_folder, self.value + ".xml") |
149 root, ext = os.path.splitext(filename) | 152 root, ext = os.path.splitext(filename) |
150 if not os.path.isfile(fullpath): | 153 if not os.path.isfile(fullpath): |
151 continue | 154 continue |
152 if ext != ".xml": | 155 if ext != ".xml": |
153 continue | 156 continue |
154 self.save_games[root] = self._create_image_widget(fullpath) | 157 self.save_games[root] = (fullpath, None) |
155 | 158 |
156 def _create_image_widget(self, fullpath): | 159 def _create_image_widget(self, fullpath): |
157 """Create an image showing the contents of a save game file.""" | 160 """Create an image showing the contents of a save game file.""" |
158 try: | 161 try: |
159 data, screenshot, level_name, timestamp = read_savegame(fullpath) | 162 data, screenshot, level_name, timestamp = read_savegame(fullpath) |
185 self.name_input.value = self.save_list.value | 188 self.name_input.value = self.save_list.value |
186 | 189 |
187 for w in self.image_container.widgets: | 190 for w in self.image_container.widgets: |
188 self.image_container.remove(w) | 191 self.image_container.remove(w) |
189 | 192 |
190 image_widget = self.save_games[self.save_list.value] | 193 name = self.save_list.value |
191 self.image_container.add(image_widget, 0, 0) | 194 fullpath, widget = self.save_games[name] |
195 if widget is None: | |
196 widget = self._create_image_widget(fullpath) | |
197 self.save_games[name] = (fullpath, widget) | |
198 | |
199 self.image_container.add(widget, 0, 0) | |
192 | 200 |
193 def _click_ok(self): | 201 def _click_ok(self): |
194 if self.name_input: | 202 if self.name_input: |
195 self.value = self.name_input.value | 203 self.value = self.name_input.value |
196 else: | 204 else: |