Skip to content

Commit

Permalink
Count pack anims by unique names
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Sep 7, 2024
1 parent 6bf0fa5 commit cc91a38
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions indexer/src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def parse(self, filename: str) -> None:


class PackParser(BaseModel):
anim_regex: ClassVar[re.Pattern] = re.compile(rb"^Name: ", re.MULTILINE)
anim_regex: ClassVar[re.Pattern] = re.compile(rb"^Name: (.*)", re.MULTILINE)

def getSHA256(self, filepath: str) -> str:
with open(filepath, "rb") as file:
Expand All @@ -241,16 +241,17 @@ def parse(self, packpath: str) -> Pack:
description=meta.get("description", ""),
)

anims_names = set()
for pack_entry in (pack_set / "source").iterdir():
if not pack_entry.is_dir():
continue
anims = 0
anims = set()
icons = 0
passport = set()
fonts = set()
if (pack_entry / "Anims/manifest.txt").is_file():
manifest = (pack_entry / "Anims/manifest.txt").read_bytes()
anims = sum(1 for _ in self.anim_regex.finditer(manifest))
anims.update(m.group(1) for m in self.anim_regex.finditer(manifest))
if (pack_entry / "Icons").is_dir():
for icon_set in (pack_entry / "Icons").iterdir():
if icon_set.name.startswith(".") or not icon_set.is_dir():
Expand Down Expand Up @@ -279,7 +280,7 @@ def parse(self, packpath: str) -> Pack:
fonts.add(font.stem)
if anims or icons or passport or fonts:
pack.stats.packs += 1
pack.stats.anims += anims
anims_names.update(anims)
pack.stats.icons += icons
pack.stats.passport = sorted(passport.union(pack.stats.passport))
pack.stats.fonts = sorted(fonts.union(pack.stats.fonts))
Expand All @@ -288,6 +289,7 @@ def parse(self, packpath: str) -> Pack:
logging.warn(
f"Pack {pack_entry.name!r} in set {pack_set.name!r} is empty"
)
pack.stats.anims = len(anims_names)

for file in (pack_set / "download").iterdir():
if file.name.startswith(".") or not file.is_file():
Expand Down

0 comments on commit cc91a38

Please sign in to comment.