Spikes, better gameHandler, map width and height computed automatically & big peanut hard map
This commit is contained in:
+13
-9
@@ -27,13 +27,13 @@ class MapReader:
|
||||
|
||||
with open(map_path, 'rb') as f:
|
||||
config = tomllib.load(f)
|
||||
|
||||
layout = config.get('layout', '')
|
||||
|
||||
map_data = {
|
||||
'name': map_name,
|
||||
'width': config.get('width', 0),
|
||||
'height': config.get('height', 0),
|
||||
'difficulty': config.get('difficulty', 0.0),
|
||||
'layout': self._parse_layout(config.get('layout', ''))
|
||||
'layout': self._parse_layout(layout)
|
||||
}
|
||||
|
||||
if config.get('min_moves') is not None:
|
||||
@@ -48,16 +48,20 @@ class MapReader:
|
||||
|
||||
def _parse_layout(self, mapString):
|
||||
# Takes the blocks and translates their characters into the corresponding block objects.
|
||||
block_characters_mapping = self._get_block_characters_mapping()
|
||||
# Makes sure tthe width is consistent across all rows by padding with None if necessary.
|
||||
block_mapping = self._get_block_characters_mapping()
|
||||
layout = []
|
||||
for line in mapString.strip().splitlines():
|
||||
for line in mapString.splitlines():
|
||||
row = []
|
||||
for char in line:
|
||||
block_class = block_characters_mapping.get(char)
|
||||
block_class = block_mapping.get(char)
|
||||
if block_class:
|
||||
row.append(block_class())
|
||||
else:
|
||||
row.append(None)
|
||||
row.append(None) # Unknown character, treat as empty space
|
||||
layout.append(row)
|
||||
return layout
|
||||
|
||||
max_width = max(len(row) for row in layout)
|
||||
for row in layout:
|
||||
while len(row) < max_width:
|
||||
row.append(None) # Pad with None to ensure consistent width
|
||||
return layout
|
||||
Reference in New Issue
Block a user