view scripts/npc-test @ 196:a4c4e2f34162

Remove DummyWorld since npc-test now uses the real world.
author Simon Cross <hodgestar@gmail.com>
date Wed, 06 Apr 2011 22:06:45 +0200
parents 445a28f4b38e
children 2cbeeef5867c
line wrap: on
line source

#!/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
from skaapsteker.gamestate import GameState


def run(npc_file):
    game = GameState("game.json")
    name = os.path.splitext(os.path.basename(npc_file))[0]
    dsm = DSM(name, game.world, npc_file)

    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()