changeset 94:245ef50de84d

Sanity-check research, schematic and mission classes. (Ironic, no?)
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 09 May 2012 21:22:10 +0200
parents f0bf77787d1e
children 0f437e0584f7
files gamelib/game_base.py gamelib/missions.py gamelib/schematics.py
diffstat 3 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/game_base.py	Wed May 09 21:16:53 2012 +0200
+++ b/gamelib/game_base.py	Wed May 09 21:22:10 2012 +0200
@@ -8,6 +8,8 @@
         if leaf_only and cls.__subclasses__():
             # Not a leaf class, and only want leaves
             continue
+        if hasattr(cls, 'sanity_check'):
+            cls.sanity_check()
         subclasses.append(cls)
     return subclasses
 
@@ -60,3 +62,9 @@
 
     def save_data(self):
         return (self.save_name(), self.points)
+
+    @classmethod
+    def sanity_check(cls):
+        for science, points in cls.PREREQUISITES:
+            assert issubclass(science, Science)
+            assert isinstance(points, int)
--- a/gamelib/missions.py	Wed May 09 21:16:53 2012 +0200
+++ b/gamelib/missions.py	Wed May 09 21:22:10 2012 +0200
@@ -60,6 +60,10 @@
     def get_data(self, key):
         return self.data.get(key, None)
 
+    @classmethod
+    def sanity_check(cls):
+        pass
+
     def can_attempt(self, state):
         """Can we currently attempt the mission"""
         if self.get_data('completed'):
@@ -292,7 +296,6 @@
     def attempt_with(self, categorised, state):
         rep = randint(5, 10)
 
-        print categorised
         if cat.MIND_CONTROL in categorised:
             result = (
                 "Your creative use of science has paid off nicely.")
--- a/gamelib/schematics.py	Wed May 09 21:16:53 2012 +0200
+++ b/gamelib/schematics.py	Wed May 09 21:22:10 2012 +0200
@@ -56,6 +56,13 @@
             power += self.POWER_INCREMENT * self.points
         return power
 
+    @classmethod
+    def sanity_check(cls):
+        for science, points in cls.PREREQUISITES:
+            assert issubclass(science, Science)
+            assert isinstance(points, int)
+        assert isinstance(cls.CATEGORIES, tuple)
+
 
 class MachineGun(Schematic):
     NAME = "machine gun"