comparison eclviewer.py @ 187:46793ccfedca

Implement replays.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 26 Oct 2011 17:54:03 -0700
parents 84da28ae7ee4
children 008f90ebfdc0
comparison
equal deleted inserted replaced
186:84da28ae7ee4 187:46793ccfedca
22 from pytouhou.resource.loader import Loader 22 from pytouhou.resource.loader import Loader
23 from pytouhou.game.background import Background 23 from pytouhou.game.background import Background
24 from pytouhou.opengl.gamerunner import GameRunner 24 from pytouhou.opengl.gamerunner import GameRunner
25 from pytouhou.game.games import EoSDGame 25 from pytouhou.game.games import EoSDGame
26 from pytouhou.game.player import PlayerState 26 from pytouhou.game.player import PlayerState
27 from pytouhou.formats.t6rp import T6RP
27 28
28 29
29 def main(path, stage_num, rank, character): 30 def main(path, stage_num, rank, character, replay):
31 if replay:
32 with open(replay, 'rb') as file:
33 replay = T6RP.read(file)
34 rank = replay.rank
35 character = replay.character
36 if not replay.levels[stage_num-1]:
37 raise Exception
38
30 resource_loader = Loader() 39 resource_loader = Loader()
31 resource_loader.scan_archives(os.path.join(path, name) 40 resource_loader.scan_archives(os.path.join(path, name)
32 for name in ('CM.DAT', 'ST.DAT')) 41 for name in ('CM.DAT', 'ST.DAT'))
33 game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16) 42 game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16)
34 43
40 49
41 # Let's go! 50 # Let's go!
42 print(stage.name) 51 print(stage.name)
43 52
44 # Main loop 53 # Main loop
45 runner = GameRunner(resource_loader, game, background) 54 runner = GameRunner(resource_loader, game, background, replay=replay)
46 runner.start() 55 runner.start()
47 56
48 57
49 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.') 58 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')
50 59
51 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.') 60 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
52 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).') 61 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
53 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).') 62 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
54 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).') 63 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
64 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
55 65
56 args = parser.parse_args() 66 args = parser.parse_args()
57 67
58 main(args.path, args.stage, args.rank, args.character) 68 main(args.path, args.stage, args.rank, args.character, args.replay)