Skip to content

Commit

Permalink
fix pt-BR subtitles to match english timings, there is no portuguese …
Browse files Browse the repository at this point in the history
…audio
  • Loading branch information
xTVaser committed May 14, 2023
1 parent 0a6d07e commit fcdfc1d
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 152 deletions.
65 changes: 42 additions & 23 deletions common/serialization/subtitles/subtitles_ser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,28 +399,28 @@ void parse_subtitle_json(GameSubtitleDB& db, const GameSubtitleDefinitionFile& f
auto base_data =
parse_commented_json(file_util::read_text_file(file_util::get_jak_project_dir() /
file_info.meta_base_path.value()),
"TODO");
"subtitle_meta_base_path");
auto data = parse_commented_json(
file_util::read_text_file(file_util::get_jak_project_dir() / file_info.meta_path),
"TODO");
"subtitle_meta_path");
base_data.at("cutscenes").update(data.at("cutscenes"));
base_data.at("hints").update(data.at("hints"));
meta_file = base_data;

} else {
meta_file = parse_commented_json(
file_util::read_text_file(file_util::get_jak_project_dir() / file_info.meta_path),
"TODO");
"subtitle_meta_path");
}
if (file_info.lines_base_path) {
auto base_data =
parse_commented_json(file_util::read_text_file(file_util::get_jak_project_dir() /
file_info.lines_base_path.value()),
"TODO");
"subtitle_line_base_path");

