from dataclasses import dataclass from functools import partial from parse import number from parse.generic import macro_line @dataclass class TilesetHeader: name: str counters: list[str] grass_tile: str animations: str def blockset(self): # renamed from "block" to better disambiguate from Map blocks return f"{self.name}_Block" def gfx(self): return f"{self.name}_GFX" def coll(self): return f"{self.name}_Coll" tokenize_lines = partial(macro_line.tokenize_lines, prefix="tileset") def flatten(tokens): for ts in tokens: assert ts[0] == 'tileset' _, (name, c0, c1, c2, grass_tile, animations) = ts yield TilesetHeader( name=name, counters=tuple(map(number.parse, [c0, c1, c2])), grass_tile=number.parse(grass_tile), animations=animations ) def parse(prefix): path = prefix / 'data/tilesets/tileset_headers.asm' with open(path) as f: tokens = tokenize_lines(f.read().split('\n')) return list(flatten(tokens))