You've already forked PythonLib
mirror of
https://github.com/lifebottle/PythonLib.git
synced 2026-02-13 15:25:50 -08:00
Fmv subs generation
This commit is contained in:
67
pythonlib/formats/rebirth/fmv_to_hdr.py
Normal file
67
pythonlib/formats/rebirth/fmv_to_hdr.py
Normal 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
|
||||
Reference in New Issue
Block a user