2021-07-15 21:37:15 -04:00
|
|
|
#include "Tools.h"
|
|
|
|
|
|
|
|
#include "common/goos/ParseHelpers.h"
|
|
|
|
#include "common/util/DgoWriter.h"
|
|
|
|
#include "common/util/FileUtil.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
|
2023-10-21 00:07:43 -04:00
|
|
|
#include "goalc/build_level/jak1/build_level.h"
|
|
|
|
#include "goalc/build_level/jak2/build_level.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
#include "goalc/compiler/Compiler.h"
|
2021-07-15 21:37:15 -04:00
|
|
|
#include "goalc/data_compiler/dir_tpages.h"
|
|
|
|
#include "goalc/data_compiler/game_count.h"
|
2022-04-24 15:15:16 -04:00
|
|
|
#include "goalc/data_compiler/game_text_common.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
|
|
|
|
#include "third-party/fmt/core.h"
|
2021-07-15 21:37:15 -04:00
|
|
|
|
|
|
|
CompilerTool::CompilerTool(Compiler* compiler) : Tool("goalc"), m_compiler(compiler) {}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool CompilerTool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
|
|
|
|
2022-07-05 20:38:13 -04:00
|
|
|
if (!m_compiler->knows_object_file(fs::path(task.input.at(0)).stem().u8string())) {
|
2021-07-15 21:37:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
2022-06-29 23:32:46 -04:00
|
|
|
return Tool::needs_run(task, path_map);
|
2021-07-15 21:37:15 -04:00
|
|
|
}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool CompilerTool::run(const ToolInput& task, const PathMap& /*path_map*/) {
|
2021-07-15 21:37:15 -04:00
|
|
|
// todo check inputs
|
|
|
|
try {
|
2022-06-24 18:21:24 -04:00
|
|
|
CompilationOptions options;
|
|
|
|
options.filename = task.input.at(0);
|
|
|
|
options.color = true;
|
|
|
|
options.write = true;
|
|
|
|
m_compiler->asm_file(options);
|
2021-07-15 21:37:15 -04:00
|
|
|
} catch (std::exception& e) {
|
2022-10-01 11:58:36 -04:00
|
|
|
lg::print("Compilation failed: {}\n", e.what());
|
2021-07-15 21:37:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
DgoDescription parse_desc_file(const std::string& filename, goos::Reader& reader) {
|
2022-02-19 13:10:10 -05:00
|
|
|
auto& dgo_desc = reader.read_from_file({filename}).as_pair()->cdr;
|
2021-07-15 21:37:15 -04:00
|
|
|
if (goos::list_length(dgo_desc) != 1) {
|
|
|
|
throw std::runtime_error("Invalid DGO description - got too many lists");
|
|
|
|
}
|
2022-02-19 13:10:10 -05:00
|
|
|
auto& dgo = dgo_desc.as_pair()->car;
|
2021-07-15 21:37:15 -04:00
|
|
|
|
|
|
|
DgoDescription desc;
|
2022-02-19 13:10:10 -05:00
|
|
|
auto& first = dgo.as_pair()->car;
|
2021-07-15 21:37:15 -04:00
|
|
|
desc.dgo_name = first.as_string()->data;
|
2023-02-13 16:39:14 -05:00
|
|
|
auto& dgo_rest = dgo.as_pair()->cdr.as_pair()->car;
|
2021-07-15 21:37:15 -04:00
|
|
|
|
|
|
|
for_each_in_list(dgo_rest, [&](const goos::Object& entry) {
|
2023-02-13 16:39:14 -05:00
|
|
|
if (!entry.is_string()) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid file name for DGO: {}\n", entry.print()));
|
2021-07-15 21:37:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DgoDescription::DgoEntry o;
|
2023-02-13 16:39:14 -05:00
|
|
|
const auto& file_name = entry.as_string()->data;
|
|
|
|
// automatically deduce dgo name
|
|
|
|
// (not really a fan of how this is written...)
|
|
|
|
if (file_name.length() > 2 && file_name.substr(file_name.length() - 2, 2) == ".o") {
|
|
|
|
// ends with .o so it's a code file
|
|
|
|
o.name_in_dgo = file_name.substr(0, file_name.length() - 2);
|
|
|
|
} else if (file_name.length() > 6 && file_name.substr(file_name.length() - 6, 6) == "-ag.go") {
|
|
|
|
// ends with -ag.go so it's an art group file
|
|
|
|
o.name_in_dgo = file_name.substr(0, file_name.length() - 6);
|
|
|
|
} else if (file_name.length() > 3 && file_name.substr(file_name.length() - 3, 3) == ".go") {
|
|
|
|
// ends with .go so it's a generic data file
|
|
|
|
o.name_in_dgo = file_name.substr(0, file_name.length() - 3);
|
|
|
|
}
|
|
|
|
o.file_name = file_name;
|
2021-07-15 21:37:15 -04:00
|
|
|
desc.entries.push_back(o);
|
|
|
|
});
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
DgoTool::DgoTool() : Tool("dgo") {}
|
|
|
|
|
2022-06-30 21:11:58 -04:00
|
|
|
bool DgoTool::run(const ToolInput& task, const PathMap& path_map) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
|
|
|
auto desc = parse_desc_file(task.input.at(0), m_reader);
|
2022-06-30 21:11:58 -04:00
|
|
|
build_dgo(desc, path_map.output_prefix);
|
2021-07-15 21:37:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
std::vector<std::string> DgoTool::get_additional_dependencies(const ToolInput& task,
|
2022-06-30 21:11:58 -04:00
|
|
|
const PathMap& path_map) {
|
2021-07-15 21:37:15 -04:00
|
|
|
std::vector<std::string> result;
|
2022-02-19 13:10:10 -05:00
|
|
|
auto desc = parse_desc_file(task.input.at(0), m_reader);
|
2021-07-15 21:37:15 -04:00
|
|
|
for (auto& x : desc.entries) {
|
2022-06-29 23:32:46 -04:00
|
|
|
// todo out
|
2022-06-30 21:11:58 -04:00
|
|
|
result.push_back(fmt::format("out/{}obj/{}", path_map.output_prefix, x.file_name));
|
2021-07-15 21:37:15 -04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
TpageDirTool::TpageDirTool() : Tool("tpage-dir") {}
|
|
|
|
|
2022-06-30 21:11:58 -04:00
|
|
|
bool TpageDirTool::run(const ToolInput& task, const PathMap& path_map) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2022-06-30 21:11:58 -04:00
|
|
|
compile_dir_tpages(task.input.at(0), path_map.output_prefix);
|
2021-07-15 21:37:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyTool::CopyTool() : Tool("copy") {}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool CopyTool::run(const ToolInput& task, const PathMap& /*path_map*/) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2021-07-15 21:37:15 -04:00
|
|
|
for (auto& out : task.output) {
|
2022-07-05 20:38:13 -04:00
|
|
|
fs::copy(fs::path(file_util::get_file_path({task.input.at(0)})),
|
|
|
|
fs::path(file_util::get_file_path({out})), fs::copy_options::overwrite_existing);
|
2021-07-15 21:37:15 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameCntTool::GameCntTool() : Tool("game-cnt") {}
|
|
|
|
|
2022-06-30 21:11:58 -04:00
|
|
|
bool GameCntTool::run(const ToolInput& task, const PathMap& path_map) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2022-06-30 21:11:58 -04:00
|
|
|
compile_game_count(task.input.at(0), path_map.output_prefix);
|
2021-07-15 21:37:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextTool::TextTool() : Tool("text") {}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool TextTool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2022-04-11 18:38:54 -04:00
|
|
|
|
|
|
|
std::vector<std::string> deps;
|
2023-04-30 17:22:56 -04:00
|
|
|
std::vector<GameTextDefinitionFile> files;
|
|
|
|
open_text_project("text", task.input.at(0), files);
|
|
|
|
for (auto& file : files) {
|
|
|
|
deps.push_back(path_map.apply_remaps(file.file_path));
|
2022-06-29 23:32:46 -04:00
|
|
|
}
|
|
|
|
return Tool::needs_run({task.input, deps, task.output, task.arg}, path_map);
|
2022-04-11 18:38:54 -04:00
|
|
|
}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool TextTool::run(const ToolInput& task, const PathMap& path_map) {
|
2022-04-24 15:15:16 -04:00
|
|
|
GameTextDB db;
|
2023-04-30 17:22:56 -04:00
|
|
|
std::vector<GameTextDefinitionFile> files;
|
|
|
|
open_text_project("text", task.input.at(0), files);
|
|
|
|
for (auto& file : files) {
|
|
|
|
file.file_path = path_map.apply_remaps(file.file_path);
|
2022-06-29 23:32:46 -04:00
|
|
|
}
|
2023-04-30 17:22:56 -04:00
|
|
|
compile_game_text(files, db, path_map.output_prefix);
|
2021-07-15 21:37:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupTool::GroupTool() : Tool("group") {}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool GroupTool::run(const ToolInput&, const PathMap& /*path_map*/) {
|
2021-07-15 21:37:15 -04:00
|
|
|
return true;
|
2022-02-19 13:10:10 -05:00
|
|
|
}
|
|
|
|
|
2023-07-08 21:53:39 -04:00
|
|
|
void enumerate_subtitle_project_files(const std::string& tool_name,
|
|
|
|
const std::string& file_path,
|
|
|
|
const PathMap& path_map,
|
|
|
|
std::vector<GameSubtitleDefinitionFile>& files,
|
|
|
|
std::vector<std::string>& deps) {
|
|
|
|
open_subtitle_project(tool_name, file_path, files);
|
|
|
|
for (auto& file : files) {
|
|
|
|
deps.push_back(path_map.apply_remaps(file.lines_path));
|
|
|
|
deps.push_back(path_map.apply_remaps(file.meta_path));
|
|
|
|
if (file.lines_base_path) {
|
|
|
|
deps.push_back(path_map.apply_remaps(file.lines_base_path.value()));
|
|
|
|
}
|
|
|
|
if (file.meta_base_path) {
|
|
|
|
deps.push_back(path_map.apply_remaps(file.meta_base_path.value()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_subtitle_project_files(const std::string& tool_name,
|
|
|
|
const std::string& file_path,
|
|
|
|
const PathMap& path_map,
|
|
|
|
std::vector<GameSubtitleDefinitionFile>& files) {
|
|
|
|
open_subtitle_project(tool_name, file_path, files);
|
|
|
|
for (auto& file : files) {
|
|
|
|
file.lines_path = path_map.apply_remaps(file.lines_path);
|
|
|
|
file.meta_path = path_map.apply_remaps(file.meta_path);
|
|
|
|
if (file.lines_base_path) {
|
|
|
|
file.lines_base_path = path_map.apply_remaps(file.lines_base_path.value());
|
|
|
|
}
|
|
|
|
if (file.meta_base_path) {
|
|
|
|
file.meta_base_path = path_map.apply_remaps(file.meta_base_path.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 18:38:54 -04:00
|
|
|
SubtitleTool::SubtitleTool() : Tool("subtitle") {}
|
2022-02-19 13:10:10 -05:00
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool SubtitleTool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
2022-02-19 13:10:10 -05:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2023-05-18 20:54:59 -04:00
|
|
|
std::vector<GameSubtitleDefinitionFile> files;
|
2023-07-08 21:53:39 -04:00
|
|
|
std::vector<std::string> deps;
|
|
|
|
enumerate_subtitle_project_files(name(), task.input.at(0), path_map, files, deps);
|
2022-06-29 23:32:46 -04:00
|
|
|
return Tool::needs_run({task.input, deps, task.output, task.arg}, path_map);
|
2022-02-19 13:10:10 -05:00
|
|
|
}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool SubtitleTool::run(const ToolInput& task, const PathMap& path_map) {
|
2022-04-24 15:15:16 -04:00
|
|
|
GameSubtitleDB db;
|
2023-07-08 21:53:39 -04:00
|
|
|
db.m_subtitle_version = GameSubtitleDB::SubtitleFormat::V1;
|
2023-05-18 20:54:59 -04:00
|
|
|
std::vector<GameSubtitleDefinitionFile> files;
|
2023-07-08 21:53:39 -04:00
|
|
|
run_subtitle_project_files(name(), task.input.at(0), path_map, files);
|
|
|
|
compile_game_subtitles(files, db, path_map.output_prefix);
|
2022-02-19 13:10:10 -05:00
|
|
|
return true;
|
|
|
|
}
|
2022-06-19 20:44:07 -04:00
|
|
|
|
2023-07-08 21:53:39 -04:00
|
|
|
SubtitleV2Tool::SubtitleV2Tool() : Tool("subtitle-v2") {}
|
2023-06-07 20:04:16 -04:00
|
|
|
|
2023-07-08 21:53:39 -04:00
|
|
|
bool SubtitleV2Tool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
2023-06-07 20:04:16 -04:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2023-07-08 21:53:39 -04:00
|
|
|
std::vector<GameSubtitleDefinitionFile> files;
|
2023-06-07 20:04:16 -04:00
|
|
|
std::vector<std::string> deps;
|
2023-07-08 21:53:39 -04:00
|
|
|
enumerate_subtitle_project_files(name(), task.input.at(0), path_map, files, deps);
|
2023-06-07 20:04:16 -04:00
|
|
|
return Tool::needs_run({task.input, deps, task.output, task.arg}, path_map);
|
|
|
|
}
|
|
|
|
|
2023-07-08 21:53:39 -04:00
|
|
|
bool SubtitleV2Tool::run(const ToolInput& task, const PathMap& path_map) {
|
|
|
|
GameSubtitleDB db;
|
|
|
|
db.m_subtitle_version = GameSubtitleDB::SubtitleFormat::V2;
|
|
|
|
std::vector<GameSubtitleDefinitionFile> files;
|
|
|
|
run_subtitle_project_files(name(), task.input.at(0), path_map, files);
|
|
|
|
compile_game_subtitles(files, db, path_map.output_prefix);
|
2023-06-07 20:04:16 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-19 20:44:07 -04:00
|
|
|
BuildLevelTool::BuildLevelTool() : Tool("build-level") {}
|
|
|
|
|
2022-06-29 23:32:46 -04:00
|
|
|
bool BuildLevelTool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
2022-06-19 20:44:07 -04:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
|
|
|
auto deps = get_build_level_deps(task.input.at(0));
|
2022-06-29 23:32:46 -04:00
|
|
|
return Tool::needs_run({task.input, deps, task.output, task.arg}, path_map);
|
2022-06-19 20:44:07 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 21:11:58 -04:00
|
|
|
bool BuildLevelTool::run(const ToolInput& task, const PathMap& path_map) {
|
2022-06-19 20:44:07 -04:00
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
2023-10-21 00:07:43 -04:00
|
|
|
return jak1::run_build_level(task.input.at(0), task.output.at(0), path_map.output_prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildLevel2Tool::BuildLevel2Tool() : Tool("build-level2") {}
|
|
|
|
|
|
|
|
bool BuildLevel2Tool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
|
|
|
auto deps = get_build_level_deps(task.input.at(0));
|
|
|
|
return Tool::needs_run({task.input, deps, task.output, task.arg}, path_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BuildLevel2Tool::run(const ToolInput& task, const PathMap& path_map) {
|
|
|
|
if (task.input.size() != 1) {
|
|
|
|
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
|
|
|
|
}
|
|
|
|
return jak2::run_build_level(task.input.at(0), task.output.at(0), path_map.output_prefix);
|
2022-06-19 20:44:07 -04:00
|
|
|
}
|