Mercurial > boomslang
comparison pyntnclick/main.py @ 589:ebc48b397fd5 pyntnclick
Turn rect_drawer into a command line option
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sat, 11 Feb 2012 17:07:52 +0200 |
parents | f20d211d2c91 |
children | a77dd4619176 |
comparison
equal
deleted
inserted
replaced
588:0571deb177e9 | 589:ebc48b397fd5 |
---|---|
21 from pyntnclick.endscreen import EndScreen | 21 from pyntnclick.endscreen import EndScreen |
22 from pyntnclick.constants import GameConstants | 22 from pyntnclick.constants import GameConstants |
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 | |
27 from pyntnclick.tools.rect_drawer import RectApp, make_rect_display | |
28 from pyntnclick.tools.utils import list_scenes | |
26 | 29 |
27 | 30 |
28 class MainShell(Shell): | 31 class MainShell(Shell): |
29 def __init__(self, display, game_description): | 32 def __init__(self, display, game_description): |
30 Shell.__init__(self, display) | 33 Shell.__init__(self, display) |
84 if self.constants.debug: | 87 if self.constants.debug: |
85 parser.add_option("--scene", type="str", default=None, | 88 parser.add_option("--scene", type="str", default=None, |
86 dest="scene", help="initial scene") | 89 dest="scene", help="initial scene") |
87 parser.add_option("--no-rects", action="store_false", default=True, | 90 parser.add_option("--no-rects", action="store_false", default=True, |
88 dest="rects", help="disable debugging rects") | 91 dest="rects", help="disable debugging rects") |
92 parser.add_option("--rect-drawer", action="store_true", | |
93 default=False, dest="rect_drawer", | |
94 help="Launch the rect drawing helper tool. Specify the" | |
95 " scene with --scene") | |
96 parser.add_option("--list-scenes", action="store_true", | |
97 default=False, dest='list_scenes', help="List all scenes" | |
98 " that can be used with --scene and exit.") | |
99 parser.add_option("--detail", type="str", default=None, | |
100 dest="detail", help="Detailed view for rect_drawer") | |
89 return parser | 101 return parser |
90 | 102 |
91 def main(self): | 103 def main(self): |
92 parser = self.option_parser() | 104 parser = self.option_parser() |
93 opts, _ = parser.parse_args(sys.argv) | 105 opts, _ = parser.parse_args(sys.argv) |
100 if self.constants.debug: | 112 if self.constants.debug: |
101 if opts.scene is not None: | 113 if opts.scene is not None: |
102 # debug the specified scene | 114 # debug the specified scene |
103 self._initial_scene = opts.scene | 115 self._initial_scene = opts.scene |
104 self._debug_rects = opts.rects | 116 self._debug_rects = opts.rects |
105 display = pygame.display.set_mode(self.constants.screen, | 117 if opts.list_scenes: |
106 SWSURFACE) | 118 # FIXME: Horrible hack to avoid image loading issues for |
107 pygame.display.set_icon(self.resource.get_image( | 119 # now |
108 'suspended_sentence24x24.png', basedir='icons')) | 120 display = pygame.display.set_mode(self.constants.screen, |
109 pygame.display.set_caption("Suspended Sentence") | 121 SWSURFACE) |
110 shell = MainShell(display, self) | 122 list_scenes(self.initial_state) |
123 sys.exit(0) | |
124 if opts.rect_drawer: | |
125 if opts.scene is None: | |
126 print 'Need to supply a scene to use the rect drawer' | |
127 sys.exit(1) | |
128 display = make_rect_display() | |
129 try: | |
130 shell = RectApp(display, self.initial_state, opts.scene, | |
131 opts.detail) | |
132 except KeyError: | |
133 print 'Invalid scene: %s' % opts.scene | |
134 sys.exit(1) | |
135 else: | |
136 display = pygame.display.set_mode(self.constants.screen, | |
137 SWSURFACE) | |
138 pygame.display.set_icon(self.resource.get_image( | |
139 'suspended_sentence24x24.png', basedir='icons')) | |
140 pygame.display.set_caption("Suspended Sentence") | |
141 | |
142 shell = MainShell(display, self) | |
111 try: | 143 try: |
112 shell.run() | 144 shell.run() |
113 except KeyboardInterrupt: | 145 except KeyboardInterrupt: |
114 pass | 146 pass |