view scripts/npc-test @ 223:f675abd90529

player needs a world argument
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Thu, 07 Apr 2011 01:24:54 +0200
parents 2cbeeef5867c
children 13b912f40a10
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_name):
    game = GameState("game.json")
    npc = getattr(game.world.npcs, npc_name)
    dsm = DSM(npc_name, game.world, npc.dsm, npc.state)

    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 name>")
    opts, args = p.parse_args()
    if len(args) != 1:
        p.error("Must provide an npc json file")
    run(args[0])

if __name__ == '__main__':
    main()