Reorganise level jsohn structure. Drop 'pos' attribute in favour of the array positio...
[koperkapel.git] / koperkapel / loaders / levelloader.py
index 4fa6ecd9331360220ea1460f8e7bbd3f3d9af3f1..124161f37d12fe93dd9681471bf140cced3a3ef5 100644 (file)
@@ -15,14 +15,22 @@ class LevelLoader(ResourceLoader):
         f = open(level_path, 'r')
         level_data = json.load(f)
         f.close()
+        self._height = len(level_data['tiles'])
+        self._width = len(level_data['tiles'][0])
         self._tiles = level_data['tiles']
+        # Consistency check, so we can assume things are correct
+        # in the level renderer
+        for row, row_data in enumerate(self._tiles):
+            if len(row_data) != self._width:
+                raise RuntimeError("Incorrect len for row %d" % row)
         self._load_tile_images()
         return level_data
 
     def _load_tile_images(self):
         """Load all the tile images"""
-        for tile in self._tiles:
-            tile['image'] = images.load(tile['base'])
+        for row_data in self._tiles:
+            for tile in row_data:
+                tile['image'] = images.load(tile['base'])
 
 
 levels = LevelLoader('levels')