2023-05-01 13:31:48 +00:00
|
|
|
import ujson as json
|
|
|
|
from aiofiles import open as async_open
|
|
|
|
|
|
|
|
from model.enums import FoodQuality, ItemType, MaterialType
|
|
|
|
from model.item import Food, Item, Material, Namecard
|
|
|
|
from utils.const import PROJECT_ROOT
|
2023-04-29 14:59:16 +00:00
|
|
|
from utils.manager import ResourceManager
|
|
|
|
from utils.typedefs import Lang
|
|
|
|
|
2023-05-01 13:31:48 +00:00
|
|
|
OUT_DIR = PROJECT_ROOT.joinpath("out")
|
|
|
|
|
2023-04-29 14:59:16 +00:00
|
|
|
|
|
|
|
# noinspection PyShadowingBuiltins
|
|
|
|
async def parse_item_data(lang: Lang):
|
2023-05-01 13:31:48 +00:00
|
|
|
out_path = OUT_DIR.joinpath(f"{lang}")
|
|
|
|
out_path.mkdir(exist_ok=True, parents=True)
|
|
|
|
|
2023-04-29 14:59:16 +00:00
|
|
|
manager = ResourceManager(lang=lang)
|
|
|
|
json_data = manager.fetch("MaterialExcelConfigData")
|
2023-05-01 13:31:48 +00:00
|
|
|
|
|
|
|
item_list = []
|
|
|
|
for data in filter(lambda x: "rankLevel" in x, json_data):
|
2023-04-29 14:59:16 +00:00
|
|
|
id = data["id"]
|
2023-05-01 13:31:48 +00:00
|
|
|
if name := manager.get_text(data["nameTextMapHash"]) is None:
|
|
|
|
continue
|
2023-04-29 14:59:16 +00:00
|
|
|
type = manager.get_text(data["typeDescTextMapHash"])
|
|
|
|
icon = data["icon"]
|
|
|
|
rarity = data["rankLevel"]
|
2023-05-01 13:31:48 +00:00
|
|
|
description = manager.get_text(data["descTextMapHash"]) or ""
|
2023-04-29 14:59:16 +00:00
|
|
|
special_description = manager.get_text(data["specialDescTextMapHash"])
|
2023-05-01 13:31:48 +00:00
|
|
|
item_type = ItemType(data["itemType"].removeprefix("ITEM_"))
|
|
|
|
|
|
|
|
kwargs = {
|
|
|
|
"id": id,
|
|
|
|
"name": name,
|
|
|
|
"type": type,
|
|
|
|
"icon": icon,
|
|
|
|
"rarity": rarity,
|
|
|
|
"description": description,
|
|
|
|
"special_description": special_description,
|
|
|
|
"item_type": item_type,
|
|
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
|
|
if "picPath" in data and data["picPath"]:
|
|
|
|
pictures = data["picPath"]
|
|
|
|
item = Namecard(pictures=pictures, **kwargs)
|
|
|
|
|
|
|
|
elif "materialType" in data:
|
|
|
|
material_type = MaterialType(
|
|
|
|
data["materialType"].removeprefix("MATERIAL_")
|
|
|
|
)
|
|
|
|
item = Material(material_type=material_type, **kwargs)
|
|
|
|
elif "foodQuality" in data:
|
|
|
|
quality = FoodQuality(data["foodQuality"])
|
|
|
|
effect = manager.get_text(data["effectDescTextMapHash"])
|
|
|
|
effect_icon = data["effectIcon"]
|
|
|
|
effect_name = data["effectName"]
|
|
|
|
item = Food(
|
|
|
|
quality=quality,
|
|
|
|
effect=effect,
|
|
|
|
effect_icon=effect_icon,
|
|
|
|
effect_name=effect_name,
|
|
|
|
**kwargs,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
item = Item(**kwargs)
|
|
|
|
except Exception as e:
|
|
|
|
breakpoint()
|
|
|
|
raise e
|
|
|
|
|
|
|
|
item_list.append(item)
|
|
|
|
async with async_open(out_path / "item.json", encoding="utf-8", mode="w") as file:
|
|
|
|
await file.write(
|
|
|
|
json.dumps(
|
|
|
|
[i.dict() for i in item_list],
|
|
|
|
ensure_ascii=False,
|
|
|
|
encode_html_chars=False,
|
|
|
|
),
|
|
|
|
)
|
2023-04-29 14:59:16 +00:00
|
|
|
breakpoint()
|