Mercurial > pyntnclick
comparison gamelib/state.py @ 498:168e9424fe91
Perform a deepcopy of INITIAL_DATA to allow mutable initial data to be used safely.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Mon, 30 Aug 2010 00:16:14 +0200 |
parents | a7ed199f69d5 |
children | 93ddcac0b772 |
comparison
equal
deleted
inserted
replaced
497:0b33a502660c | 498:168e9424fe91 |
---|---|
1 """Utilities and base classes for dealing with scenes.""" | 1 """Utilities and base classes for dealing with scenes.""" |
2 | |
3 import copy | |
2 | 4 |
3 from albow.resource import get_image, get_font | 5 from albow.resource import get_image, get_font |
4 from albow.utils import frame_rect | 6 from albow.utils import frame_rect |
5 from widgets import BoomLabel | 7 from widgets import BoomLabel |
6 from pygame.rect import Rect | 8 from pygame.rect import Rect |
234 INITIAL_DATA = None | 236 INITIAL_DATA = None |
235 | 237 |
236 def __init__(self): | 238 def __init__(self): |
237 self.data = {} | 239 self.data = {} |
238 if self.INITIAL_DATA: | 240 if self.INITIAL_DATA: |
239 self.data.update(self.INITIAL_DATA) | 241 # deep copy of INITIAL_DATA allows lists, sets and |
242 # other mutable types to safely be used in INITIAL_DATA | |
243 self.data.update(copy.deepcopy(self.INITIAL_DATA)) | |
240 | 244 |
241 def set_data(self, key, value): | 245 def set_data(self, key, value): |
242 self.data[key] = value | 246 self.data[key] = value |
243 | 247 |
244 def get_data(self, key): | 248 def get_data(self, key): |