annotate eclviewer.py @ 186:84da28ae7ee4

Parse command line with argparse.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 26 Oct 2011 15:03:50 -0700
parents 959c8b312918
children 46793ccfedca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 #!/usr/bin/env python
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
2 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
3 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
4 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
5 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
6 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
7 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
8 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
9 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
10 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
13 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
14 ##
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
16 import argparse
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17 import os
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
19 import pyximport
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
20 pyximport.install()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
21
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
22 from pytouhou.resource.loader import Loader
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23 from pytouhou.game.background import Background
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
24 from pytouhou.opengl.gamerunner import GameRunner
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 119
diff changeset
25 from pytouhou.game.games import EoSDGame
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
26 from pytouhou.game.player import PlayerState
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
27
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28
162
959c8b312918 Add character choosing in CLI.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 137
diff changeset
29 def main(path, stage_num, rank, character):
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
30 resource_loader = Loader()
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
31 resource_loader.scan_archives(os.path.join(path, name)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
32 for name in ('CM.DAT', 'ST.DAT'))
162
959c8b312918 Add character choosing in CLI.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 137
diff changeset
33 game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16)
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
34
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
35 # Load stage data
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
36 stage = resource_loader.get_stage('stage%d.std' % stage_num)
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
38 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
39 background = Background(stage, background_anm_wrapper)
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
41 # Let's go!
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
42 print(stage.name)
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
44 # Main loop
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
45 runner = GameRunner(resource_loader, game, background)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
46 runner.start()
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
48
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
49 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
51 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
52 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
53 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
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).')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
55
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
56 args = parser.parse_args()
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
57
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
58 main(args.path, args.stage, args.rank, args.character)