Changeset 72:5db052531510


Ignore:
Timestamp:
Sep 1, 2013, 7:41:49 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Move save() to Level

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/level.py

    r54 r72  
    6363            add_polygon(polygon, index, num_points)
    6464
     65    def save(self):
     66        closed = True
     67        for poly in self.polygons.values():
     68            if len(poly) == 0:
     69                # We ignore empty polygons
     70                continue
     71            elif len(poly) == 1:
     72                closed = False
     73                print "\033[31mError: polygon too small\033[0m"
     74            elif poly[-1] != poly[0]:
     75                closed = False
     76                print "\033[31mError: polygon not closed\033[0m"
     77        if not closed:
     78            print 'Not saving the level'
     79            return
     80        with resources.get_file(self.name, mode='w') as f:
     81            f.write('X-Size: %s\n' % self.x)
     82            f.write('Y-Size: %s\n' % self.y)
     83            f.write('Base tile: %s\n' % self.basetile)
     84            for i, poly in self.polygons.items():
     85                if len(poly) == 0:
     86                    continue
     87                f.write('Polygon %d : %d\n' % (i, len(poly)))
     88                for point in poly:
     89                    f.write('Point: %d %d\n' % point)
     90        print 'level %s saved' % self.name
     91
    6592    def get_size(self):
    6693        return self.x, self.y
  • 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.