# HG changeset patch # User Jeremy Thurgood # Date 1336324624 -7200 # Node ID 23720d0fd9a0e95a565c7347da05b8736ab8fd4a # Parent f6a3b213857ba9058df682edb4026c25a87e4099 Make SCIENCE_TYPE explicit. diff -r f6a3b213857b -r 23720d0fd9a0 gamelib/lab.py --- a/gamelib/lab.py Sun May 06 19:06:28 2012 +0200 +++ b/gamelib/lab.py Sun May 06 19:17:04 2012 +0200 @@ -23,21 +23,19 @@ def _load_data(self, init_data): for name, points in init_data['science'].iteritems(): - module, cls = name.split('.') - if module == 'products': + science_type, cls = name.split('.') + if science_type == 'product': science = getattr(products, cls) - elif module == 'research': + elif science_type == 'research': science = getattr(research, cls) else: - raise ValueError("Unknown science type: %s" % (module,)) + raise ValueError("Unknown science type: %s" % (science_type,)) self._gain_science(science(points)) def save_data(self): data = {'science': {}} for science in self.science: - science_class = type(science) - name = "%s.%s" % (science_class.__module__.split('.')[-1], - science_class.__name__) + name = "%s.%s" % (science.SCIENCE_TYPE, type(science).__name__) data['science'][name] = science.points return data diff -r f6a3b213857b -r 23720d0fd9a0 gamelib/products.py --- a/gamelib/products.py Sun May 06 19:06:28 2012 +0200 +++ b/gamelib/products.py Sun May 06 19:17:04 2012 +0200 @@ -8,6 +8,7 @@ COST = 0 UPGRADE_REQUIREMENT = 1 STARTING_PRODUCT = False + SCIENCE_TYPE = 'product' def __init__(self, points=0): self.points = points diff -r f6a3b213857b -r 23720d0fd9a0 gamelib/research.py --- a/gamelib/research.py Sun May 06 19:06:28 2012 +0200 +++ b/gamelib/research.py Sun May 06 19:17:04 2012 +0200 @@ -1,6 +1,7 @@ class ResearchArea(object): NAME = None PREREQUISITES = () + SCIENCE_TYPE = 'research' def __init__(self, points=0): self.points = points diff -r f6a3b213857b -r 23720d0fd9a0 gamelib/tests/test_lab.py --- a/gamelib/tests/test_lab.py Sun May 06 19:06:28 2012 +0200 +++ b/gamelib/tests/test_lab.py Sun May 06 19:17:04 2012 +0200 @@ -44,5 +44,5 @@ # Add a product and check that it gets saved as well. lab._gain_science(products.LightningGun()) new_science = dict( - LAB_DATA['science'].items() + [('products.LightningGun', 0)]) + LAB_DATA['science'].items() + [('product.LightningGun', 0)]) self.assertEqual({'science': new_science}, lab.save_data())