changeset 217:fcc5eca8eaca

Add explicit starting state to avoid it magically appearing later.
author Simon Cross <hodgestar@gmail.com>
date Thu, 07 Apr 2011 00:59:08 +0200
parents 023eea4ad4a5
children 7ee5bd883d62 2d5dfec4cd11
files data/game.json skaapsteker/dialogue.py skaapsteker/sprites/base.py
diffstat 3 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/data/game.json	Thu Apr 07 00:47:02 2011 +0200
+++ b/data/game.json	Thu Apr 07 00:59:08 2011 +0200
@@ -13,8 +13,8 @@
         "teapot": { "type": "TeaPot", "level": "level1", "pos": [13, 2] }
     },
     "npcs": {
-        "monk": { "type": "Monk", "level": "level1", "pos": [15, 16], "dsm": "npcs/monk.json" },
-        "guard": { "type": "Guard", "level": "level2", "pos": [10, 3], "dsm": "npcs/guard.json" }
+        "monk": { "type": "Monk", "level": "level1", "pos": [15, 16], "dsm": "npcs/monk.json", "state": "start" },
+        "guard": { "type": "Guard", "level": "level2", "pos": [10, 3], "dsm": "npcs/guard.json", "state": "start" }
     },
     "levels": {
         "level1" : "level1",
--- a/skaapsteker/dialogue.py	Thu Apr 07 00:47:02 2011 +0200
+++ b/skaapsteker/dialogue.py	Thu Apr 07 00:59:08 2011 +0200
@@ -15,17 +15,15 @@
            Something to allow states to introspect the game state with.
        """
 
-    def __init__(self, name, world, json_filename):
-        me = getattr(world.npcs, name)
-        self.state = getattr(me, 'state', 'start')
-        me.state = self.state
+    def __init__(self, name, world, json_filename, state):
+        self.state = state
         self.world = world
         self.states = AttrDict()
         src = json.loads(data.load(json_filename).read())
         for state, state_src in src.iteritems():
             pseudo_path = [json_filename, state]
             self.states[state] = DsmState(state, state_src, pseudo_path)
-        assert self.state in self.states, "DSM must have start state"
+        assert self.state in self.states, "DSM must have start state %r" % (self.state,)
 
     def get_state(self):
         return self.states[self.state]
@@ -42,6 +40,7 @@
         if next_state.name in self.states:
             self.states[self.state].leave(my_locals)
             self.state = next_state.name
+            # TODO: update self.world to reflect new state?
             self.states[self.state].enter(my_locals)
 
     def choice(self, i):
--- a/skaapsteker/sprites/base.py	Thu Apr 07 00:47:02 2011 +0200
+++ b/skaapsteker/sprites/base.py	Thu Apr 07 00:59:08 2011 +0200
@@ -136,8 +136,8 @@
         AnimatedGameSprite.__init__(self, pos, **opts)
         self._layer = Layers.PLAYER
 
-    def setup(self, name, world, dsm):
-        self.dsm = dialogue.DSM(name, world, dsm)
+    def setup(self, name, world, dsm, state):
+        self.dsm = dialogue.DSM(name, world, dsm, state)
 
 
     def collided_player(self, player):