mirror of
https://github.com/PaiGramTeam/python-genshin-artifact.git
synced 2024-12-12 05:39:00 +00:00
28 lines
766 B
Python
28 lines
766 B
Python
import json
|
|
import os
|
|
from typing import Dict, Optional
|
|
|
|
PATH = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
class Assets:
|
|
_instance: "Assets" = None
|
|
character: Dict[str, dict] = {}
|
|
|
|
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:
|
|
path = os.path.join(PATH, "assets", "characters.json")
|
|
with open(path, "r", encoding="utf-8") as file:
|
|
self.character = json.load(file)
|
|
|
|
def get_character(self, character_id: int) -> Optional[dict]:
|
|
return self.character.get(str(character_id))
|