generate: add moves
This commit is contained in:
parent
145b6b8936
commit
0348eb2e74
@ -9,8 +9,9 @@ def generate(base_path, target_path):
|
|||||||
path = base_path / filename
|
path = base_path / filename
|
||||||
if path != target_path:
|
if path != target_path:
|
||||||
continue
|
continue
|
||||||
|
buf = func().getvalue()
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(func().getvalue())
|
f.write(buf)
|
||||||
|
|
||||||
# sys.argv[1] is secretly used in parse
|
# sys.argv[1] is secretly used in parse
|
||||||
base_path = Path(sys.argv[2])
|
base_path = Path(sys.argv[2])
|
||||||
|
@ -5,6 +5,7 @@ from generate import tilesets
|
|||||||
from generate import collision_tile_ids
|
from generate import collision_tile_ids
|
||||||
from generate import text
|
from generate import text
|
||||||
from generate import text_pointers
|
from generate import text_pointers
|
||||||
|
from generate.move import moves
|
||||||
|
|
||||||
files = [
|
files = [
|
||||||
(maps.generate_header, "maps.hpp"),
|
(maps.generate_header, "maps.hpp"),
|
||||||
@ -21,4 +22,6 @@ files = [
|
|||||||
(text.generate_source, "text.cpp"),
|
(text.generate_source, "text.cpp"),
|
||||||
(text_pointers.generate_header, "text_pointers.hpp"),
|
(text_pointers.generate_header, "text_pointers.hpp"),
|
||||||
(text_pointers.generate_source, "text_pointers.cpp"),
|
(text_pointers.generate_source, "text_pointers.cpp"),
|
||||||
|
(moves.generate_header, "moves.hpp"),
|
||||||
|
(moves.generate_source, "moves.cpp"),
|
||||||
]
|
]
|
||||||
|
110
tools/generate/move/moves.py
Normal file
110
tools/generate/move/moves.py
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
"""
|
||||||
|
struct move_t {
|
||||||
|
uint8_t effect; // fixme: constants/move_effect_constants.asm
|
||||||
|
uint8_t power;
|
||||||
|
uint8_t type; // fixme: constants/type_constants.asm
|
||||||
|
uint8_t accuracy;
|
||||||
|
uint8_t pp;
|
||||||
|
|
||||||
|
enum move {
|
||||||
|
wing_attack,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const move_t moves[] = {
|
||||||
|
[move_t::pound] = {
|
||||||
|
.effect =
|
||||||
|
.power =
|
||||||
|
.type =
|
||||||
|
.accuracy =
|
||||||
|
.pp =
|
||||||
|
},
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
|
||||||
|
from generate.generate import renderer
|
||||||
|
from parse import parse
|
||||||
|
|
||||||
|
# parse.move_constants_list()
|
||||||
|
# parse.move_names_list()
|
||||||
|
# parse.move_moves_list()
|
||||||
|
|
||||||
|
def includes_header():
|
||||||
|
yield "#pragma once"
|
||||||
|
yield ""
|
||||||
|
|
||||||
|
def move_constants():
|
||||||
|
_move_constants = parse.move_constants_list()
|
||||||
|
_moves = list(parse.move_moves_list())
|
||||||
|
for constant_ix, constant_name in enumerate(_move_constants):
|
||||||
|
# move_constants is also used for animation names it will be
|
||||||
|
# modeled in a separate enum (e.g: there is no such move as
|
||||||
|
# "shrinking_square_black_anim", so it shouldn't appear in
|
||||||
|
# this enum). This appears to be a questionable decision in
|
||||||
|
# the pokered decompilation project, not an original design
|
||||||
|
# decision in the game.
|
||||||
|
if constant_ix < len(_moves):
|
||||||
|
yield constant_name
|
||||||
|
|
||||||
|
def struct_move_t():
|
||||||
|
_move_constants = move_constants()
|
||||||
|
_move_constants_str = (f"{s.lower()}," for s in _move_constants)
|
||||||
|
return [
|
||||||
|
"struct move_t {",
|
||||||
|
"uint8_t animation;",
|
||||||
|
"uint8_t effect;",
|
||||||
|
"uint8_t power;",
|
||||||
|
"uint8_t type;",
|
||||||
|
"uint8_t accuracy;",
|
||||||
|
"uint8_t pp;",
|
||||||
|
"",
|
||||||
|
"enum move {",
|
||||||
|
*_move_constants_str,
|
||||||
|
"};",
|
||||||
|
"};",
|
||||||
|
]
|
||||||
|
|
||||||
|
def extern_moves():
|
||||||
|
yield "extern const move_t moves[];"
|
||||||
|
|
||||||
|
def generate_header():
|
||||||
|
render, out = renderer()
|
||||||
|
render(includes_header())
|
||||||
|
render(struct_move_t())
|
||||||
|
render(extern_moves())
|
||||||
|
return out
|
||||||
|
|
||||||
|
def move(constant_index, constant_name):
|
||||||
|
_move = parse.move_moves_list()[constant_index]
|
||||||
|
return [
|
||||||
|
f"[move_t::{constant_name.lower()}] = {{",
|
||||||
|
".animation = 0,",
|
||||||
|
".effect = 0,",
|
||||||
|
f".power = {_move.power},",
|
||||||
|
".type = 0,",
|
||||||
|
f".accuracy = {_move.accuracy},",
|
||||||
|
f".pp = {_move.pp},",
|
||||||
|
"},"
|
||||||
|
]
|
||||||
|
|
||||||
|
def moves():
|
||||||
|
yield "const move_t moves[] = {"
|
||||||
|
for constant_index, constant_name in enumerate(move_constants()):
|
||||||
|
if constant_index == 0:
|
||||||
|
# no_move
|
||||||
|
yield f"[move_t::{constant_name.lower()}] = {{ 0 }},"
|
||||||
|
else:
|
||||||
|
yield from move(constant_index - 1, constant_name)
|
||||||
|
yield "};"
|
||||||
|
|
||||||
|
def includes_source():
|
||||||
|
yield '#include <cstdint>'
|
||||||
|
yield ''
|
||||||
|
yield '#include "moves.hpp"'
|
||||||
|
yield ''
|
||||||
|
|
||||||
|
def generate_source():
|
||||||
|
render, out = renderer()
|
||||||
|
render(includes_source())
|
||||||
|
render(moves())
|
||||||
|
return out
|
@ -7,7 +7,7 @@ tokenize_lines = partial(tokenize.lines, prefix='move ')
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Move:
|
class Move:
|
||||||
constant_name: str
|
animation_name: str
|
||||||
effect: str
|
effect: str
|
||||||
power: int
|
power: int
|
||||||
type: str
|
type: str
|
||||||
@ -17,9 +17,9 @@ class Move:
|
|||||||
def flatten(tokens):
|
def flatten(tokens):
|
||||||
for t in tokens:
|
for t in tokens:
|
||||||
assert t[0] == 'move', t
|
assert t[0] == 'move', t
|
||||||
_, (constant_name, effect, power, type, accuracy, pp) = t
|
_, (animation_name, effect, power, type, accuracy, pp) = t
|
||||||
yield constant_name, Move(
|
yield Move(
|
||||||
constant_name,
|
animation_name,
|
||||||
effect,
|
effect,
|
||||||
number.parse(power),
|
number.parse(power),
|
||||||
type,
|
type,
|
||||||
@ -30,4 +30,4 @@ def flatten(tokens):
|
|||||||
def parse(prefix):
|
def parse(prefix):
|
||||||
path = prefix / 'data/moves/moves.asm'
|
path = prefix / 'data/moves/moves.asm'
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
return dict(flatten(tokenize_lines(f.read().split('\n'))))
|
return list(flatten(tokenize_lines(f.read().split('\n'))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user