move: add constants and moves parsers
This commit is contained in:
parent
a921a44b66
commit
f4aad91349
17
tools/parse/move/constants.py
Normal file
17
tools/parse/move/constants.py
Normal file
@ -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'))))
|
33
tools/parse/move/moves.py
Normal file
33
tools/parse/move/moves.py
Normal file
@ -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'))))
|
Loading…
x
Reference in New Issue
Block a user