Changeset 139:d1f543ff0805
- Timestamp:
- Sep 2, 2013, 4:27:58 PM (7 years ago)
- Branch:
- default
- rebase_source:
- fb79546c13df1c3516671b1eec5fdbacf16ac799
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
data/levels/level1
r77 r139 1 X-Size: 1200 2 Y-Size: 900 3 Base tile: tiles/floor.png 4 Polygon 1 : 15 5 Point: 60 780 6 Point: 130 850 7 Point: 1150 850 8 Point: 1010 710 9 Point: 1010 190 10 Point: 880 60 11 Point: 700 60 12 Point: 560 200 13 Point: 560 650 14 Point: 410 650 15 Point: 410 70 16 Point: 60 70 17 Point: 260 270 18 Point: 60 470 19 Point: 60 780 1 base_tile: tiles/floor.png 2 polygons: 3 1: 4 - [60, 780] 5 - [130, 850] 6 - [1150, 850] 7 - [1010, 710] 8 - [1010, 190] 9 - [880, 60] 10 - [700, 60] 11 - [560, 200] 12 - [560, 650] 13 - [410, 650] 14 - [410, 70] 15 - [60, 70] 16 - [260, 270] 17 - [60, 470] 18 - [60, 780] 19 size: [1200, 900] -
nagslang/level.py
r122 r139 3 3 4 4 from nagslang.resources import resources 5 from nagslang.yamlish import load, dump 5 6 6 7 POLY_COLORS = { … … 28 29 29 30 def load(self): 30 31 def add_polygon(polygon, index, num_points):32 self.polygons[index] = polygon33 if len(polygon) != num_points:34 print 'Error - incorrect polygon size'35 print 'Expected: %d, got %d' % (num_points, len(polygon))36 37 inpoly = False38 polygon = []39 index = 040 num_points = 041 31 with resources.get_file('levels', self.name) as f: 42 for line in f: 43 if inpoly: 44 if not line.startswith('Point:'): 45 add_polygon(polygon, index, num_points) 46 polygon = [] 47 inpoly = False 48 index = 0 49 else: 50 point = line.split(':', 1)[1] 51 x, y = [int(i) for i in point.split()] 52 polygon.append((x, y)) 53 if line.startswith('X-Size:'): 54 self.x = int(line.split(':', 1)[1]) 55 elif line.startswith('Y-Size:'): 56 self.y = int(line.split(':', 1)[1]) 57 elif line.startswith('Base tile:'): 58 self.basetile = line.split(':', 1)[1].strip() 59 elif line.startswith('Polygon'): 60 rest = line.split(' ', 1)[1] 61 index, num_points = [int(x) for x in rest.split(':', 1)] 62 inpoly = True 63 if index: 64 add_polygon(polygon, index, num_points) 32 data = load(f) 33 self.x, self.y = data['size'] 34 self.base_tile = data['base_tile'] 35 for i, points in data['polygons'].iteritems(): 36 self.polygons[i] = [] 37 for point in points: 38 self.polygons[i].append(tuple(point)) 65 39 66 40 def all_closed(self): … … 85 59 return False 86 60 with resources.get_file('levels', self.name, mode='w') as f: 87 f.write('X-Size: %s\n' % self.x) 88 f.write('Y-Size: %s\n' % self.y) 89 f.write('Base tile: %s\n' % self.basetile) 90 for i, poly in self.polygons.items(): 91 if len(poly) == 0: 92 continue 93 f.write('Polygon %d : %d\n' % (i, len(poly))) 94 for point in poly: 95 f.write('Point: %d %d\n' % point) 61 dump({ 62 'size': [self.x, self.y], 63 'base_tile': self.basetile, 64 'polygons': self.polygons, 65 }, f) 96 66 return True 97 67
Note: See TracChangeset
for help on using the changeset viewer.