annotate scripts/npc-test @ 222:2cbeeef5867c

Fix npc tester (again).
author Simon Cross <hodgestar@gmail.com>
date Thu, 07 Apr 2011 01:15:47 +0200
parents a4c4e2f34162
children 13b912f40a10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
2 "Skaapsteker npc tester"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
3
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
4 import os.path
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
5 import sys
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
6 import optparse
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
7 from pprint import pprint
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
8
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
9 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
10
196
a4c4e2f34162 Remove DummyWorld since npc-test now uses the real world.
Simon Cross <hodgestar@gmail.com>
parents: 195
diff changeset
11 from skaapsteker.dialogue import DSM, DsmEvent
195
445a28f4b38e Fix npc tester.
Simon Cross <hodgestar@gmail.com>
parents: 153
diff changeset
12 from skaapsteker.gamestate import GameState
153
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
13
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
14
222
2cbeeef5867c Fix npc tester (again).
Simon Cross <hodgestar@gmail.com>
parents: 196
diff changeset
15 def run(npc_name):
195
445a28f4b38e Fix npc tester.
Simon Cross <hodgestar@gmail.com>
parents: 153
diff changeset
16 game = GameState("game.json")
222
2cbeeef5867c Fix npc tester (again).
Simon Cross <hodgestar@gmail.com>
parents: 196
diff changeset
17 npc = getattr(game.world.npcs, npc_name)
2cbeeef5867c Fix npc tester (again).
Simon Cross <hodgestar@gmail.com>
parents: 196
diff changeset
18 dsm = DSM(npc_name, game.world, npc.dsm, npc.state)
153
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
19
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
20 print "States:"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
21 print "-------"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
22 pprint(dsm.states.keys())
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
23 print
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
24
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
25 while True:
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
26 state = dsm.get_state()
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
27 print "%s:" % dsm.state, state.text
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
28 print "--"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
29 for i, choice in state.choices:
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
30 print "%d: %s" % (i, choice)
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
31 print "L: Leave"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
32 print "--"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
33
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
34 key = raw_input("Choice? ")
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
35 key = key.strip().upper()
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
36 if key == "L":
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
37 break
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
38 elif key.isdigit():
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
39 dsm.choice(int(key))
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
40
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
41 print "--"
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
42
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
43
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
44 def main():
222
2cbeeef5867c Fix npc tester (again).
Simon Cross <hodgestar@gmail.com>
parents: 196
diff changeset
45 p = optparse.OptionParser(usage="%prog [options] <npc name>")
153
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
46 opts, args = p.parse_args()
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
47 if len(args) != 1:
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
48 p.error("Must provide an npc json file")
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
49 run(args[0])
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
50
704d23022f09 Start of dialogue tree / NPC state machine support.
Simon Cross <hodgestar@gmail.com>
parents:
diff changeset
51 if __name__ == '__main__':
195
445a28f4b38e Fix npc tester.
Simon Cross <hodgestar@gmail.com>
parents: 153
diff changeset
52 main()