Mercurial > boomslang
comparison pyntnclick/main.py @ 594:a9e9a7fbdbcf pyntnclick
Make debug a env variable
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sat, 11 Feb 2012 18:04:23 +0200 |
parents | a77dd4619176 |
children | 5496dcd16a84 |
comparison
equal
deleted
inserted
replaced
593:1eb1537173ef | 594:a9e9a7fbdbcf |
---|---|
17 from albow.shell import Shell | 17 from albow.shell import Shell |
18 | 18 |
19 from pyntnclick.menu import MenuScreen | 19 from pyntnclick.menu import MenuScreen |
20 from pyntnclick.gamescreen import GameScreen | 20 from pyntnclick.gamescreen import GameScreen |
21 from pyntnclick.endscreen import EndScreen | 21 from pyntnclick.endscreen import EndScreen |
22 from pyntnclick.constants import GameConstants | 22 from pyntnclick.constants import GameConstants, DEBUG_ENVVAR |
23 from pyntnclick.resources import Resources | 23 from pyntnclick.resources import Resources |
24 from pyntnclick.sound import Sound | 24 from pyntnclick.sound import Sound |
25 from pyntnclick import state | 25 from pyntnclick import state |
26 | 26 |
27 from pyntnclick.tools.rect_drawer import RectApp, make_rect_display | 27 from pyntnclick.tools.rect_drawer import RectApp, make_rect_display |
64 self._resource_module = self.RESOURCE_MODULE | 64 self._resource_module = self.RESOURCE_MODULE |
65 self._debug_rects = False | 65 self._debug_rects = False |
66 self.resource = Resources(self._resource_module) | 66 self.resource = Resources(self._resource_module) |
67 self.sound = Sound(self.resource) | 67 self.sound = Sound(self.resource) |
68 self.constants = self.game_constants() | 68 self.constants = self.game_constants() |
69 self.debug_options = [] | |
69 | 70 |
70 def initial_state(self): | 71 def initial_state(self): |
71 """Create a copy of the initial game state.""" | 72 """Create a copy of the initial game state.""" |
72 initial_state = state.GameState(self) | 73 initial_state = state.GameState(self) |
73 initial_state.set_debug_rects(self._debug_rects) | 74 initial_state.set_debug_rects(self._debug_rects) |
82 | 83 |
83 def option_parser(self): | 84 def option_parser(self): |
84 parser = OptionParser() | 85 parser = OptionParser() |
85 parser.add_option("--no-sound", action="store_false", default=True, | 86 parser.add_option("--no-sound", action="store_false", default=True, |
86 dest="sound", help="disable sound") | 87 dest="sound", help="disable sound") |
88 # We flag these, so we can warn the user that these require debug mode | |
89 self.debug_options = ['--scene', '--no-rects', '--rect-drawer', | |
90 '--list-scenes', '--details'] | |
87 if self.constants.debug: | 91 if self.constants.debug: |
88 parser.add_option("--scene", type="str", default=None, | 92 parser.add_option("--scene", type="str", default=None, |
89 dest="scene", help="initial scene") | 93 dest="scene", help="initial scene") |
90 parser.add_option("--no-rects", action="store_false", default=True, | 94 parser.add_option("--no-rects", action="store_false", default=True, |
91 dest="rects", help="disable debugging rects") | 95 dest="rects", help="disable debugging rects") |
98 " that can be used with --scene and exit.") | 102 " that can be used with --scene and exit.") |
99 parser.add_option("--detail", type="str", default=None, | 103 parser.add_option("--detail", type="str", default=None, |
100 dest="detail", help="Detailed view for rect_drawer") | 104 dest="detail", help="Detailed view for rect_drawer") |
101 return parser | 105 return parser |
102 | 106 |
107 def warn_debug(self, option): | |
108 """Warn the user that he needs debug mode""" | |
109 print '%s is only valid in debug mode' % option | |
110 print 'set %s to enable debug mode' % DEBUG_ENVVAR | |
111 print | |
112 | |
103 def main(self): | 113 def main(self): |
104 parser = self.option_parser() | 114 parser = self.option_parser() |
115 # This is a bit hack'ish, but works | |
116 if not self.constants.debug: | |
117 for option in self.debug_options: | |
118 if option in sys.argv: | |
119 self.warn_debug(option) | |
105 opts, _ = parser.parse_args(sys.argv) | 120 opts, _ = parser.parse_args(sys.argv) |
106 pygame.display.init() | 121 pygame.display.init() |
107 pygame.font.init() | 122 pygame.font.init() |
108 if opts.sound: | 123 if opts.sound: |
109 self.sound.enable_sound(self.constants) | 124 self.sound.enable_sound(self.constants) |