generate: add moves

This commit is contained in:
Zack Buhman 2023-08-02 01:49:25 +00:00
parent 145b6b8936
commit ff19b3f38b
3 changed files with 10 additions and 6 deletions

View File

@ -9,8 +9,9 @@ def generate(base_path, target_path):
path = base_path / filename
if path != target_path:
continue
buf = func().getvalue()
with open(path, 'w') as f:
f.write(func().getvalue())
f.write(buf)
# sys.argv[1] is secretly used in parse
base_path = Path(sys.argv[2])

View File

@ -5,6 +5,7 @@ from generate import tilesets
from generate import collision_tile_ids
from generate import text
from generate import text_pointers
from generate.move import moves
files = [
(maps.generate_header, "maps.hpp"),
@ -21,4 +22,6 @@ files = [
(text.generate_source, "text.cpp"),
(text_pointers.generate_header, "text_pointers.hpp"),
(text_pointers.generate_source, "text_pointers.cpp"),
(moves.generate_header, "moves.hpp"),
(moves.generate_source, "moves.cpp"),
]

View File

@ -7,7 +7,7 @@ tokenize_lines = partial(tokenize.lines, prefix='move ')
@dataclass
class Move:
constant_name: str
animation_name: str
effect: str
power: int
type: str
@ -17,9 +17,9 @@ class Move:
def flatten(tokens):
for t in tokens:
assert t[0] == 'move', t
_, (constant_name, effect, power, type, accuracy, pp) = t
yield constant_name, Move(
constant_name,
_, (animation_name, effect, power, type, accuracy, pp) = t
yield Move(
animation_name,
effect,
number.parse(power),
type,
@ -30,4 +30,4 @@ def flatten(tokens):
def parse(prefix):
path = prefix / 'data/moves/moves.asm'
with open(path) as f:
return dict(flatten(tokenize_lines(f.read().split('\n'))))
return list(flatten(tokenize_lines(f.read().split('\n'))))