diff gamelib/lab.py @ 24:23720d0fd9a0

Make SCIENCE_TYPE explicit.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 06 May 2012 19:17:04 +0200
parents f6a3b213857b
children efc4f90cfd63
line wrap: on
line diff
--- 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