Ignore:
Timestamp:
09/01/13 19:41:49 (8 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Message:

Move save() to Level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r71 r72  
    2020sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    2121
    22 from nagslang.resources import resources
    2322from nagslang.constants import SCREEN, FPS
    2423from nagslang.level import Level, POLY_COLORS
     
    9392        surface_area = pygame.rect.Rect(topleft, SCREEN)
    9493        surface.blit(self._surface, (0, 0), surface_area)
    95 
    96     def save(self):
    97         closed = True
    98         for poly in self.polygons.values():
    99             if len(poly) == 0:
    100                 # We ignore empty polygons
    101                 continue
    102             elif len(poly) == 1:
    103                 closed = False
    104                 print "\033[31mError: polygon too small\033[0m"
    105             elif poly[-1] != poly[0]:
    106                 closed = False
    107                 print "\033[31mError: polygon not closed\033[0m"
    108         if not closed:
    109             print 'Not saving the level'
    110             return
    111         with resources.get_file(self.name, mode='w') as f:
    112             f.write('X-Size: %s\n' % self.x)
    113             f.write('Y-Size: %s\n' % self.y)
    114             f.write('Base tile: %s\n' % self.basetile)
    115             for i, poly in self.polygons.items():
    116                 if len(poly) == 0:
    117                     continue
    118                 f.write('Polygon %d : %d\n' % (i, len(poly)))
    119                 for point in poly:
    120                     f.write('Point: %d %d\n' % point)
    121         print 'level %s saved' % self.name
    12294
    12395
Note: See TracChangeset for help on using the changeset viewer.