1
0
mirror of https://github.com/Escartem/AnimeWwise.git synced 2026-06-27 07:30:29 +08:00

json and tsv support for mapper

This commit is contained in:
Escartem
2026-05-22 20:24:05 -04:00
parent 4e8b363795
commit 06c2393703

View File

@@ -6,10 +6,63 @@ from filereader import FileReader
class Mapper: class Mapper:
def __init__(self, mapping_file): def __init__(self, mapping_file):
file = open(mapping_file, "rb")
### NORMAL MAP LOADING ###
self.load_data(mapping_file)
self.load_map("MAP")
# you can use the following to load your own mapping instead of the official one
# for both cases, comment the 2 lines in the normal mode and uncomment the 2 in your mode
# and for both make sure of the following
#
# key -> the hashed path
# value -> without the .wem extension, by default the language is also removed and
# obtained back via addLang param but you can keep it in the path
#
# example : 3fe302b037275600 -> voice\\chapter4\\76\\player\\chapter4_76_player_118_f
### JSON MAP LOADING ###
# make sure the json is in the format {hash: path}
# format the path to use *double backward slashes*
#
# example
# {"3fe302b037275600": "voice\\chapter4\\76\\player\\chapter4_76_player_118_f"}
# self.load_data("maps/yourmap.json")
# self.load_map("JSON")
### TSV MAP LOADING ###
# make sure it is in the format "hash \t path"
# format the path to use *single backward slashes*
#
# example
# 3fe302b037275600 voice\chapter4\76\player\chapter4_76_player_118_f
# self.load_data("maps/yourmap.tsv")
# self.load_map("TSV")
def load_map(self, mode):
self.mode = mode
if self.mode == "MAP":
self.process_map()
elif self.mode == "JSON":
self.keys = json.loads(self.data)
elif self.mode == "TSV":
self.keys = {
parts[0]:parts[1]
for e in self.data.decode("utf-8").splitlines()
if (parts := e.split("\t")) and len(parts) >= 2}
def load_data(self, file):
file = open(file, "rb")
self.data = file.read() self.data = file.read()
file.close() file.close()
def process_map(self):
reader = FileReader(io.BytesIO(self.data), "little") reader = FileReader(io.BytesIO(self.data), "little")
# check file # check file
@@ -25,9 +78,6 @@ class Mapper:
reader.ReadBytes(2) reader.ReadBytes(2)
self.process_map(reader)
def process_map(self, reader):
games = { games = {
"hk4e": "Genshin", "hk4e": "Genshin",
"hkrpg": "Star Rail", "hkrpg": "Star Rail",
@@ -113,7 +163,8 @@ class Mapper:
if hasMusic: if hasMusic:
print(f": {n_music} musics") print(f": {n_music} musics")
def get_key(self, key, lang=False): def get_key(self, key, addLang=False):
if self.mode == "MAP":
if (not key in self.keys) and (not key in self.music_keys): if (not key in self.keys) and (not key in self.music_keys):
return None return None
@@ -144,10 +195,12 @@ class Mapper:
name = ["\\".join(name)] name = ["\\".join(name)]
if lang: if addLang:
name.append(self.languages[lang]) name.append(self.languages[lang])
return name return name
elif self.mode in ["JSON", "TSV"]:
return [self.keys[key]]
def reset(self): def reset(self):
self.reader = None self.reader = None