2023-02-17 07:02:21 +01:00
|
|
|
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
|
|
|
|
2023-02-17 07:02:21 +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:
|
2023-02-17 07:02:21 +01:00
|
|
|
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)}"
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
except IndexError:
|
|
|
|
self.logger.error(f"Invalid wacca version {version}")
|
|
|
|
exit(1)
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-17 07:02:21 +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")
|
|
|
|
):
|
2023-02-17 07:02:21 +01:00
|
|
|
self.logger.error("Could not find Table or Message folder, nothing to read")
|
|
|
|
return
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-17 07:02:21 +01:00
|
|
|
self.read_music(f"{self.bin_dir}/Table", "MusicParameterTable")
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-17 07:02:21 +01:00
|
|
|
def read_music(self, base_dir: str, table: str) -> None:
|
|
|
|
if not self.check_valid_pair(base_dir, table):
|
2023-08-08 16:17:56 +02:00
|
|
|
self.logger.warning(
|
2023-03-09 17:38:58 +01:00
|
|
|
f"Cannot find {table} uasset/uexp pair at {base_dir}, music will not be read"
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
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)
|
2023-02-17 07:02:21 +01:00
|
|
|
package_json = json.dumps(package, indent=4, sort_keys=True)
|
2023-03-09 17:38:58 +01:00
|
|
|
data = json.loads(package_json)
|
2023-02-17 07:02:21 +01:00
|
|
|
|
|
|
|
first_elem = data[0]
|
2023-03-09 17:38:58 +01:00
|
|
|
wacca_data = first_elem["rows"]
|
2023-02-17 07:02:21 +01:00
|
|
|
|
|
|
|
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"]
|
2023-02-17 07:02:21 +01:00
|
|
|
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,
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
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
|
|
|
|
2023-02-17 07:02:21 +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,
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
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,
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
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,
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
self.logger.info(f"Read song {song_id} chart 4")
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-17 07:02:21 +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")
|