35 lines
813 B
Python
35 lines
813 B
Python
from dataclasses import dataclass
|
|
|
|
from parse.map_header import tokenize_line
|
|
|
|
def tokenize_map_const(line):
|
|
return tokenize_line(line)
|
|
|
|
def tokenize_lines(lines):
|
|
for line in lines:
|
|
if "map_const" in line:
|
|
yield tokenize_map_const(line)
|
|
|
|
@dataclass
|
|
class MapConstant:
|
|
width: int
|
|
height: int
|
|
|
|
def flatten(tokens):
|
|
for macro, args in tokens:
|
|
if macro == 'map_const':
|
|
name, width, height = args
|
|
yield name, MapConstant(
|
|
int(width),
|
|
int(height)
|
|
)
|
|
|
|
def parse(prefix):
|
|
path = prefix / "constants/map_constants.asm"
|
|
with open(path) as f:
|
|
tokens = tokenize_lines(f.read().split("\n"))
|
|
l = list(flatten(tokens))
|
|
d = dict(l)
|
|
assert len(l) == len(d)
|
|
return d
|