from dataclasses import dataclass from parse.map_header import tokenize_line from parse import number def tokenize_lines(lines): for line in lines: if 'tileset ' in line: yield tokenize_line(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" def flatten(tokens): for ts in tokens: if ts[0] != 'tileset': continue _, (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))