# HG changeset patch # User Simon Cross # Date 1302286305 -7200 # Node ID 9e6ff3eb63d6e343d983f7580545b3ff3705f08c # Parent 849e59e919afc59a6567ff2bacba29d7516851ef Enable testing of individual NPCs. diff -r 849e59e919af -r 9e6ff3eb63d6 scripts/npc-test --- a/scripts/npc-test Fri Apr 08 19:59:16 2011 +0200 +++ b/scripts/npc-test Fri Apr 08 20:11:45 2011 +0200 @@ -12,8 +12,17 @@ from skaapsteker.gamestate import GameState -def run(npc_name, game_json): +def run(npc_name, game_json, interact): game = GameState(game_json) + + print "Testing ..." + print "===========" + test_npc(game, npc_name) + print + + if not interact: + return + npc = getattr(game.world.npcs, npc_name) dsm = DSM(npc_name, game.world, npc.dsm, npc.state) @@ -41,28 +50,33 @@ print "--" +def test_npc(game, npc_name): + """Test one npc.""" + print "Checking", npc_name, "...", + npc = getattr(game.world.npcs, npc_name) + dsm = DSM(npc_name, game.world, npc.dsm, npc.state) + print " Loaded %s." % (npc.dsm) + + my_locals = { "world": dsm.world, "state": dsm.states, "npcs": dsm.world.npcs } + my_locals.update(DsmEvent().items) + for state_name, state in dsm.states.items(): + print " Testing triggers for state %s" % state_name + for trigger in state.triggers: + eval(trigger._matches, {}, my_locals.copy()) + eval(trigger._next_state, {}, my_locals.copy()) + print " Test on_entry and on_exit for state %s" % state_name + state.enter(my_locals) + state.leave(my_locals) + print "ok" + + def test_all(game_json): game = GameState(game_json) print "Testing NPCs" print "============" for npc_name in game.world.npcs: - print "Checking", npc_name, "...", - npc = getattr(game.world.npcs, npc_name) - dsm = DSM(npc_name, game.world, npc.dsm, npc.state) - print " Loaded %s." % (npc.dsm) - - my_locals = { "world": dsm.world, "state": dsm.states, "npcs": dsm.world.npcs } - my_locals.update(DsmEvent().items) - for state_name, state in dsm.states.items(): - print " Testing triggers for state %s" % state_name - for trigger in state.triggers: - eval(trigger._matches, {}, my_locals.copy()) - eval(trigger._next_state, {}, my_locals.copy()) - print " Test on_entry and on_exit for state %s" % state_name - state.enter(my_locals) - state.leave(my_locals) - print "ok" + test_npc(game, npc_name) print print "Testing Sprites" @@ -78,6 +92,8 @@ parser = optparse.OptionParser(usage="%prog [options] ") parser.add_option("--all", action="store_true", default=False, dest="test_all", help="test all NPCs in game") + parser.add_option("--interact", "-i", action="store_true", default=False, + dest="interact", help="enable interactive session with npc after testing") parser.add_option("--game", default="game.json", dest="game", help="game .json file to use") @@ -89,7 +105,7 @@ if len(args) != 1: parser.error("Must provide an npc json file") - run(args[0], opts.game) + run(args[0], opts.game, opts.interact) if __name__ == '__main__': main()