jak-project/scripts/subtitle2_gen.py
ManDude 18ddd1613c
Jak 2 pc subtitle support (#2672)
Adds support for adding custom subtitles to Jak 2 audio. Comes with a
new editor for the new system and format. Compared to the Jak 1 system,
this is much simpler to make an editor for.

Comes with a few subtitles already made as an example.
Cutscenes are not officially supported but you can technically subtitle
those with editor, so please don't right now.

This new system supports multiple subtitles playing at once (even from a
single source!) and will smartly push the subtitles up if there's a
message already playing:

![image](https://github.com/open-goal/jak-project/assets/7569514/033e6374-a05a-4c31-b029-51868153a932)

![image](https://github.com/open-goal/jak-project/assets/7569514/5298aa6d-a183-446e-bdb6-61c4682df917)

Unlike in Jak 1, it will not hide the bottom HUD when subtitles are
active:

![image](https://github.com/open-goal/jak-project/assets/7569514/d466bfc0-55d0-4689-a6e1-b7784b9fff59)

Sadly this leaves us with not much space for the subtitle region (and
the subtitles are shrunk when the minimap is enabled) but when you have
guards and citizens talking all the time, hiding the HUD every time
anyone spoke would get really frustrating.

The subtitle speaker is also color-coded now, because I thought that
would be fun to do.

TODO:
- [x] proper cutscene support.
- [x] merge mode for cutscenes so we don't have to rewrite the script?

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
2023-06-08 01:04:16 +01:00

101 lines
2.7 KiB
Python

import json
import argparse
import re
# script to generate dummy subtitle2 JSON entries for a given speaker
# usage: python subtitle2-gen.py <path/to/vag_list> <speaker>
# to get the vag list, run (vag-list-to-file "file-name") in the REPL
# speaker regexes
speakers = {
"computer": "cityv[0-9]{3}$",
"jak": "(jak|jk|jd)[0-9]{3}$",
"darkjak": "",
"daxter": "(ds|dsek|dsbop)[0-9]{3}$",
"samos": "sam[0-9]{3}$",
"keira": "kei[0-9]{3}$",
"keira-before-class-3": "kei[0-9]{3}$",
"kid": "",
"kor": "kor[0-9]{3}$",
"metalkor": "",
"baron": "(bf|bar|prop)[0-9]{3}$",
"errol": "ero[0-9]{3}$",
"torn": "(bb|tor|torn)[0-9]{3}$",
"tess": "(tess|tswm)[0-9]{3}$",
"guard": "kgv?[0-9]{3}$",
"guard-a": "kg[0-9]{3}a",
"guard-b": "kg[0-9]{3}b",
"krew": "(krew|kwbf)[0-9]{3}$",
"sig": "(sigt|sigc)[0-9]{3}$",
"brutter": "bru[0-9]{3}$",
"vin": "vin[0-9]{3}$",
"youngsamos": "ys[0-9]{3}$",
"youngsamos-before-rescue": "",
"pecker": "pek[0-9]{3}$",
"onin": "",
"ashelin": "asha[0-9]{3}$",
"jinx": "hal[0-9]{3}$",
"mog": "hal[0-9]{3}$",
"grim": "hal[0-9]{3}$",
"agent": "agnt[0-9]{3}$",
# there's no clear pattern for what citizen line is male or female, but this seems to be the closest match
"citizen-male": "cit[0-9]{3}(a|b)?$",
"citizen-female": "cit[0-9]{3}(c|d)$",
"oracle": "ora[0-9]{3}$",
"precursor": "",
}
vag_list = []
sub_json = {}
def read_vag_list(file_name):
with open(file_name) as f:
for line in f:
vag_list.append(line.strip())
def gen_json_for_speaker(speaker):
sub = {
"lines": [
{
"end": 10000.0,
"merge": False,
"offscreen": True,
"speaker": speaker,
"start": 0.0,
"text": "TODO",
}
]
}
return sub
def get_vags_for_speaker(speaker):
vags = []
names = speakers[speaker]
if not names:
return []
else:
reg = re.compile(names)
result = list(filter(reg.match, vag_list))
vags.extend(result)
return vags
def main():
parser = argparse.ArgumentParser()
parser.add_argument("vag_list", type=str)
parser.add_argument("speaker", type=str)
args = parser.parse_args()
read_vag_list(args.vag_list)
try:
vags = get_vags_for_speaker(args.speaker)
except KeyError:
print("No vags found for speaker " + args.speaker)
exit(1)
for vag in vags:
sub_json[vag] = (gen_json_for_speaker(args.speaker))
with open (args.speaker + "_subs.json", "w") as f:
json.dump(sub_json, f, indent=2)
if __name__ == "__main__":
main()