Files
arcaea-apk-assets/arcaea_apk_assets/processor.py
2025-07-06 18:43:00 +08:00

70 lines
2.0 KiB
Python

"""
Copyright (C) 2025 283375
This file is part of "arcaea-apk-assets" (stated as "this program" below).
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar
from typeguard import typechecked
from .assets import (
ArcaeaApkAsset,
ArcaeaApkAssetJacket,
ArcaeaApkAssetList,
ArcaeaApkAssetPartnerIcon,
)
if TYPE_CHECKING:
import zipfile
__all__ = ["ArcaeaApkAssetsProcessor"]
class ArcaeaApkAssetsProcessor:
ASSET_TYPES: ClassVar[list[type[ArcaeaApkAsset]]] = [
ArcaeaApkAssetJacket,
ArcaeaApkAssetPartnerIcon,
ArcaeaApkAssetList,
]
@classmethod
def get_asset(cls, asset_zip_filename: str) -> ArcaeaApkAsset | None:
asset = None
for asset_type in cls.ASSET_TYPES:
if asset_ := asset_type.from_zip_filename(asset_zip_filename):
asset = asset_
break
return asset
@classmethod
def is_asset(cls, asset_zip_filename: str) -> bool:
return cls.get_asset(asset_zip_filename) is not None
@classmethod
@typechecked
def get_assets(cls, zf: zipfile.ZipFile) -> dict[zipfile.ZipInfo, ArcaeaApkAsset]:
matches = {}
for info in zf.infolist():
filename = info.filename
asset = cls.get_asset(filename)
if asset is not None:
matches[info] = asset
return matches