37 lines
995 B
Python
37 lines
995 B
Python
from dataclasses import dataclass
|
|
from functools import partial
|
|
from parse.generic import number
|
|
from parse.generic import tokenize
|
|
|
|
tokenize_lines = partial(tokenize.lines, prefix='overworld_sprite')
|
|
|
|
@dataclass
|
|
class Spritesheet:
|
|
name: str
|
|
sprite_count: int
|
|
|
|
def translate_tile_count(tile_count):
|
|
# this is the number of non-animation sprites in the spritesheet
|
|
# the animation sprite is always at tile_index * 2
|
|
# all animated sprites have 2 animation frames
|
|
return int(tile_count) // 4
|
|
|
|
def flatten(tokens):
|
|
for ts in tokens:
|
|
if ts[0] != 'overworld_sprite':
|
|
continue
|
|
_, (name, tile_count) = ts
|
|
|
|
sprite_count = translate_tile_count(tile_count)
|
|
|
|
yield Spritesheet(
|
|
name=name,
|
|
sprite_count=sprite_count,
|
|
)
|
|
|
|
def parse(prefix):
|
|
path = prefix / 'data/sprites/sprites.asm'
|
|
with open(path) as f:
|
|
tokens = tokenize_lines(f.read().split('\n'))
|
|
return list(flatten(tokens))
|