28 lines
909 B
Python
28 lines
909 B
Python
|
import json
|
||
|
|
||
|
from level.Level import Level
|
||
|
|
||
|
|
||
|
class LevelManager:
|
||
|
def __init__(self, level_dir: str):
|
||
|
self.level_dir = level_dir
|
||
|
self.levels = []
|
||
|
|
||
|
def load_from_config(self, config_file: str):
|
||
|
print('Loading levels from sprite sheet config file', config_file)
|
||
|
config = json.load(open(config_file))
|
||
|
|
||
|
for level_data in config:
|
||
|
csv = self.parse_csv(self.level_dir + '/' + level_data['file'])
|
||
|
level = Level(level_data['name'], level_data['theme'], level_data['abilities'], csv)
|
||
|
self.levels.append(level)
|
||
|
|
||
|
def parse_csv(self, file: str):
|
||
|
csv_array = []
|
||
|
with open(file) as csvfile:
|
||
|
for row in csvfile:
|
||
|
split_row = row.split(',')
|
||
|
filtered_row = list(map(lambda x: x.replace('\n', ''), split_row))
|
||
|
csv_array.append(filtered_row)
|
||
|
return csv_array
|