Mercurial > skaapsteker
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/npc-test Tue Apr 05 22:18:26 2011 +0200 @@ -0,0 +1,50 @@ +#!/usr/bin/env python +"Skaapsteker npc tester" + +import os.path +import sys +import optparse +from pprint import pprint + +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + +from skaapsteker.dialogue import DSM, DsmEvent, DummyWorld + + +def run(npc_file): + world = DummyWorld() + dsm = DSM(npc_file, world) + + print "States:" + print "-------" + pprint(dsm.states.keys()) + print + + while True: + state = dsm.get_state() + print "%s:" % dsm.state, state.text + print "--" + for i, choice in state.choices: + print "%d: %s" % (i, choice) + print "L: Leave" + print "--" + + key = raw_input("Choice? ") + key = key.strip().upper() + if key == "L": + break + elif key.isdigit(): + dsm.choice(int(key)) + + print "--" + + +def main(): + p = optparse.OptionParser(usage="%prog [options] <npc json state file>") + opts, args = p.parse_args() + if len(args) != 1: + p.error("Must provide an npc json file") + run(args[0]) + +if __name__ == '__main__': + main() \ No newline at end of file