comparison scripts/npc-test @ 227:13b912f40a10

Add --all option for testing NPCs and sprite creation.
author Simon Cross <hodgestar@gmail.com>
date Thu, 07 Apr 2011 01:35:26 +0200
parents 2cbeeef5867c
children a661b6621ec4
comparison
equal deleted inserted replaced
226:3286f1f32263 227:13b912f40a10
10 10
11 from skaapsteker.dialogue import DSM, DsmEvent 11 from skaapsteker.dialogue import DSM, DsmEvent
12 from skaapsteker.gamestate import GameState 12 from skaapsteker.gamestate import GameState
13 13
14 14
15 def run(npc_name): 15 def run(npc_name, game_json):
16 game = GameState("game.json") 16 game = GameState(game_json)
17 npc = getattr(game.world.npcs, npc_name) 17 npc = getattr(game.world.npcs, npc_name)
18 dsm = DSM(npc_name, game.world, npc.dsm, npc.state) 18 dsm = DSM(npc_name, game.world, npc.dsm, npc.state)
19 19
20 print "States:" 20 print "States:"
21 print "-------" 21 print "-------"
39 dsm.choice(int(key)) 39 dsm.choice(int(key))
40 40
41 print "--" 41 print "--"
42 42
43 43
44 def test_all(game_json):
45 game = GameState(game_json)
46
47 print "Testing NPCs"
48 print "============"
49 for npc_name in game.world.npcs:
50 print "Checking", npc_name, "...",
51 npc = getattr(game.world.npcs, npc_name)
52 dsm = DSM(npc_name, game.world, npc.dsm, npc.state)
53 print "ok"
54 print
55
56 print "Testing Sprites"
57 print "==============="
58 for level in game.world.levels:
59 print "Checking", level, "...",
60 game.create_sprites(level)
61 print "ok"
62 print
63
64
44 def main(): 65 def main():
45 p = optparse.OptionParser(usage="%prog [options] <npc name>") 66 parser = optparse.OptionParser(usage="%prog [options] <npc name>")
46 opts, args = p.parse_args() 67 parser.add_option("--all", action="store_true", default=False,
68 dest="test_all", help="test all NPCs in game")
69 parser.add_option("--game", default="game.json",
70 dest="game", help="game .json file to use")
71
72 opts, args = parser.parse_args()
73
74 if opts.test_all:
75 test_all(opts.game)
76 return
77
47 if len(args) != 1: 78 if len(args) != 1:
48 p.error("Must provide an npc json file") 79 p.error("Must provide an npc json file")
49 run(args[0]) 80 run(args[0], game)
50 81
51 if __name__ == '__main__': 82 if __name__ == '__main__':
52 main() 83 main()