mirror of
https://github.com/open-goal/jak-project
synced 2026-05-27 08:09:29 -04:00
c87db7e670
The main thing that was done here was to slightly modify the new subtitle-v2 JSON schema to be more similar to the existing one so that it can properly be used in Crowdin. Draft while I double-check the diff myself Along the way the following was also done (among other things): - got rid of as much duplication as was feasible in the serialization and editor code - separated the text serialization code from the subtitle code for better organization - simplified "base language" in the editor. The new subtitle format has built-in support for defining a base language so the editor doesn't have to be used as a crutch. Also, cutscenes only defined in the base come first in the list now as that is generally the order you'd work from (what you havn't done first) - got rid of the GOAL subtitle format code completely - switched jak 2 text translations to the JSON format as well - found a few mistakes in the jak 1 subtitle metadata files - added a couple minor features to the editor - consolidate and removed complexity, ie. recently all jak 1 hints were forced to the `named` type, so I got rid of the two types as there isn't a need anymore. - removed subtitle editor groups for jak 1, the only reason they existed was so when the GOAL file was manually written out they were somewhat organized, the editor has a decent filter control, there's no need for them. - removed the GOAL -> JSON python script helper, it's been a month or so and no one has come forward with existing translations that they need help with migrating. If they do need it, the script will be in the git history. I did some reasonably through testing in Jak1/Jak 2 and everything seemed to work. But more testing is always a good idea. --------- Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
94 lines
2.8 KiB
C++
94 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <utility>
|
|
|
|
#include "common/goos/Object.h"
|
|
#include "common/log/log.h"
|
|
#include "common/util/Assert.h"
|
|
#include "common/util/FontUtils.h"
|
|
#include "common/util/json_util.h"
|
|
#include "common/versions/versions.h"
|
|
|
|
struct GameTextDefinitionFile {
|
|
enum class Format { GOAL, JSON };
|
|
Format format;
|
|
std::string file_path = "";
|
|
int language_id = -1;
|
|
std::string text_version = "jak1-v2";
|
|
std::optional<std::string> group_name = std::nullopt;
|
|
};
|
|
|
|
/*!
|
|
* The text bank contains all lines (accessed with an ID) for a language.
|
|
*/
|
|
class GameTextBank {
|
|
public:
|
|
GameTextBank(int lang_id) : m_lang_id(lang_id) {}
|
|
|
|
int lang() const { return m_lang_id; }
|
|
const std::map<int, std::string>& lines() const { return m_lines; }
|
|
|
|
bool line_exists(int id) const { return m_lines.find(id) != m_lines.end(); }
|
|
std::string line(int id) { return m_lines.at(id); }
|
|
void set_line(int id, std::string line) { m_lines[id] = line; }
|
|
|
|
private:
|
|
int m_lang_id;
|
|
std::map<int, std::string> m_lines;
|
|
};
|
|
|
|
/*!
|
|
* The text database contains a text bank for each language for each text group.
|
|
* Each text bank contains a list of text lines. Very simple.
|
|
*/
|
|
class GameTextDB {
|
|
public:
|
|
const std::unordered_map<std::string, std::map<int, std::shared_ptr<GameTextBank>>>& groups()
|
|
const {
|
|
return m_banks;
|
|
}
|
|
const std::map<int, std::shared_ptr<GameTextBank>>& banks(std::string group) const {
|
|
return m_banks.at(group);
|
|
}
|
|
|
|
bool bank_exists(std::string group, int id) const {
|
|
if (m_banks.find(group) == m_banks.end())
|
|
return false;
|
|
return m_banks.at(group).find(id) != m_banks.at(group).end();
|
|
}
|
|
|
|
std::shared_ptr<GameTextBank> add_bank(std::string group, std::shared_ptr<GameTextBank> bank) {
|
|
ASSERT(!bank_exists(group, bank->lang()));
|
|
m_banks[group][bank->lang()] = bank;
|
|
return bank;
|
|
}
|
|
std::shared_ptr<GameTextBank> bank_by_id(std::string group, int id) {
|
|
if (!bank_exists(group, id)) {
|
|
return nullptr;
|
|
}
|
|
return m_banks.at(group).at(id);
|
|
}
|
|
|
|
private:
|
|
std::unordered_map<std::string, std::map<int, std::shared_ptr<GameTextBank>>> m_banks;
|
|
};
|
|
|
|
void parse_text_goal(const goos::Object& data,
|
|
GameTextDB& db,
|
|
const GameTextDefinitionFile& /*file_info*/);
|
|
void parse_text_json(const nlohmann::json& json,
|
|
GameTextDB& db,
|
|
const GameTextDefinitionFile& file_info);
|
|
GameTextVersion parse_text_only_version(const std::string& filename);
|
|
GameTextVersion parse_text_only_version(const goos::Object& data);
|
|
|
|
void open_text_project(const std::string& kind,
|
|
const std::string& filename,
|
|
std::vector<GameTextDefinitionFile>& inputs);
|