Mercurial > nagslang
comparison tools/area_editor.py @ 55:26d7bb8c09c8
Only save levels if the loops are closed
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 01 Sep 2013 18:50:19 +0200 |
parents | 9c4681f35866 |
children | 1261c0731385 |
comparison
equal
deleted
inserted
replaced
54:2c1b85b6f457 | 55:26d7bb8c09c8 |
---|---|
87 self.point_to_pygame(endpoint)) | 87 self.point_to_pygame(endpoint)) |
88 surface_area = pygame.rect.Rect(topleft, SCREEN) | 88 surface_area = pygame.rect.Rect(topleft, SCREEN) |
89 surface.blit(self._surface, (0, 0), surface_area) | 89 surface.blit(self._surface, (0, 0), surface_area) |
90 | 90 |
91 def save(self): | 91 def save(self): |
92 closed = True | |
93 for poly in self.polygons.values(): | |
94 if len(poly) == 0: | |
95 # We ignore empty polygons | |
96 continue | |
97 elif len(poly) == 1: | |
98 closed = False | |
99 print "\033[31mError: polygon too small\033[0m" | |
100 elif poly[-1] != poly[0]: | |
101 closed = False | |
102 print "\033[31mError: polygon not closed\033[0m" | |
103 if not closed: | |
104 print 'Not saving the level' | |
105 return | |
92 levelfile = resources.get_resource_path(self.name) | 106 levelfile = resources.get_resource_path(self.name) |
93 with file(levelfile, 'w') as f: | 107 with file(levelfile, 'w') as f: |
94 f.write('X-Size: %s\n' % self.x) | 108 f.write('X-Size: %s\n' % self.x) |
95 f.write('Y-Size: %s\n' % self.y) | 109 f.write('Y-Size: %s\n' % self.y) |
96 f.write('Base tile: %s\n' % self.basetile) | 110 f.write('Base tile: %s\n' % self.basetile) |
97 for i, poly in self.polygons.items(): | 111 for i, poly in self.polygons.items(): |
112 if len(poly) == 0: | |
113 continue | |
98 f.write('Polygon %d : %d\n' % (i, len(poly))) | 114 f.write('Polygon %d : %d\n' % (i, len(poly))) |
99 for point in poly: | 115 for point in poly: |
100 f.write('Point: %d %d\n' % point) | 116 f.write('Point: %d %d\n' % point) |
117 print 'level %s saved' % self.name | |
101 | 118 |
102 | 119 |
103 class Editor(object): | 120 class Editor(object): |
104 | 121 |
105 def __init__(self, level, surface): | 122 def __init__(self, level, surface): |