2023-05-18 08:59:17 +00:00
|
|
|
import json
|
2023-10-23 06:40:51 +00:00
|
|
|
from typing import Dict, Tuple, List
|
2023-05-18 08:59:17 +00:00
|
|
|
|
2023-11-07 16:42:44 +00:00
|
|
|
from python_genshin_artifact import (
|
2023-05-18 08:59:17 +00:00
|
|
|
gen_character_meta_as_json,
|
|
|
|
gen_weapon_meta_as_json,
|
|
|
|
gen_artifact_meta_as_json,
|
|
|
|
gen_generate_locale_as_json,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Assets:
|
|
|
|
_instance: "Assets" = None
|
|
|
|
character: Dict[str, dict] = {}
|
|
|
|
weapon: Dict[str, dict] = {}
|
|
|
|
artifact: Dict[str, dict] = {}
|
2023-10-23 06:40:51 +00:00
|
|
|
locale: Dict[str, List[str]] = {}
|
2023-05-18 08:59:17 +00:00
|
|
|
langs: Tuple[str] = ("zh-cn", "en")
|
|
|
|
|
|
|
|
def __new__(cls):
|
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = super().__new__(cls)
|
|
|
|
cls._instance.reload_assets()
|
|
|
|
return cls._instance
|
|
|
|
|
|
|
|
def reload_assets(self) -> None:
|
|
|
|
self.__load_assets_data()
|
|
|
|
|
|
|
|
def __load_assets_data(self) -> None:
|
|
|
|
character_meta = gen_character_meta_as_json()
|
2023-10-21 12:08:26 +00:00
|
|
|
_characters = json.loads(character_meta)
|
|
|
|
for _character in _characters:
|
|
|
|
name = _character.get("name")
|
|
|
|
if name is not None:
|
|
|
|
self.character.setdefault(name, _character)
|
2023-05-18 08:59:17 +00:00
|
|
|
weapon_meta = gen_weapon_meta_as_json()
|
2023-10-21 12:08:26 +00:00
|
|
|
_weapons = json.loads(weapon_meta)
|
|
|
|
for _weapon in _weapons:
|
|
|
|
name = _weapon.get("name")
|
|
|
|
if name is not None:
|
|
|
|
self.weapon.setdefault(name, _weapon)
|
2023-05-18 08:59:17 +00:00
|
|
|
artifact_meta = gen_artifact_meta_as_json()
|
2023-10-21 12:08:26 +00:00
|
|
|
_artifacts = json.loads(artifact_meta)
|
|
|
|
for _artifact in _artifacts:
|
|
|
|
name = _artifact.get("name")
|
|
|
|
if name is not None:
|
|
|
|
self.artifact.setdefault(name, _artifact)
|
2023-05-18 08:59:17 +00:00
|
|
|
for loc in self.langs:
|
|
|
|
locale = gen_generate_locale_as_json(loc)
|
2023-10-21 12:08:26 +00:00
|
|
|
self.locale.setdefault(loc, json.loads(locale))
|