Mercurial > boomslang
comparison pyntnclick/main.py @ 556:a4f28da12720 pyntnclick
Move option_parser onto GameDescription so it can be overridden by sub-classes if they lik.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Sat, 11 Feb 2012 14:12:11 +0200 |
parents | 99a1420097df |
children | 28f03563f4db |
comparison
equal
deleted
inserted
replaced
555:c0474fe18b96 | 556:a4f28da12720 |
---|---|
21 from pyntnclick.endscreen import EndScreen | 21 from pyntnclick.endscreen import EndScreen |
22 from pyntnclick.constants import ( | 22 from pyntnclick.constants import ( |
23 SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG) | 23 SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG) |
24 from pyntnclick.sound import no_sound, disable_sound | 24 from pyntnclick.sound import no_sound, disable_sound |
25 from pyntnclick import state, data | 25 from pyntnclick import state, data |
26 | |
27 | |
28 def parse_args(args): | |
29 parser = OptionParser() | |
30 parser.add_option("--no-sound", action="store_false", default=True, | |
31 dest="sound", help="disable sound") | |
32 if DEBUG: | |
33 parser.add_option("--scene", type="str", default=None, | |
34 dest="scene", help="initial scene") | |
35 parser.add_option("--no-rects", action="store_false", default=True, | |
36 dest="rects", help="disable debugging rects") | |
37 opts, _ = parser.parse_args(args or []) | |
38 return opts | |
39 | 26 |
40 | 27 |
41 class MainShell(Shell): | 28 class MainShell(Shell): |
42 def __init__(self, display, initial_state): | 29 def __init__(self, display, initial_state): |
43 Shell.__init__(self, display) | 30 Shell.__init__(self, display) |
78 initial_state.load_scenes(scene) | 65 initial_state.load_scenes(scene) |
79 initial_state.set_current_scene(self._initial_scene) | 66 initial_state.set_current_scene(self._initial_scene) |
80 initial_state.set_do_enter_leave() | 67 initial_state.set_do_enter_leave() |
81 return initial_state | 68 return initial_state |
82 | 69 |
70 def option_parser(self): | |
71 parser = OptionParser() | |
72 parser.add_option("--no-sound", action="store_false", default=True, | |
73 dest="sound", help="disable sound") | |
74 if DEBUG: | |
75 parser.add_option("--scene", type="str", default=None, | |
76 dest="scene", help="initial scene") | |
77 parser.add_option("--no-rects", action="store_false", default=True, | |
78 dest="rects", help="disable debugging rects") | |
79 return parser | |
80 | |
83 def main(self): | 81 def main(self): |
84 opts = parse_args(sys.argv) | 82 parser = self.option_parser() |
83 opts, _ = parser.parse_args(sys.argv) | |
85 pygame.display.init() | 84 pygame.display.init() |
86 pygame.font.init() | 85 pygame.font.init() |
87 if opts.sound: | 86 if opts.sound: |
88 try: | 87 try: |
89 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) | 88 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) |