Fmv subs generation

This commit is contained in:
Mc-muffin
2024-12-05 19:54:30 -05:00
parent 6ad3c6d7ad
commit 5985d1d868
3 changed files with 102 additions and 5 deletions

View File

@@ -132,8 +132,16 @@ def get_arguments(argv=None):
sp_insert.add_argument(
"--update-battle-subs",
required=False,
dest="update_subs",
action="store_true",
help="(Optional) - Update Battle Subs header from google sheet",
help="(Deprecated)",
)
sp_insert.add_argument(
"--update-subs",
required=False,
action="store_true",
help="(Optional) - Update Battle and Fmv Subs",
)
sp_insert.add_argument(
@@ -163,7 +171,7 @@ def getTalesInstance(args, game_name):
args.project.resolve(), insert_mask, args.only_changed
)
talesInstance.single_build = args.single_build
talesInstance.make_btl_subs = args.update_battle_subs
talesInstance.make_btl_subs = args.update_subs
elif game_name == "NDX":
talesInstance = ToolsNDX.ToolsNDX("TBL_All.json")
else:
@@ -180,7 +188,8 @@ if __name__ == "__main__":
if args.action == "insert":
if args.update_battle_subs:
if args.update_subs:
tales_instance.create_fmv_subs()
tales_instance.create_btl_subs()
if args.file_type == "Main":

View File

@@ -0,0 +1,67 @@
from pathlib import Path
from .. import srt
from .text_util import text_to_cstr, indent_lines
def subs_to_lines(subs: list[srt.SrtSub], name: str) -> list[str]:
content = list()
inner_content = list()
content.append(f"const fmv_sub fmv_{name}[{len(subs) * 2}] = {{")
for sub in subs:
start = sub.start
start_text = f"TS_TO_FRAMES({start.minutes}, {start.seconds}, {start.milis})"
ts_end = sub.end
end_text = f"TS_TO_FRAMES({ts_end.minutes}, {ts_end.seconds}, {ts_end.milis})"
text = text_to_cstr(sub.content.replace('"', '\\"'))
inner_content.append("{")
inner_content.append(f" {start_text},")
inner_content.extend(indent_lines(text.split("\n"), 1))
inner_content.append("},")
inner_content.append("{")
inner_content.append(f" {end_text},")
inner_content.append(" (char*)NULL")
inner_content.append("},")
inner_content[-1] = inner_content[-1][:-1] # remove trailing comma
content.extend(indent_lines(inner_content, 1))
content.append("};")
return content
def generate_header_lines(files: list[Path]) -> list[str]:
file_subs = list()
for file in files:
file_subs.append((file.stem, srt.get_subs(file)))
# Start creating the header file content
hdr = [
"/* This file is autogenerated*/",
"#ifndef __FMV_SUBS_H__",
"#define __FMV_SUBS_H__",
"",
'#include "types.h"',
'#include "fmv_subs.h"',
'#include "rebirth_text.h"',
"",
]
for name, subs in file_subs:
hdr.extend(subs_to_lines(subs, name))
hdr.append("")
hdr.append(f"const fmv_entry fmv_table[{len(file_subs)}] = {{")
for name, subs in file_subs:
hdr.append(" {")
hdr.append(f" ARRAY_COUNT(fmv_{name}),")
hdr.append(f" fmv_{name}")
hdr.append(" },")
hdr[-1] = hdr[-1][:-1] # remove trailing comma
hdr.append("};")
hdr.append("")
hdr.append("#endif /* __FMV_SUBS_H__ */")
hdr.append("")
return hdr

View File

@@ -17,6 +17,7 @@ import pyjson5 as json
from tqdm import tqdm
import pythonlib.formats.rebirth.btlsub_to_hdr as btl_maker
import pythonlib.formats.rebirth.fmv_to_hdr as fmv_maker
import pythonlib.formats.rebirth.pak2 as pak2lib
import pythonlib.utils.comptolib as comptolib
from pythonlib.formats.FileIO import FileIO
@@ -120,6 +121,23 @@ class ToolsTOR(ToolsTales):
print("Done!")
def create_fmv_subs(self):
if not self.make_btl_subs:
return
print("Updating FMV sub data...")
srt_path = self.paths["translated_files"] / "fmv"
srts = list(srt_path.glob("*.srt"))
lines = fmv_maker.generate_header_lines(srts)
h_file = self.paths["tools"] / "hacks/src/fmv_subs_text.h"
with h_file.open("w", encoding="utf8") as f:
f.write("\n".join(lines))
print("Done!")
def get_build_name(self) -> str:
if self.single_build:
return "TalesOfRebirth_latest"
@@ -447,8 +465,11 @@ class ToolsTOR(ToolsTales):
return finalText
def read_xml(self, xml_path: Path) -> etree._Element:
with xml_path.open("r", encoding='utf-8') as xml_file:
xml_str = xml_file.read().replace("<EnglishText></EnglishText>", "<EnglishText empty=\"true\"></EnglishText>")
try:
with xml_path.open("r", encoding='utf-8') as xml_file:
xml_str = xml_file.read().replace("<EnglishText></EnglishText>", "<EnglishText empty=\"true\"></EnglishText>")
except FileNotFoundError:
xml_str = "<SceneText></SceneText>"
root = etree.fromstring(xml_str, parser=etree.XMLParser(recover=True))
return root