mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-07-01 17:50:24 +08:00
json and tsv support for mapper
This commit is contained in:
65
mapper.py
65
mapper.py
@@ -6,10 +6,63 @@ from filereader import FileReader
|
||||
|
||||
class Mapper:
|
||||
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()
|
||||
file.close()
|
||||
|
||||
def process_map(self):
|
||||
reader = FileReader(io.BytesIO(self.data), "little")
|
||||
|
||||
# check file
|
||||
@@ -25,9 +78,6 @@ class Mapper:
|
||||
|
||||
reader.ReadBytes(2)
|
||||
|
||||
self.process_map(reader)
|
||||
|
||||
def process_map(self, reader):
|
||||
games = {
|
||||
"hk4e": "Genshin",
|
||||
"hkrpg": "Star Rail",
|
||||
@@ -113,7 +163,8 @@ class Mapper:
|
||||
if hasMusic:
|
||||
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):
|
||||
return None
|
||||
|
||||
@@ -144,10 +195,12 @@ class Mapper:
|
||||
|
||||
name = ["\\".join(name)]
|
||||
|
||||
if lang:
|
||||
if addLang:
|
||||
name.append(self.languages[lang])
|
||||
|
||||
return name
|
||||
elif self.mode in ["JSON", "TSV"]:
|
||||
return [self.keys[key]]
|
||||
|
||||
def reset(self):
|
||||
self.reader = None
|
||||
|
||||
Reference in New Issue
Block a user