Skip to content

Commit

Permalink
to_bin()
Browse files Browse the repository at this point in the history
  • Loading branch information
svnv-svsv-jm committed Dec 28, 2023
1 parent 7471754 commit fe1df3a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/skypy/app/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
__all__ = ["to_bin"]

from loguru import logger
import subprocess
import os
import shutil

from skypy.const.loc import BIN_FOLDER, WAZA_SCHEMA, FILENAME_WAZA


def to_bin(
output_dir: str = BIN_FOLDER,
waza_schema: str = WAZA_SCHEMA,
) -> None:
"""Creates the waza.bin file."""
# Ensure output directory exists
os.makedirs(output_dir, exist_ok=True)

# Command to execute
command = [
"flatc",
"-b",
waza_schema,
os.path.join(output_dir, FILENAME_WAZA),
]

# Run the command
subprocess.run(command, check=False)

# Example: Copy the generated binary file to another directory
output_binary_path = os.path.join(output_dir, "personal_array.bin")
shutil.copy(os.path.join(output_dir, "personal_array.json"), output_binary_path)

print(f"Binary file copied to {output_binary_path}")
4 changes: 3 additions & 1 deletion src/skypy/app/waza.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from skypy.utils.nb import nb_init, pretty_waza
from skypy.const import ABILITIES, POKEMON, TYPES, MOVES
from skypy.ops import resume_waza, read_waza, write_waza_to_json, set_waza
from .utils import to_bin


class MoveEditor(ctk.CTkScrollableFrame):
Expand Down Expand Up @@ -140,8 +141,9 @@ def __update_df(self, event: tk.Event) -> None:

def __save(self) -> None:
"""Save Dataframe."""
logger.debug(f"Saving...")
logger.debug("Saving...")
write_waza_to_json(self.df)
to_bin()

def show_move_info(self) -> None:
"""Show move info."""
Expand Down
3 changes: 3 additions & 0 deletions src/skypy/const/loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
INPUT_FOLDER = os.path.join(ASSETS, "json")
INPUT_FOLDER_OVERRIDE = "input"
OUTPUT_FOLDER = "output"
BIN_FOLDER = "bin"
SCHEMA_FOLDER = os.path.normpath(os.path.join(ASSETS, "schema"))
WAZA_SCHEMA = os.path.join(SCHEMA_FOLDER, "waza_array.fbs")

0 comments on commit fe1df3a

Please sign in to comment.