Skip to content

Commit

Permalink
Have loads return the root name
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcaliburZero committed Oct 7, 2023
1 parent adef14d commit 0e6e52e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
31 changes: 17 additions & 14 deletions cbpickaxe/hoylake.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def load_animation(self, path: str) -> Animation:

raise ValueError(f"Could not find animation file at path: {path}")

def load_monster_form(self, path: str) -> MonsterForm:
def load_monster_form(self, path: str) -> Tuple[RootName, MonsterForm]:
"""
Loads in the monster form at the given res:// filepath.
Expand All @@ -92,7 +92,7 @@ def load_monster_form(self, path: str) -> MonsterForm:
relative_path = Hoylake.__parse_res_path(path)

if relative_path in self.__monster_forms:
return self.__monster_forms[relative_path][1]
return self.__monster_forms[relative_path]

for root_name, root in self.__roots.items():
monster_path = root / relative_path
Expand All @@ -101,11 +101,11 @@ def load_monster_form(self, path: str) -> MonsterForm:
monster_form = MonsterForm.from_tres(input_stream)
self.__monster_forms[relative_path] = (root_name, monster_form)

return monster_form
return (root_name, monster_form)

raise ValueError(f"Could not find monster file at path: {path}")

def load_monster_forms(self, path: str) -> Dict[str, MonsterForm]:
def load_monster_forms(self, path: str) -> Dict[str, Tuple[RootName, MonsterForm]]:
"""
Loads in all of the monster forms within the given res:// directory path.
Expand All @@ -117,7 +117,7 @@ def load_monster_forms(self, path: str) -> Dict[str, MonsterForm]:

relative_path = Hoylake.__parse_res_path(path)

monster_forms: Dict[str, MonsterForm] = {}
monster_forms: Dict[str, Tuple[RootName, MonsterForm]] = {}
for root_name, root in self.__roots.items():
monsters_dir_path = root / relative_path
if monsters_dir_path.exists():
Expand All @@ -128,22 +128,25 @@ def load_monster_forms(self, path: str) -> Dict[str, MonsterForm]:
if monster_relative_path in self.__monster_forms:
monster_forms[
f"res://{monster_relative_path}"
] = self.__monster_forms[monster_relative_path][1]
] = self.__monster_forms[monster_relative_path]
continue

with open(monster_path, "r", encoding="utf-8") as input_stream:
monster_form = MonsterForm.from_tres(input_stream)

monster_relative_path = relative_path / monster_path.name
monster_forms[f"res://{monster_relative_path}"] = monster_form
monster_forms[f"res://{monster_relative_path}"] = (
root_name,
monster_form,
)
self.__monster_forms[monster_relative_path] = (
root_name,
monster_form,
)

return monster_forms

def load_move(self, path: str) -> Move:
def load_move(self, path: str) -> Tuple[RootName, Move]:
"""
Loads in the move at the given res:// filepath.
Expand All @@ -157,7 +160,7 @@ def load_move(self, path: str) -> Move:
relative_path = Hoylake.__parse_res_path(path)

if relative_path in self.__moves:
return self.__moves[relative_path][1]
return self.__moves[relative_path]

for root_name, root in self.__roots.items():
move_path = root / relative_path
Expand All @@ -166,11 +169,11 @@ def load_move(self, path: str) -> Move:
move = Move.from_tres(input_stream)
self.__moves[relative_path] = (root_name, move)

return move
return (root_name, move)

raise ValueError(f"Could not find monster file at path: {path}")

def load_moves(self, path: str) -> Dict[str, Move]:
def load_moves(self, path: str) -> Dict[str, Tuple[RootName, Move]]:
"""
Loads in all of the moves within the given res:// directory path.
Expand All @@ -182,7 +185,7 @@ def load_moves(self, path: str) -> Dict[str, Move]:

relative_path = Hoylake.__parse_res_path(path)

moves: Dict[str, Move] = {}
moves: Dict[str, Tuple[RootName, Move]] = {}
for root_name, root in self.__roots.items():
moves_dir_path = root / relative_path
if moves_dir_path.exists():
Expand All @@ -196,13 +199,13 @@ def load_moves(self, path: str) -> Dict[str, Move]:
if move_relative_path in self.__moves:
moves[f"res://{move_relative_path}"] = self.__moves[
move_relative_path
][1]
]
continue

with open(move_path, "r", encoding="utf-8") as input_stream:
move = Move.from_tres(input_stream)

moves[f"res://{move_relative_path}"] = move
moves[f"res://{move_relative_path}"] = (root_name, move)
self.__moves[move_relative_path] = (root_name, move)

return moves
Expand Down
2 changes: 1 addition & 1 deletion cbpickaxe_scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def main(argv: List[str]) -> int:
monster_form_images_dir = monster_forms_dir / "sprites"
monster_form_images_dir.mkdir()

monster_path, monster_form = sorted(monster_forms.items())[0]
monster_path, (_, monster_form) = sorted(monster_forms.items())[0]
monster_page_filepath = monster_forms_dir / (
hoylake.translate(monster_form.name) + ".html"
)
Expand Down
4 changes: 2 additions & 2 deletions cbpickaxe_scripts/get_move_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def main(argv: List[str]) -> int:
users = [
hoylake.translate(monster_form.name)
for _, monster_form in sorted(
hoylake.get_monster_forms_by_tags(move.tags).items(),
hoylake.get_monster_forms_by_tags(move[1].tags).items(),
key=lambda d: (d[1].bestiary_index, hoylake.translate(d[1].name)),
)
]
writer.writerow(
{
"move": hoylake.translate(move.name),
"move": hoylake.translate(move[1].name),
"users": ", ".join(users),
}
)
Expand Down
4 changes: 2 additions & 2 deletions misc_scripts/monster_max_move_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def main(argv: List[str]) -> int:
print("{{#switch: {{{1|}}}")
for _, monster_form in sorted(
monster_forms.items(),
key=lambda d: (d[1].bestiary_index, hoylake.translate(d[1].name)),
key=lambda d: (d[1][1].bestiary_index, hoylake.translate(d[1][1].name)),
):
print(
f"| {hoylake.translate(monster_form.name)} = {monster_form.max_move_slots}"
f"| {hoylake.translate(monster_form[1].name)} = {monster_form[1].max_move_slots}"
)
print("| #default = Unknown")
print("}}")
Expand Down
4 changes: 2 additions & 2 deletions misc_scripts/try_hoylake.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def main(argv: List[str]) -> int:
_ = hoylake.load_monster_forms("res://data/monster_forms/")
_ = hoylake.load_monster_forms("res://data/monster_forms_secret/")

move = hoylake.load_move("res://data/battle_moves/carnivore.tres")
move = hoylake.load_move("res://data/battle_moves/carnivore.tres")[1]
for path, monster_form in hoylake.get_monster_forms_by_tags(move.tags).items():
print(path, monster_form)

Expand All @@ -40,7 +40,7 @@ def main(argv: List[str]) -> int:

monster_form = hoylake.load_monster_form(
"res://data/monster_forms/shining_kuneko.tres"
)
)[1]
for path, move in hoylake.get_moves_by_tags(monster_form.move_tags).items():
print(path, move)

Expand Down

0 comments on commit 0e6e52e

Please sign in to comment.