Mercurial > skaapsteker
comparison scripts/npc-test @ 153:704d23022f09
Start of dialogue tree / NPC state machine support.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Tue, 05 Apr 2011 22:18:26 +0200 |
parents | |
children | 445a28f4b38e |
comparison
equal
deleted
inserted
replaced
152:60138b935bc0 | 153:704d23022f09 |
---|---|
1 #!/usr/bin/env python | |
2 "Skaapsteker npc tester" | |
3 | |
4 import os.path | |
5 import sys | |
6 import optparse | |
7 from pprint import pprint | |
8 | |
9 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | |
10 | |
11 from skaapsteker.dialogue import DSM, DsmEvent, DummyWorld | |
12 | |
13 | |
14 def run(npc_file): | |
15 world = DummyWorld() | |
16 dsm = DSM(npc_file, world) | |
17 | |
18 print "States:" | |
19 print "-------" | |
20 pprint(dsm.states.keys()) | |
21 print | |
22 | |
23 while True: | |
24 state = dsm.get_state() | |
25 print "%s:" % dsm.state, state.text | |
26 print "--" | |
27 for i, choice in state.choices: | |
28 print "%d: %s" % (i, choice) | |
29 print "L: Leave" | |
30 print "--" | |
31 | |
32 key = raw_input("Choice? ") | |
33 key = key.strip().upper() | |
34 if key == "L": | |
35 break | |
36 elif key.isdigit(): | |
37 dsm.choice(int(key)) | |
38 | |
39 print "--" | |
40 | |
41 | |
42 def main(): | |
43 p = optparse.OptionParser(usage="%prog [options] <npc json state file>") | |
44 opts, args = p.parse_args() | |
45 if len(args) != 1: | |
46 p.error("Must provide an npc json file") | |
47 run(args[0]) | |
48 | |
49 if __name__ == '__main__': | |
50 main() |