auto data = parse_commented_json(
file_util::read_text_file(file_util::get_jak_project_dir() / file_info.lines_path),
"TODO");
"subtitle_line_path");
base_data.at("cutscenes").update(data.at("cutscenes"));
base_data.at("hints").update(data.at("hints"));
base_data.at("speakers").update(data.at("speakers"));
Expand All @@ -429,26 +429,34 @@ void parse_subtitle_json(GameSubtitleDB& db, const GameSubtitleDefinitionFile& f
} else {
lines_file = parse_commented_json(
file_util::read_text_file(file_util::get_jak_project_dir() / file_info.lines_path),
"TODO");
"subtitle_line_path");
}
} catch (std::exception& e) {
// TODO - a decent error
lg::error("Unable to parse subtitle json entry, couldn't successfully load files - {}",
e.what());
throw;
}
// Iterate through the metadata file as blank lines are no omitted from the lines file now
// Cutscenes First
for (const auto& [cutscene_name, cutscene_lines] : meta_file.cutscenes) {
lg::info(cutscene_name);
GameSubtitleSceneInfo scene(SubtitleSceneKind::Movie);
scene.set_name(cutscene_name);
/*scene.m_sorting_group = db.m_subtitle_groups->find_group(cutscene_name);
scene.m_sorting_group_idx = db.m_subtitle_groups->find_group_index(scene.m_sorting_group);*/
// Iterate the lines, grab the actual text from the lines file if it's not a clear screen entry
int line_idx = 0;
for (const auto& line : cutscene_lines) {
if (line.clear) {
scene.add_clear_entry(line.frame);
} else {
// TODO - assumptions going on here
if (lines_file.cutscenes.find(cutscene_name) == lines_file.cutscenes.end() ||
if (lines_file.speakers.find(line.speaker) == lines_file.speakers.end() ||
lines_file.cutscenes.find(cutscene_name) == lines_file.cutscenes.end() ||
lines_file.cutscenes.at(cutscene_name).size() < line_idx) {
lg::warn("Couldn't find {} in line file, or line list is too small!", cutscene_name);
lg::warn(
"{} Couldn't find {} in line file, or line list is too small, or speaker could not "
"be resolved {}!",
file_info.language_id, cutscene_name, line.speaker);
} else {
scene.add_line(
line.frame,
Expand All @@ -468,8 +476,11 @@ void parse_subtitle_json(GameSubtitleDB& db, const GameSubtitleDefinitionFile& f
}
// Now hints
for (const auto& [hint_name, hint_info] : meta_file.hints) {
lg::info(hint_name);
GameSubtitleSceneInfo scene(SubtitleSceneKind::Hint);
scene.set_name(hint_name);
/*scene.m_sorting_group = db.m_subtitle_groups->find_group(hint_name);
scene.m_sorting_group_idx = db.m_subtitle_groups->find_group_index(scene.m_sorting_group);*/
if (hint_info.id == "0") {
scene.m_kind = SubtitleSceneKind::HintNamed;
} else {
Expand All @@ -481,10 +492,18 @@ void parse_subtitle_json(GameSubtitleDB& db, const GameSubtitleDefinitionFile& f
if (line.clear) {
scene.add_clear_entry(line.frame);
} else {
// TODO - assumptions going on here
scene.add_line(line.frame,
font->convert_utf8_to_game(lines_file.hints.at(hint_name).at(line_idx)),
font->convert_utf8_to_game(lines_file.speakers.at(line.speaker)), true);
if (lines_file.speakers.find(line.speaker) == lines_file.speakers.end() ||
lines_file.hints.find(hint_name) == lines_file.hints.end() ||
lines_file.hints.at(hint_name).size() < line_idx) {
lg::warn(
"{} Couldn't find {} in line file, or line list is too small, or speaker could not "
"be resolved {}!",
file_info.language_id, hint_name, line.speaker);
} else {
scene.add_line(line.frame,
font->convert_utf8_to_game(lines_file.hints.at(hint_name).at(line_idx)),
font->convert_utf8_to_game(lines_file.speakers.at(line.speaker)), true);
}
line_idx++;
}
}
Expand Down Expand Up @@ -886,17 +905,18 @@ GameSubtitleDB load_subtitle_project(GameVersion game_version) {
db.m_subtitle_groups->hydrate_from_asset_file();
try {
goos::Reader reader;
std::vector<GameTextDefinitionFile> files;
std::vector<GameSubtitleDefinitionFile> files;
std::string subtitle_project = (file_util::get_jak_project_dir() / "game" / "assets" /
version_to_game_name(game_version) / "game_subtitle.gp")
.string();
open_text_project("subtitle", subtitle_project, files);
open_subtitle_project("subtitle", subtitle_project, files);
for (auto& file : files) {
if (file.format != GameTextDefinitionFile::Format::GOAL) {
continue; // non-GOAL formats are not supported for subtitles
if (file.format == GameSubtitleDefinitionFile::Format::GOAL) {
auto code = reader.read_from_file({file.lines_path});
parse_subtitle(code, db, file.lines_path);
} else if (file.format == GameSubtitleDefinitionFile::Format::JSON) {
parse_subtitle_json(db, file);
}
auto code = reader.read_from_file({file.file_path});
parse_subtitle(code, db, file.file_path);
}
} catch (std::runtime_error& e) {
lg::error("error loading subtitle project: {}", e.what());
Expand All @@ -915,7 +935,8 @@ GameSubtitleDB load_subtitle_project(GameVersion game_version) {

// std::vector<std::string> locale_lookup = {"en-US", "fr-FR", "de-DE", "es-ES", "it-IT",
// "jp-JP", "en-GB", "pt-PT", "fi-FI", "sv-SE",
// "da-DK", "no-NO", "nl-NL", "pt-BR", "hu-HU"};
// "da-DK", "no-NO", "nl-NL", "pt-BR", "hu-HU", "ca-ES",
// "is-IS"};

// for (const auto& [language_id, bank] : db.m_banks) {
// auto meta_file =
Expand Down Expand Up @@ -951,5 +972,3 @@ GameSubtitleDB load_subtitle_project(GameVersion game_version) {

return db;
}

// TODO - write a deserializer, the compiler still can do the compiling!
2 changes: 1 addition & 1 deletion game/assets/jak1/game_subtitle.gp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
:lines "game/assets/jak1/subtitle/subtitle_lines_pt-BR.json"
:lines-base "game/assets/jak1/subtitle/subtitle_lines_en-US.json"
:meta "game/assets/jak1/subtitle/subtitle_meta_pt-BR.json"
:meta-base "game/assets/jak1/subtitle/subtitle_meta_en-ES.json") ;; Timings for pt-BR seem to be copied from es-ES
:meta-base "game/assets/jak1/subtitle/subtitle_meta_en-US.json")
(file-json
:language-id 14
:text-version "jak1-v2"
Expand Down
88 changes: 88 additions & 0 deletions game/assets/jak1/subtitle/cleanup-subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,91 @@ def clean_lines(lines):
# Lines get copied after because we actually don't want duplication to be removed (it needs to be translated!)
for locale in locales:
shutil.copy("./subtitle_lines_en-US.json", "./subtitle_lines_" + locale + ".json")

# Special case for portuguese brazilian
# it was done based off the spanish timings, but there is no portuguese audio
# so manually find the cutscenes that don't match so they can be adjusted...manually...
with open("./subtitle_lines_pt-BR.json", "r", encoding="utf-8") as f:
port_lines = json.load(f)

for cutscene_name, cutscene_lines in port_lines["cutscenes"].items():
if len(cutscene_lines) != len(english_lines["cutscenes"][cutscene_name]):
print(cutscene_name)
for hint_name, hint_lines in port_lines["hints"].items():
if len(hint_lines) != len(english_lines["hints"][hint_name]):
print(hint_name)

# assistant-lavatube-end-resolution
# assistant-reminder-1-generic
# billy-accept
# billy-introduction
# billy-reject
# billy-resolution
# bird-lady-beach-resolution
# bird-lady-introduction
# bird-lady-reminder-2
# bluesage-resolution
# explorer-introduction
# explorer-resolution
# farmer-introduction
# farmer-reminder-1
# fisher-accept
# fisher-introduction
# fisher-reject
# fisher-resolution
# green-sagecage-daxter-sacrifice
# green-sagecage-introduction
# green-sagecage-outro-beat-boss-b
# green-sagecage-outro-preboss
# green-sagecage-resolution
# oracle-intro-1
# oracle-intro-2
# oracle-intro-3
# oracle-reminder-1
# oracle-reminder-2
# oracle-reminder-3
# redsage-resolution
# sage-intro-sequence-a
# sage-intro-sequence-d1
# sage-intro-sequence-d2
# sage-intro-sequence-e
# sage-village3-introduction
# sage-village3-introduction-dark-eco
# yellowsage-resolution
# ASSTLP24
# ASSTLP36
# CHI-AM03
# CHI-AM04
# EXP-AM01
# EXP-AM05
# FAR-AM01
# FIS-AM01
# FIS-AM02
# MSH-AM12
# SAGELP05
# asstv100
# asstv101
# asstva73
# asstvb02
# asstvb04
# asstvb08
# asstvb21
# asstvb23
# asstvb24
# asstvb25
# asstvb45
# asstvb47
# sagevb01
# sagevb02
# sagevb03
# sagevb23
# sagevb24
# sagevb25
# sksp0013
# sksp0017
# sksp0059
# sksp0060
# sksp0067
# sksp0116
# sksp0145
# sksp0b42
6 changes: 2 additions & 4 deletions game/assets/jak1/subtitle/subtitle-groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@
"sksp0072",
"sksp0073",
"sksp0435",
"fishermans-boat-ride-to-village1-alt"
"fishermans-boat-ride-to-village1-alt",
"evilbro-misty-end"
],
"ogre": [
"asstvb23",
Expand Down Expand Up @@ -539,9 +540,6 @@
"sagevb38",
"sagevb39"
],
"uncategorized": [
"evilbro-misty-end"
],
"village1": [
"ASSTLP01",
"ASSTLP02",
Expand Down

0 comments on commit fcdfc1d

Please sign in to comment.