You've already forked PythonLib
mirror of
https://github.com/lifebottle/PythonLib.git
synced 2026-02-13 15:25:50 -08:00
Fix "Speaker" and voice_id replace
This commit is contained in:
27
ToolsTOR.py
27
ToolsTOR.py
@@ -160,12 +160,8 @@ class ToolsTOR(ToolsTales):
|
||||
xml_jap_cleaned = self.clean_text(xml_jap)
|
||||
|
||||
if key == xml_jap_cleaned:
|
||||
split_text = re.split(r"(<voice:\w+>)", xml_eng)
|
||||
item = self.add_line_break(item)
|
||||
|
||||
if len(split_text) >= 2:
|
||||
item = split_text[1] + item
|
||||
|
||||
if xml_eng != item:
|
||||
entry_node.find("EnglishText").text = item
|
||||
need_save = True
|
||||
@@ -278,7 +274,7 @@ class ToolsTOR(ToolsTales):
|
||||
|
||||
root = etree.Element("SceneText")
|
||||
speakers_node = etree.SubElement(root, 'Speakers')
|
||||
etree.SubElement(speakers_node, 'Section').text = "Speakers"
|
||||
etree.SubElement(speakers_node, 'Section').text = "Speaker"
|
||||
strings_node = etree.SubElement(root, 'Strings')
|
||||
etree.SubElement(strings_node, 'Section').text = section
|
||||
|
||||
@@ -759,24 +755,21 @@ class ToolsTOR(ToolsTales):
|
||||
data = pak.read()
|
||||
theirsce = io.BytesIO(pak2lib.get_theirsce_from_pak2(data))
|
||||
|
||||
rsce = Theirsce(path=theirsce)
|
||||
# pointers_offset, texts_offset = self.extract_Story_Pointers(rsce)
|
||||
names, lines = self.extract_lines_with_speaker(rsce)
|
||||
|
||||
for i, (k, v) in enumerate(names.items(), -1):
|
||||
names[k] = NameEntry(i, v)
|
||||
|
||||
with open('../{}.theirsce'.format(file_name), 'wb') as f:
|
||||
f.write(theirsce.getvalue())
|
||||
|
||||
header = theirsce.read(8)
|
||||
pointer_block = struct.unpack("<L", theirsce.read(4))[0]
|
||||
strings_offset = struct.unpack("<L", theirsce.read(4))[0]
|
||||
|
||||
# File size
|
||||
fsize = theirsce.getbuffer().nbytes
|
||||
theirsce.seek(pointer_block, 0) # Go the the start of the pointer section
|
||||
pointers_offset, texts_offset = self.extract_Story_Pointers(theirsce, strings_offset, fsize,
|
||||
self.story_byte_code)
|
||||
|
||||
text_list = []
|
||||
if text:
|
||||
text_list = [self.bytes_to_text(theirsce, ele)[0] for ele in texts_offset]
|
||||
text_list = [line.text for line in lines]
|
||||
|
||||
df = pd.DataFrame({"Pointers_Offset": pointers_offset, "Text_Offset":texts_offset, "Jap_Text": text_list})
|
||||
df = pd.DataFrame({"Jap_Text": text_list})
|
||||
df['Text_Offset'] = df['Text_Offset'].apply(lambda x: hex(x)[2:])
|
||||
df['Pointers_Offset'] = df['Pointers_Offset'].apply(lambda x: hex(x)[2:])
|
||||
df.to_excel('../{}.xlsx'.format(self.get_file_name(file_name)), index=False)
|
||||
|
||||
@@ -567,8 +567,12 @@ class ToolsTales:
|
||||
dict_current_translations = dict(zip(keys, items))
|
||||
|
||||
for new_entry in new_root.iter("Entry"):
|
||||
jap_text = new_entry.find("JapaneseText").text
|
||||
|
||||
jap_text = new_entry.find("JapaneseText").text or ''
|
||||
|
||||
#Remove voiceId because its part of a node now
|
||||
if jap_text.startswith("<voice:"):
|
||||
jap_text = re.split(self.COMMON_TAG, jap_text)[2]
|
||||
|
||||
if jap_text in dict_current_translations:
|
||||
entry_found = dict_current_translations[jap_text]
|
||||
|
||||
@@ -580,7 +584,50 @@ class ToolsTales:
|
||||
txt=etree.tostring(new_root, encoding="UTF-8", pretty_print=True)
|
||||
with open(new_XML_path, "wb") as xmlFile:
|
||||
xmlFile.write(txt)
|
||||
|
||||
|
||||
def denkou_Copy_Script(self, source_folder):
|
||||
destinationFolder = '../{}/Data/{}/Story/XML'.format(self.repo_name, self.gameName)
|
||||
fileList = os.listdir(source_folder)
|
||||
dictionnary = {}
|
||||
|
||||
for file in fileList:
|
||||
with open(os.path.join(source_folder, file), 'r', encoding='utf-8') as f:
|
||||
contents = f.read()
|
||||
tree = ET.fromstring(contents)
|
||||
|
||||
for entry in tree.iter("Entry"):
|
||||
key = entry.find("JapaneseText").text
|
||||
value = entry.find("EnglishText").text
|
||||
|
||||
if key and key not in dictionnary and value:
|
||||
dictionnary[key] = value
|
||||
#print(key + " = " + value)
|
||||
|
||||
fileList = os.listdir(destinationFolder)
|
||||
|
||||
for file in fileList:
|
||||
save = False
|
||||
|
||||
with open(os.path.join(destinationFolder, file), 'r', encoding='utf-8') as f:
|
||||
contents = f.read()
|
||||
tree = ET.fromstring(contents)
|
||||
|
||||
for entry in tree.iter("Entry"):
|
||||
key = entry.find("JapaneseText").text
|
||||
|
||||
if key in dictionnary:
|
||||
entry.find("EnglishText").text = dictionnary[key]
|
||||
|
||||
if key == entry.find("EnglishText").text:
|
||||
entry.find("Status").text = "Done"
|
||||
else:
|
||||
entry.find("Status").text = "Editing"
|
||||
save = True
|
||||
|
||||
if save:
|
||||
saveTree = ET.ElementTree(tree)
|
||||
saveTree.write(os.path.join(destinationFolder, file), pretty_print=True, xml_declaration=False,
|
||||
encoding="utf-8")
|
||||
def copy_XML_English_Translations(self, current_XML_path, new_XML_path):
|
||||
|
||||
tree = etree.parse(current_XML_path)
|
||||
|
||||
Reference in New Issue
Block a user