This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD - Export unit info model to json (#33)
Signed-off-by: RaenonX <[email protected]>
- Loading branch information
Showing
24 changed files
with
295 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Entry of a character info.""" | ||
from dataclasses import dataclass, field | ||
from typing import Any | ||
|
||
from dlparse.enums import Weapon | ||
from dlparse.mono.asset import CharaDataEntry | ||
from .base import UnitInfoEntryBase | ||
|
||
__all__ = ("CharaInfoEntry",) | ||
|
||
|
||
@dataclass | ||
class CharaInfoEntry(UnitInfoEntryBase[CharaDataEntry]): | ||
"""Chara info entry class.""" | ||
|
||
weapon: Weapon = field(init=False) | ||
|
||
has_unique_dragon: bool = field(init=False) | ||
|
||
def __post_init__(self): | ||
super().__post_init__() | ||
|
||
self.weapon = self.unit_data.weapon | ||
self.has_unique_dragon = self.unit_data.has_unique_dragon | ||
|
||
def to_json_entry(self) -> dict[str, Any]: | ||
return super().to_json_entry() | { | ||
"weapon": self.weapon.value, | ||
"hasUniqueDragon": self.has_unique_dragon | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Entry of a dragon info.""" | ||
from dataclasses import dataclass | ||
|
||
from dlparse.mono.asset import DragonDataEntry | ||
from .base import UnitInfoEntryBase | ||
|
||
__all__ = ("DragonInfoEntry",) | ||
|
||
|
||
@dataclass | ||
class DragonInfoEntry(UnitInfoEntryBase[DragonDataEntry]): | ||
"""Dragon info entry class.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Functions to export unit info, including characters and dragons.""" | ||
from dlparse.errors import ( | ||
AbilityConditionUnconvertibleError, AbilityLimitDataNotFoundError, AbilityOnSkillUnconvertibleError, | ||
AbilityVariantUnconvertibleError, | ||
) | ||
from dlparse.export.entry import CharaInfoEntry, DragonInfoEntry | ||
from dlparse.mono.manager import AssetManager | ||
from .base import export_as_json, print_skipped_messages | ||
|
||
__all__ = ( | ||
"export_chara_info_as_entries", "export_chara_info_as_json", | ||
"export_dragon_info_as_entries", "export_dragon_info_as_json", | ||
) | ||
|
||
|
||
def export_chara_info_as_entries( | ||
asset_manager: AssetManager, /, skip_unparsable: bool = True | ||
) -> list[CharaInfoEntry]: | ||
"""Export all character info as entries.""" | ||
entries: list[CharaInfoEntry] = [] | ||
skipped_messages: list[str] = [] | ||
|
||
for chara_data in asset_manager.asset_chara_data.playable_data: | ||
try: | ||
entries.append(CharaInfoEntry( | ||
asset_manager=asset_manager, unit_data=chara_data | ||
)) | ||
except (AbilityOnSkillUnconvertibleError, AbilityConditionUnconvertibleError, | ||
AbilityVariantUnconvertibleError, AbilityLimitDataNotFoundError) as ex: | ||
if skip_unparsable: | ||
skipped_messages.append( | ||
f"[Chara Info] Character ID #{chara_data.id} " | ||
f"({chara_data.get_name(asset_manager.asset_text_multi)})" | ||
) | ||
continue | ||
|
||
raise ex | ||
|
||
print_skipped_messages(skipped_messages) | ||
|
||
return entries | ||
|
||
|
||
def export_chara_info_as_json(file_path: str, asset_manager: AssetManager, /, skip_unparsable: bool = True): | ||
"""Export all character info as json.""" | ||
export_as_json(export_chara_info_as_entries(asset_manager, skip_unparsable=skip_unparsable), file_path) | ||
|
||
|
||
def export_dragon_info_as_entries( | ||
asset_manager: AssetManager, /, skip_unparsable: bool = True | ||
) -> list[DragonInfoEntry]: | ||
"""Export all character info as entries.""" | ||
entries: list[DragonInfoEntry] = [] | ||
skipped_messages: list[str] = [] | ||
|
||
for dragon_data in asset_manager.asset_dragon_data.playable_data: | ||
try: | ||
entries.append(DragonInfoEntry( | ||
asset_manager=asset_manager, unit_data=dragon_data | ||
)) | ||
except (AbilityOnSkillUnconvertibleError, AbilityConditionUnconvertibleError, | ||
AbilityVariantUnconvertibleError, AbilityLimitDataNotFoundError) as ex: | ||
if skip_unparsable: | ||
skipped_messages.append( | ||
f"[Dragon Info] Dragon ID #{dragon_data.id} " | ||
f"({dragon_data.get_name(asset_manager.asset_text_multi)})" | ||
) | ||
continue | ||
|
||
raise ex | ||
|
||
print_skipped_messages(skipped_messages) | ||
|
||
return entries | ||
|
||
|
||
def export_dragon_info_as_json(file_path: str, asset_manager: AssetManager, /, skip_unparsable: bool = True): | ||
"""Export all character info as json.""" | ||
export_as_json(export_dragon_info_as_entries(asset_manager, skip_unparsable=skip_unparsable), file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.