42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from dataclasses import dataclass
|
|
from functools import partial
|
|
|
|
from parse.generic import number
|
|
from parse.generic import tokenize
|
|
|
|
@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(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))
|