Changeset 55:26d7bb8c09c8


Ignore:
Timestamp:
Sep 1, 2013, 4:50:19 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Only save levels if the loops are closed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r51 r55  
    9090
    9191    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
    92106        levelfile = resources.get_resource_path(self.name)
    93107        with file(levelfile, 'w') as f:
     
    96110            f.write('Base tile: %s\n' % self.basetile)
    97111            for i, poly in self.polygons.items():
     112                if len(poly) == 0:
     113                    continue
    98114                f.write('Polygon %d : %d\n' % (i, len(poly)))
    99115                for point in poly:
    100116                    f.write('Point: %d %d\n' % point)
     117        print 'level %s saved' % self.name
    101118
    102119
Note: See TracChangeset for help on using the changeset viewer.