1
0
mirror of synced 2024-12-18 16:25:53 +01:00
artemis/titles/wacca/read.py

136 lines
4.3 KiB
Python
Raw Normal View History

from typing import Optional
import wacky
import json
from os import walk, path
from read import BaseReader
from core.config import CoreConfig
from titles.wacca.database import WaccaData
from titles.wacca.const import WaccaConstants
2023-03-09 17:38:58 +01:00
class WaccaReader(BaseReader):
2023-03-09 17:38:58 +01:00
def __init__(
self,
config: CoreConfig,
version: int,
bin_dir: Optional[str],
opt_dir: Optional[str],
extra: Optional[str],
) -> None:
super().__init__(config, version, bin_dir, opt_dir, extra)
self.data = WaccaData(config)
try:
2023-03-09 17:38:58 +01:00
self.logger.info(
f"Start importer for {WaccaConstants.game_ver_to_string(version)}"
)
except IndexError:
self.logger.error(f"Invalid wacca version {version}")
exit(1)
2023-03-09 17:38:58 +01:00
def read(self) -> None:
2023-03-09 17:38:58 +01:00
if not (
path.exists(f"{self.bin_dir}/Table")
and path.exists(f"{self.bin_dir}/Message")
):
self.logger.error("Could not find Table or Message folder, nothing to read")
return
2023-03-09 17:38:58 +01:00
self.read_music(f"{self.bin_dir}/Table", "MusicParameterTable")
2023-03-09 17:38:58 +01:00
def read_music(self, base_dir: str, table: str) -> None:
if not self.check_valid_pair(base_dir, table):
2023-03-09 17:38:58 +01:00
self.logger.warn(
f"Cannot find {table} uasset/uexp pair at {base_dir}, music will not be read"
)
return
2023-03-09 17:38:58 +01:00
uasset = open(f"{base_dir}/{table}.uasset", "rb")
uexp = open(f"{base_dir}/{table}.uexp", "rb")
package = wacky.jsonify(uasset, uexp)
package_json = json.dumps(package, indent=4, sort_keys=True)
2023-03-09 17:38:58 +01:00
data = json.loads(package_json)
first_elem = data[0]
2023-03-09 17:38:58 +01:00
wacca_data = first_elem["rows"]
for i, key in enumerate(wacca_data):
song_id = int(key)
2023-03-09 17:38:58 +01:00
title = wacca_data[str(key)]["MusicMessage"]
artist = wacca_data[str(key)]["ArtistMessage"]
bpm = wacca_data[str(key)]["Bpm"]
jacket_asset_name = wacca_data[str(key)]["JacketAssetName"]
diff = float(wacca_data[str(key)]["DifficultyNormalLv"])
designer = wacca_data[str(key)]["NotesDesignerNormal"]
if diff > 0:
2023-03-09 17:38:58 +01:00
self.data.static.put_music(
self.version,
song_id,
1,
title,
artist,
bpm,
diff,
designer,
jacket_asset_name,
)
self.logger.info(f"Read song {song_id} chart 1")
diff = float(wacca_data[str(key)]["DifficultyHardLv"])
designer = wacca_data[str(key)]["NotesDesignerHard"]
2023-03-09 17:38:58 +01:00
if diff > 0:
2023-03-09 17:38:58 +01:00
self.data.static.put_music(
self.version,
song_id,
2,
title,
artist,
bpm,
diff,
designer,
jacket_asset_name,
)
self.logger.info(f"Read song {song_id} chart 2")
diff = float(wacca_data[str(key)]["DifficultyExtremeLv"])
designer = wacca_data[str(key)]["NotesDesignerExpert"]
if diff > 0:
2023-03-09 17:38:58 +01:00
self.data.static.put_music(
self.version,
song_id,
3,
title,
artist,
bpm,
diff,
designer,
jacket_asset_name,
)
self.logger.info(f"Read song {song_id} chart 3")
diff = float(wacca_data[str(key)]["DifficultyInfernoLv"])
designer = wacca_data[str(key)]["NotesDesignerInferno"]
if diff > 0:
2023-03-09 17:38:58 +01:00
self.data.static.put_music(
self.version,
song_id,
4,
title,
artist,
bpm,
diff,
designer,
jacket_asset_name,
)
self.logger.info(f"Read song {song_id} chart 4")
2023-03-09 17:38:58 +01:00
def check_valid_pair(self, dir: str, file: str) -> bool:
2023-03-09 17:38:58 +01:00
return path.exists(f"{dir}/{file}.uasset") and path.exists(f"{dir}/{file}.uexp")