changeset 234:a661b6621ec4

Add testing of triggers and entry / exit functions.
author Simon Cross <hodgestar@gmail.com>
date Thu, 07 Apr 2011 11:05:54 +0200
parents 8ea658969f47
children 169bacba9f48
files scripts/npc-test
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/npc-test	Thu Apr 07 11:05:31 2011 +0200
+++ b/scripts/npc-test	Thu Apr 07 11:05:54 2011 +0200
@@ -50,6 +50,18 @@
         print "Checking", npc_name, "...",
         npc = getattr(game.world.npcs, npc_name)
         dsm = DSM(npc_name, game.world, npc.dsm, npc.state)
+        print "  Loaded %s." % (npc.dsm)
+
+        my_locals = { "world": dsm.world, "state": dsm.states, "npcs": dsm.world.npcs }
+        my_locals.update(DsmEvent().items)
+        for state_name, state in dsm.states.items():
+            print "  Testing triggers for state %s" % state_name
+            for trigger in state.triggers:
+                eval(trigger._matches, {}, my_locals.copy())
+                eval(trigger._next_state, {}, my_locals.copy())
+            print "  Test on_entry and on_exit for state %s" % state_name
+            state.enter(my_locals)
+            state.leave(my_locals)
         print "ok"
     print