pokemon/tools/parse/move/moves.py
2023-08-02 01:50:18 +00:00

34 lines
806 B
Python

from dataclasses import dataclass
from functools import partial
from parse.generic import tokenize
from parse.generic import number
tokenize_lines = partial(tokenize.lines, prefix='move ')
@dataclass
class Move:
animation_name: str
effect: str
power: int
type: str
accuracy: int
pp: int
def flatten(tokens):
for t in tokens:
assert t[0] == 'move', t
_, (animation_name, effect, power, type, accuracy, pp) = t
yield Move(
animation_name,
effect,
number.parse(power),
type,
number.parse(accuracy),
number.parse(pp)
)
def parse(prefix):
path = prefix / 'data/moves/moves.asm'
with open(path) as f:
return list(flatten(tokenize_lines(f.read().split('\n'))))