Skip to content

Commit

Permalink
Asset packer bugfixes and improvements
Browse files Browse the repository at this point in the history
- Ignore hidden files
- Fix .DS_Store
- Check known extensions
- Support precompiled anims
- Fix FBT integration
  • Loading branch information
Willy-JL committed Mar 17, 2024
1 parent 0349924 commit 6ae098f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
13 changes: 9 additions & 4 deletions scripts/asset_packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def pack_anim(src: pathlib.Path, dst: pathlib.Path):
shutil.copyfile(src / "meta.txt", dst / "meta.txt")
continue
elif frame.name.startswith("frame_"):
(dst / frame.with_suffix(".bm").name).write_bytes(convert_bm(frame))
if frame.suffix == ".bm":
shutil.copyfile(frame, dst / frame.name)
elif frame.suffix == ".png":
(dst / frame.with_suffix(".bm").name).write_bytes(convert_bm(frame))


def pack_icon_animated(src: pathlib.Path, dst: pathlib.Path):
Expand Down Expand Up @@ -141,17 +144,19 @@ def pack(

if (source / "Icons").is_dir():
for icons in (source / "Icons").iterdir():
if not icons.is_dir():
if not icons.is_dir() or icons.name.startswith("."):
continue
for icon in icons.iterdir():
if icon.name.startswith("."):
continue
if icon.is_dir():
logger(
f"Compile: icon for pack '{source.name}': {icons.name}/{icon.name}"
)
pack_icon_animated(
icon, packed / "Icons" / icons.name / icon.name
)
elif icon.is_file():
elif icon.is_file() and icon.suffix == ".png":
logger(
f"Compile: icon for pack '{source.name}': {icons.name}/{icon.name}"
)
Expand All @@ -161,7 +166,7 @@ def pack(

if (source / "Fonts").is_dir():
for font in (source / "Fonts").iterdir():
if not font.is_file():
if not font.is_file() or font.name.startswith(".") or font.suffix != ".c":
continue
logger(f"Compile: font for pack '{source.name}': {font.name}")
pack_font(font, packed / "Fonts" / font.name)
Expand Down
24 changes: 15 additions & 9 deletions scripts/fbt_tools/fbt_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,30 @@ def _packs_emitter(target, source, env):
target_dir = target[0]
env.Replace(_PACKS_OUT_DIR=target_dir)
env.Replace(_PACKS_SRC_DIR=source_dir)
target = set();

target = [
target_dir.File(source_dir.rel_path(node))
target.update(
source_dir.rel_path(node)
for node in env.GlobRecursive("*/Anims/manifest.txt", source_dir.srcnode())
]
target.extend(
target_dir.File(source_dir.rel_path(node).removesuffix(".png") + ".bm")
)
target.update(
source_dir.rel_path(node)
for node in env.GlobRecursive("*/Anims/**/*.bm", source_dir.srcnode())
)
target.update(
source_dir.rel_path(node).removesuffix(".png") + ".bm"
for node in env.GlobRecursive("*/Anims/**/*.png", source_dir.srcnode())
)
target.extend(
target_dir.File(source_dir.rel_path(node).removesuffix(".png") + ".bmx")
target.update(
source_dir.rel_path(node).removesuffix(".png") + ".bmx"
for node in env.GlobRecursive("*/Icons/**/*.png", source_dir.srcnode())
)
target.extend(
target_dir.File(source_dir.rel_path(node).removesuffix(".c") + ".u8f")
target.update(
source_dir.rel_path(node).removesuffix(".c") + ".u8f"
for node in env.GlobRecursive("*/Fonts/*.c", source_dir.srcnode())
)

target = [target_dir.File(path) for path in target]
return target, source


Expand Down

0 comments on commit 6ae098f

Please sign in to comment.