diff --git a/tools/parse/move/constants.py b/tools/parse/move/constants.py new file mode 100644 index 0000000..cd64b2b --- /dev/null +++ b/tools/parse/move/constants.py @@ -0,0 +1,17 @@ +from functools import partial +from parse.generic import macro_line + +tokenize_lines = partial(macro_line.tokenize_lines, prefix='const ') + +def flatten(tokens): + index = 0 + for t in tokens: + assert t[0] == 'const', t + _, (name,) = t + yield name, index + index += 1 + +def parse(prefix): + path = prefix / 'constants/move_constants.asm' + with open(path) as f: + return dict(flatten(tokenize_lines(f.read().split('\n')))) diff --git a/tools/parse/move/moves.py b/tools/parse/move/moves.py new file mode 100644 index 0000000..3701773 --- /dev/null +++ b/tools/parse/move/moves.py @@ -0,0 +1,33 @@ +from dataclasses import dataclass +from functools import partial +from parse import number +from parse.generic import macro_line + +tokenize_lines = partial(macro_line.tokenize_lines, prefix='move ') + +@dataclass +class Move: + name: str + effect: str + power: int + type: str + accuracy: int + pp: int + +def flatten(tokens): + for t in tokens: + assert t[0] == 'move', t + _, (name, effect, power, type, accuracy, pp) = t + return Move( + name, + effect, + number(power), + type, + number(accuracy), + number(pp) + ) + +def parse(prefix): + path = prefix / 'data/moves/moves.asm' + with open(path) as f: + return dict(flatten(tokenize_lines(f.read().split('\n'))))