mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-27 03:49:58 -07:00
Asset Packer: Fix edge cases for animated icons
- FBT allows animated icons with any frame naming scheme - Flipper needs precise naming - This will ensure correct parsing and correct output - If .bm and .png input for packer is mixed, could have issues due to inconsistent naming between input and output (duplicated frames)
This commit is contained in:
@@ -69,22 +69,24 @@ def pack_icon_animated(src: pathlib.Path, dst: pathlib.Path):
|
||||
frame_count = 0
|
||||
frame_rate = None
|
||||
size = None
|
||||
for frame in src.iterdir():
|
||||
files = [file for file in src.iterdir() if file.is_file()]
|
||||
for frame in sorted(files, key=lambda x: x.name):
|
||||
if not frame.is_file():
|
||||
continue
|
||||
if frame.name == "frame_rate":
|
||||
frame_rate = int(frame.read_text())
|
||||
frame_rate = int(frame.read_text().strip())
|
||||
elif frame.name == "meta":
|
||||
shutil.copyfile(frame, dst / frame.name)
|
||||
elif frame.name.startswith("frame_"):
|
||||
else:
|
||||
dst_frame = dst / f"frame_{frame_count:02}.bm"
|
||||
if frame.suffix == ".png":
|
||||
if not size:
|
||||
size = Image.open(frame).size
|
||||
(dst / frame.with_suffix(".bm").name).write_bytes(convert_bm(frame))
|
||||
dst_frame.write_bytes(convert_bm(frame))
|
||||
frame_count += 1
|
||||
elif frame.suffix == ".bm":
|
||||
if not (dst / frame.name).is_file():
|
||||
shutil.copyfile(frame, dst / frame.name)
|
||||
if frame.with_suffix(".png") not in files:
|
||||
shutil.copyfile(frame, dst_frame)
|
||||
frame_count += 1
|
||||
if size is not None and frame_rate is not None:
|
||||
(dst / "meta").write_bytes(struct.pack("<IIII", *size, frame_rate, frame_count))
|
||||
|
||||
Reference in New Issue
Block a user