2023-02-17 06:02:21 +00:00
|
|
|
from typing import Optional
|
|
|
|
from os import walk, path
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
from read import BaseReader
|
|
|
|
|
|
|
|
from core.config import CoreConfig
|
|
|
|
from titles.chuni.database import ChuniData
|
|
|
|
from titles.chuni.const import ChuniConstants
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
class ChuniReader(BaseReader):
|
2023-03-09 16:38:58 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
config: CoreConfig,
|
|
|
|
version: int,
|
|
|
|
bin_dir: Optional[str],
|
|
|
|
opt_dir: Optional[str],
|
|
|
|
extra: Optional[str],
|
|
|
|
) -> None:
|
2023-02-17 06:02:21 +00:00
|
|
|
super().__init__(config, version, bin_dir, opt_dir, extra)
|
|
|
|
self.data = ChuniData(config)
|
|
|
|
|
|
|
|
try:
|
2023-03-09 16:38:58 +00:00
|
|
|
self.logger.info(
|
|
|
|
f"Start importer for {ChuniConstants.game_ver_to_string(version)}"
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
except IndexError:
|
|
|
|
self.logger.error(f"Invalid chunithm version {version}")
|
|
|
|
exit(1)
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
async def read(self) -> None:
|
2023-02-17 06:02:21 +00:00
|
|
|
data_dirs = []
|
|
|
|
if self.bin_dir is not None:
|
|
|
|
data_dirs += self.get_data_directories(self.bin_dir)
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
if self.opt_dir is not None:
|
2023-03-09 16:38:58 +00:00
|
|
|
data_dirs += self.get_data_directories(self.opt_dir)
|
2024-09-05 15:45:22 +00:00
|
|
|
|
|
|
|
we_diff = "4"
|
|
|
|
if self.version >= ChuniConstants.VER_CHUNITHM_NEW:
|
|
|
|
we_diff = "5"
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
for dir in data_dirs:
|
|
|
|
self.logger.info(f"Read from {dir}")
|
2024-01-09 19:42:17 +00:00
|
|
|
await self.read_events(f"{dir}/event")
|
2024-09-05 15:45:22 +00:00
|
|
|
await self.read_music(f"{dir}/music", we_diff)
|
2024-01-09 19:42:17 +00:00
|
|
|
await self.read_charges(f"{dir}/chargeItem")
|
|
|
|
await self.read_avatar(f"{dir}/avatarAccessory")
|
|
|
|
await self.read_login_bonus(f"{dir}/")
|
2023-03-28 16:28:57 +00:00
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
async def read_login_bonus(self, root_dir: str) -> None:
|
2023-03-28 16:28:57 +00:00
|
|
|
for root, dirs, files in walk(f"{root_dir}loginBonusPreset"):
|
|
|
|
for dir in dirs:
|
|
|
|
if path.exists(f"{root}/{dir}/LoginBonusPreset.xml"):
|
2024-06-22 02:19:57 +00:00
|
|
|
with open(f"{root}/{dir}/LoginBonusPreset.xml", "r", encoding="utf-8") as fp:
|
|
|
|
strdata = fp.read()
|
2023-03-28 16:28:57 +00:00
|
|
|
|
|
|
|
xml_root = ET.fromstring(strdata)
|
|
|
|
for name in xml_root.findall("name"):
|
|
|
|
id = name.find("id").text
|
|
|
|
name = name.find("str").text
|
|
|
|
is_enabled = (
|
|
|
|
True if xml_root.find("disableFlag").text == "false" else False
|
|
|
|
)
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
result = await self.data.static.put_login_bonus_preset(
|
2023-03-28 16:28:57 +00:00
|
|
|
self.version, id, name, is_enabled
|
|
|
|
)
|
|
|
|
|
|
|
|
if result is not None:
|
|
|
|
self.logger.info(f"Inserted login bonus preset {id}")
|
|
|
|
else:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Failed to insert login bonus preset {id}")
|
2023-03-28 16:28:57 +00:00
|
|
|
|
|
|
|
for bonus in xml_root.find("infos").findall("LoginBonusDataInfo"):
|
|
|
|
for name in bonus.findall("loginBonusName"):
|
|
|
|
bonus_id = name.find("id").text
|
|
|
|
bonus_name = name.find("str").text
|
|
|
|
|
|
|
|
if path.exists(
|
|
|
|
f"{root_dir}/loginBonus/loginBonus{bonus_id}/LoginBonus.xml"
|
|
|
|
):
|
|
|
|
with open(
|
|
|
|
f"{root_dir}/loginBonus/loginBonus{bonus_id}/LoginBonus.xml",
|
|
|
|
"rb",
|
|
|
|
) as fp:
|
|
|
|
bytedata = fp.read()
|
|
|
|
strdata = bytedata.decode("UTF-8")
|
|
|
|
|
|
|
|
bonus_root = ET.fromstring(strdata)
|
|
|
|
|
|
|
|
for present in bonus_root.findall("present"):
|
|
|
|
present_id = present.find("id").text
|
|
|
|
present_name = present.find("str").text
|
|
|
|
|
|
|
|
item_num = int(bonus_root.find("itemNum").text)
|
|
|
|
need_login_day_count = int(
|
|
|
|
bonus_root.find("needLoginDayCount").text
|
|
|
|
)
|
|
|
|
login_bonus_category_type = int(
|
|
|
|
bonus_root.find("loginBonusCategoryType").text
|
|
|
|
)
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
result = await self.data.static.put_login_bonus(
|
2023-03-28 16:28:57 +00:00
|
|
|
self.version,
|
|
|
|
id,
|
|
|
|
bonus_id,
|
|
|
|
bonus_name,
|
|
|
|
present_id,
|
|
|
|
present_name,
|
|
|
|
item_num,
|
|
|
|
need_login_day_count,
|
|
|
|
login_bonus_category_type,
|
|
|
|
)
|
|
|
|
|
|
|
|
if result is not None:
|
|
|
|
self.logger.info(f"Inserted login bonus {bonus_id}")
|
|
|
|
else:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(
|
2023-03-28 16:28:57 +00:00
|
|
|
f"Failed to insert login bonus {bonus_id}"
|
|
|
|
)
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
async def read_events(self, evt_dir: str) -> None:
|
2023-02-17 06:02:21 +00:00
|
|
|
for root, dirs, files in walk(evt_dir):
|
|
|
|
for dir in dirs:
|
|
|
|
if path.exists(f"{root}/{dir}/Event.xml"):
|
2024-06-22 02:19:57 +00:00
|
|
|
with open(f"{root}/{dir}/Event.xml", "r", encoding="utf-8") as fp:
|
|
|
|
strdata = fp.read()
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
xml_root = ET.fromstring(strdata)
|
2023-03-09 16:38:58 +00:00
|
|
|
for name in xml_root.findall("name"):
|
|
|
|
id = name.find("id").text
|
|
|
|
name = name.find("str").text
|
|
|
|
for substances in xml_root.findall("substances"):
|
|
|
|
event_type = substances.find("type").text
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
result = await self.data.static.put_event(
|
2023-03-09 16:38:58 +00:00
|
|
|
self.version, id, event_type, name
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
if result is not None:
|
|
|
|
self.logger.info(f"Inserted event {id}")
|
|
|
|
else:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Failed to insert event {id}")
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2024-09-05 15:45:22 +00:00
|
|
|
async def read_music(self, music_dir: str, we_diff: str = "4") -> None:
|
2023-02-17 06:02:21 +00:00
|
|
|
for root, dirs, files in walk(music_dir):
|
|
|
|
for dir in dirs:
|
|
|
|
if path.exists(f"{root}/{dir}/Music.xml"):
|
2024-06-22 02:19:57 +00:00
|
|
|
with open(f"{root}/{dir}/Music.xml", "r", encoding='utf-8') as fp:
|
|
|
|
strdata = fp.read()
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
xml_root = ET.fromstring(strdata)
|
2023-03-09 16:38:58 +00:00
|
|
|
for name in xml_root.findall("name"):
|
|
|
|
song_id = name.find("id").text
|
|
|
|
title = name.find("str").text
|
|
|
|
|
|
|
|
for artistName in xml_root.findall("artistName"):
|
|
|
|
artist = artistName.find("str").text
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
for genreNames in xml_root.findall("genreNames"):
|
|
|
|
for list_ in genreNames.findall("list"):
|
|
|
|
for StringID in list_.findall("StringID"):
|
|
|
|
genre = StringID.find("str").text
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
for jaketFile in xml_root.findall("jaketFile"): # nice typo, SEGA
|
|
|
|
jacket_path = jaketFile.find("path").text
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
for fumens in xml_root.findall("fumens"):
|
|
|
|
for MusicFumenData in fumens.findall("MusicFumenData"):
|
|
|
|
fumen_path = MusicFumenData.find("file").find("path")
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2023-03-01 20:09:06 +00:00
|
|
|
if fumen_path is not None:
|
2023-09-09 12:10:33 +00:00
|
|
|
chart_type = MusicFumenData.find("type")
|
|
|
|
chart_id = chart_type.find("id").text
|
|
|
|
chart_diff = chart_type.find("str").text
|
2024-09-05 15:45:22 +00:00
|
|
|
if chart_diff == "WorldsEnd" and chart_id == we_diff: # 4 in SDBT, 5 in SDHD
|
2023-02-17 06:02:21 +00:00
|
|
|
level = float(xml_root.find("starDifType").text)
|
2023-03-09 16:38:58 +00:00
|
|
|
we_chara = (
|
|
|
|
xml_root.find("worldsEndTagName")
|
|
|
|
.find("str")
|
|
|
|
.text
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
else:
|
2023-03-09 16:38:58 +00:00
|
|
|
level = float(
|
|
|
|
f"{MusicFumenData.find('level').text}.{MusicFumenData.find('levelDecimal').text}"
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
we_chara = None
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
result = await self.data.static.put_music(
|
2023-02-17 06:02:21 +00:00
|
|
|
self.version,
|
|
|
|
song_id,
|
2023-03-09 16:38:58 +00:00
|
|
|
chart_id,
|
2023-02-17 06:02:21 +00:00
|
|
|
title,
|
|
|
|
artist,
|
|
|
|
level,
|
|
|
|
genre,
|
|
|
|
jacket_path,
|
2023-03-09 16:38:58 +00:00
|
|
|
we_chara,
|
2023-02-17 06:02:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if result is not None:
|
2023-03-09 16:38:58 +00:00
|
|
|
self.logger.info(
|
|
|
|
f"Inserted music {song_id} chart {chart_id}"
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
else:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(
|
2023-03-09 16:38:58 +00:00
|
|
|
f"Failed to insert music {song_id} chart {chart_id}"
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
async def read_charges(self, charge_dir: str) -> None:
|
2023-02-17 06:02:21 +00:00
|
|
|
for root, dirs, files in walk(charge_dir):
|
|
|
|
for dir in dirs:
|
|
|
|
if path.exists(f"{root}/{dir}/ChargeItem.xml"):
|
2024-06-22 02:19:57 +00:00
|
|
|
with open(f"{root}/{dir}/ChargeItem.xml", "r", encoding='utf-8') as fp:
|
|
|
|
strdata = fp.read()
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
xml_root = ET.fromstring(strdata)
|
2023-03-09 16:38:58 +00:00
|
|
|
for name in xml_root.findall("name"):
|
|
|
|
id = name.find("id").text
|
|
|
|
name = name.find("str").text
|
|
|
|
expirationDays = xml_root.find("expirationDays").text
|
|
|
|
consumeType = xml_root.find("consumeType").text
|
|
|
|
sellingAppeal = bool(xml_root.find("sellingAppeal").text)
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
result = await self.data.static.put_charge(
|
2023-03-09 16:38:58 +00:00
|
|
|
self.version,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
expirationDays,
|
|
|
|
consumeType,
|
|
|
|
sellingAppeal,
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
if result is not None:
|
|
|
|
self.logger.info(f"Inserted charge {id}")
|
|
|
|
else:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Failed to insert charge {id}")
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
async def read_avatar(self, avatar_dir: str) -> None:
|
2023-02-17 06:02:21 +00:00
|
|
|
for root, dirs, files in walk(avatar_dir):
|
|
|
|
for dir in dirs:
|
|
|
|
if path.exists(f"{root}/{dir}/AvatarAccessory.xml"):
|
2024-06-22 02:19:57 +00:00
|
|
|
with open(f"{root}/{dir}/AvatarAccessory.xml", "r", encoding='utf-8') as fp:
|
|
|
|
strdata = fp.read()
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
xml_root = ET.fromstring(strdata)
|
2023-03-09 16:38:58 +00:00
|
|
|
for name in xml_root.findall("name"):
|
|
|
|
id = name.find("id").text
|
|
|
|
name = name.find("str").text
|
|
|
|
category = xml_root.find("category").text
|
|
|
|
for image in xml_root.findall("image"):
|
|
|
|
iconPath = image.find("path").text
|
|
|
|
for texture in xml_root.findall("texture"):
|
|
|
|
texturePath = texture.find("path").text
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
result = await self.data.static.put_avatar(
|
2023-03-09 16:38:58 +00:00
|
|
|
self.version, id, name, category, iconPath, texturePath
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
if result is not None:
|
|
|
|
self.logger.info(f"Inserted avatarAccessory {id}")
|
|
|
|
else:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Failed to insert avatarAccessory {id}")
|