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
  • 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
Note: See TracChangeset for help on using the changeset viewer.