comparison scripts/pytouhou @ 597:244c99c568c8

Don’t hardcode the available games and interfaces, and relocation them.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 25 Oct 2014 18:52:16 +0200
parents ab131d04987d
children e9300aae4b24
comparison
equal deleted inserted replaced
596:ab131d04987d 597:244c99c568c8
22 22
23 defaults = {'data': default_data, 23 defaults = {'data': default_data,
24 'path': '.', 24 'path': '.',
25 'rank': 0, 25 'rank': 0,
26 'character': 0, 26 'character': 0,
27 'game': 'EoSD', 27 'game': 'eosd',
28 'interface': 'EoSD', 28 'interface': 'eosd',
29 'port': 0, 29 'port': 0,
30 'backend': ['opengl', 'sdl'], 30 'backend': ['opengl', 'sdl'],
31 'gl-flavor': 'compatibility', 31 'gl-flavor': 'compatibility',
32 'gl-version': 2.1, 32 'gl-version': 2.1,
33 'double-buffer': None, 33 'double-buffer': None,
55 except ImportError: 55 except ImportError:
56 logger.error('GTK+ unavailable, disabling the GUI menu.') 56 logger.error('GTK+ unavailable, disabling the GUI menu.')
57 else: 57 else:
58 menu(options, args) 58 menu(options, args)
59 59
60 if args.game == 'EoSD': 60 import sys
61 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game 61 from importlib import import_module
62 62
63 if args.interface == 'EoSD': 63 def load_module(type_, name, items=None):
64 from pytouhou.interfaces.eosd import EoSDInterface as Interface 64 try:
65 elif args.interface == 'Sample': 65 module = import_module('pytouhou.games.%s.%s' % (name, type_))
66 from pytouhou.interfaces.sample import SampleInterface as Interface 66 except ImportError:
67 67 logger.critical('Module “%s” doesn’t contain %s data, aborting.', name, type_)
68 sys.exit(1)
69 if items is None:
70 return module
71 return (getattr(module, item) for item in items)
72
73 Game, Common = load_module('game', args.game, ['Game', 'Common'])
74 Interface = load_module('interface', args.interface).Interface
68 75
69 from pytouhou.lib.sdl import SDL, show_simple_message_box 76 from pytouhou.lib.sdl import SDL, show_simple_message_box
70 from pytouhou.ui.window import Window 77 from pytouhou.ui.window import Window
71 from pytouhou.resource.loader import Loader 78 from pytouhou.resource.loader import Loader
72 from pytouhou.ui.gamerunner import GameRunner 79 from pytouhou.ui.gamerunner import GameRunner
75 from pytouhou.utils.random import Random 82 from pytouhou.utils.random import Random
76 from pytouhou.formats.hint import Hint 83 from pytouhou.formats.hint import Hint
77 from pytouhou.network import Network 84 from pytouhou.network import Network
78 85
79 86
80 from importlib import import_module
81 for backend_name in args.backend: 87 for backend_name in args.backend:
82 if backend_name == 'opengl': 88 if backend_name == 'opengl':
83 options = { 89 options = {
84 'flavor': args.gl_flavor, 90 'flavor': args.gl_flavor,
85 'version': args.gl_version, 91 'version': args.gl_version,
144 150
145 try: 151 try:
146 resource_loader.scan_archives(data) 152 resource_loader.scan_archives(data)
147 except IOError: 153 except IOError:
148 show_simple_message_box(u'Some data files were not found, did you forget the -p option?') 154 show_simple_message_box(u'Some data files were not found, did you forget the -p option?')
149 import sys
150 sys.exit(1) 155 sys.exit(1)
151 156
152 if stage_num is None: 157 if stage_num is None:
153 story = True 158 story = True
154 stage_num = 1 159 stage_num = 1