mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Add configurable src and dest paths
This commit is contained in:
+16
-12
@@ -349,13 +349,13 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) {
|
||||
for(size_t i = 0; i < externalFiles.size(); i++) {
|
||||
auto externalFile = externalFiles[i];
|
||||
if (externalFile.size() == 0) {
|
||||
this->gCurrentExternalFiles.push_back(externalFile.as<std::string>());
|
||||
this->gCurrentExternalFiles.push_back(this->gSourceDirectory / externalFile.as<std::string>());
|
||||
} else {
|
||||
SPDLOG_INFO("External File size {}", externalFile.size());
|
||||
throw std::runtime_error("Incorrect yaml syntax for external files.\n\nThe yaml expects:\n:config:\n external_files:\n - <external_files>\n\ne.g.:\nexternal_files:\n - actors/actor1.yaml");
|
||||
}
|
||||
|
||||
auto externalFileName = externalFile.as<std::string>();
|
||||
std::string externalFileName = this->gSourceDirectory / externalFile.as<std::string>();
|
||||
if (std::filesystem::relative(externalFileName, this->gAssetPath).string().starts_with("../")) {
|
||||
throw std::runtime_error("External File " + externalFileName + " Not In Asset Directory " + this->gAssetPath);
|
||||
} else if (std::filesystem::relative(externalFileName, this->gAssetPath).string() == "") {
|
||||
@@ -475,7 +475,7 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) {
|
||||
}
|
||||
|
||||
void Companion::ParseHash() {
|
||||
const std::string out = "torch.hash.yml";
|
||||
const std::string out = this->gDestinationPath / "torch.hash.yml";
|
||||
|
||||
if(fs::exists(out)) {
|
||||
this->gHashNode = YAML::LoadFile(out);
|
||||
@@ -983,13 +983,15 @@ void Companion::ProcessFile(YAML::Node root) {
|
||||
|
||||
void Companion::Process() {
|
||||
|
||||
if(!fs::exists("config.yml")) {
|
||||
auto configPath = this->gSourceDirectory / "config.yml";
|
||||
|
||||
if(!fs::exists(configPath)) {
|
||||
SPDLOG_ERROR("No config file found");
|
||||
return;
|
||||
}
|
||||
|
||||
auto start = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
|
||||
YAML::Node config = YAML::LoadFile("config.yml");
|
||||
YAML::Node config = YAML::LoadFile(configPath);
|
||||
|
||||
bool isDirectoryMode = config["mode"] && config["mode"].as<std::string>() == "directory";
|
||||
|
||||
@@ -1067,13 +1069,14 @@ void Companion::Process() {
|
||||
this->gConfig.segment.global[i + 1] = segments[i];
|
||||
}
|
||||
}
|
||||
this->gAssetPath = rom["path"].as<std::string>();
|
||||
this->gAssetPath = this->gSourceDirectory / rom["path"].as<std::string>();
|
||||
auto opath = cfg["output"];
|
||||
auto gbi = cfg["gbi"];
|
||||
auto gbi_floats = cfg["gbi_floats"];
|
||||
auto modding_path = opath && opath["modding"] ? opath["modding"].as<std::string>() : "modding";
|
||||
auto output_path = this->gDestinationPath;
|
||||
|
||||
this->gConfig.moddingPath = modding_path;
|
||||
this->gConfig.moddingPath = this->gSourceDirectory / modding_path;
|
||||
switch (this->gConfig.exporterType) {
|
||||
case ExportType::Binary: {
|
||||
std::string extension = "";
|
||||
@@ -1087,23 +1090,24 @@ void Companion::Process() {
|
||||
default:
|
||||
throw std::runtime_error("Invalid archive type for export type Binary");
|
||||
}
|
||||
this->gConfig.outputPath = opath && opath["binary"] ? opath["binary"].as<std::string>() : ("generic" + extension);
|
||||
output_path /= opath && opath["binary"] ? opath["binary"].as<std::string>() : ("generic" + extension);
|
||||
break;
|
||||
}
|
||||
case ExportType::Header: {
|
||||
this->gConfig.outputPath = opath && opath["headers"] ? opath["headers"].as<std::string>() : "headers";
|
||||
output_path /= opath && opath["headers"] ? opath["headers"].as<std::string>() : "headers";
|
||||
break;
|
||||
}
|
||||
case ExportType::Code: {
|
||||
this->gConfig.outputPath = opath && opath["code"] ? opath["code"].as<std::string>() : "code";
|
||||
output_path /= opath && opath["code"] ? opath["code"].as<std::string>() : "code";
|
||||
break;
|
||||
}
|
||||
case ExportType::XML:
|
||||
case ExportType::Modding: {
|
||||
this->gConfig.outputPath = modding_path;
|
||||
output_path /= modding_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->gConfig.outputPath = output_path;
|
||||
|
||||
if(gbi) {
|
||||
auto key = gbi.as<std::string>();
|
||||
@@ -1273,7 +1277,7 @@ void Companion::Process() {
|
||||
}
|
||||
|
||||
// Write entries hash
|
||||
std::ofstream file("torch.hash.yml", std::ios::binary);
|
||||
std::ofstream file(this->gDestinationPath / "torch.hash.yml", std::ios::binary);
|
||||
file << this->gHashNode;
|
||||
file.close();
|
||||
|
||||
|
||||
+14
-2
@@ -112,7 +112,9 @@ class Companion {
|
||||
public:
|
||||
static Companion* Instance;
|
||||
|
||||
explicit Companion(std::filesystem::path rom, const ArchiveType otr, const bool debug, const bool modding = false) : gCartridge(nullptr) {
|
||||
explicit Companion(std::filesystem::path rom, const ArchiveType otr, const bool debug, const bool modding = false,
|
||||
const std::string& srcDir = "", const std::string& destPath = "") : gCartridge(nullptr),
|
||||
gSourceDirectory(srcDir), gDestinationPath(destPath) {
|
||||
this->gRomPath = rom;
|
||||
this->gConfig.otrMode = otr;
|
||||
this->gConfig.debug = debug;
|
||||
@@ -120,7 +122,9 @@ public:
|
||||
this->gConfig.textureDefines = false;
|
||||
}
|
||||
|
||||
explicit Companion(std::vector<uint8_t> rom, const ArchiveType otr, const bool debug, const bool modding = false) : gCartridge(nullptr) {
|
||||
explicit Companion(std::vector<uint8_t> rom, const ArchiveType otr, const bool debug, const bool modding = false,
|
||||
const std::string& srcDir = "", const std::string& destPath = "") : gCartridge(nullptr),
|
||||
gSourceDirectory(srcDir), gDestinationPath(destPath) {
|
||||
this->gRomData = rom;
|
||||
this->gConfig.otrMode = otr;
|
||||
this->gConfig.debug = debug;
|
||||
@@ -128,6 +132,12 @@ public:
|
||||
this->gConfig.textureDefines = false;
|
||||
}
|
||||
|
||||
explicit Companion(std::filesystem::path rom, const ArchiveType otr, const bool debug, const std::string& srcDir = "", const std::string& destPath = "") :
|
||||
Companion(rom, otr, debug, false, srcDir, destPath) {}
|
||||
|
||||
explicit Companion(std::vector<uint8_t> rom, const ArchiveType otr, const bool debug, const std::string& srcDir = "", const std::string& destPath = "") :
|
||||
Companion(rom, otr, debug, false, srcDir, destPath) {}
|
||||
|
||||
void Init(ExportType type);
|
||||
|
||||
bool NodeHasChanges(const std::string& string);
|
||||
@@ -179,6 +189,8 @@ public:
|
||||
private:
|
||||
TorchConfig gConfig;
|
||||
YAML::Node gModdingConfig;
|
||||
fs::path gSourceDirectory;
|
||||
fs::path gDestinationPath;
|
||||
fs::path gCurrentDirectory;
|
||||
std::string gCurrentHash;
|
||||
std::string gAssetPath;
|
||||
|
||||
+13
-8
@@ -20,9 +20,14 @@ int main(int argc, char *argv[]) {
|
||||
bool otrModeSelected = false;
|
||||
bool xmlMode = false;
|
||||
bool debug = false;
|
||||
std::string srcdir;
|
||||
std::string destdir
|
||||
|
||||
app.require_subcommand();
|
||||
|
||||
app.add_option("-s", "--srcdir", srcdir, "Set source directory to locate config.yml, asset metadata, and modding files for importing");
|
||||
app.add_option("-d", "--destdir", destdir, "Set destination directory for exporting and generating binaries and source code");
|
||||
|
||||
/* Generate an OTR */
|
||||
const auto otr = app.add_subcommand("otr", "OTR - Generates an otr\n");
|
||||
|
||||
@@ -30,7 +35,7 @@ int main(int argc, char *argv[]) {
|
||||
otr->add_flag("-v,--verbose", debug, "Verbose Debug Mode");
|
||||
|
||||
otr->parse_complete_callback([&] {
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::OTR, debug);
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::OTR, debug, srcdir, destdir);
|
||||
instance->Init(ExportType::Binary);
|
||||
});
|
||||
|
||||
@@ -41,7 +46,7 @@ int main(int argc, char *argv[]) {
|
||||
o2r->add_flag("-v,--verbose", debug, "Verbose Debug Mode");
|
||||
|
||||
o2r->parse_complete_callback([&] {
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::O2R, debug);
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::O2R, debug, srcdir, destdir);
|
||||
instance->Init(ExportType::Binary);
|
||||
});
|
||||
|
||||
@@ -52,7 +57,7 @@ int main(int argc, char *argv[]) {
|
||||
code->add_flag("-v,--verbose", debug, "Verbose Debug Mode; adds offsets to C code");
|
||||
|
||||
code->parse_complete_callback([&]() {
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::None, debug);
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::None, debug, srcdir, destdir);
|
||||
instance->Init(ExportType::Code);
|
||||
});
|
||||
|
||||
@@ -62,7 +67,7 @@ int main(int argc, char *argv[]) {
|
||||
binary->add_option("<baserom.z64>", filename, "")->required()->check(CLI::ExistingFile);
|
||||
|
||||
binary->parse_complete_callback([&] {
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::None, debug);
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::None, debug, srcdir, destdir);
|
||||
instance->Init(ExportType::Binary);
|
||||
});
|
||||
|
||||
@@ -80,7 +85,7 @@ int main(int argc, char *argv[]) {
|
||||
otrMode = ArchiveType::None;
|
||||
}
|
||||
|
||||
const auto instance = Companion::Instance = new Companion(filename, otrMode, debug);
|
||||
const auto instance = Companion::Instance = new Companion(filename, otrMode, debug, srcdir, destdir);
|
||||
instance->Init(ExportType::Header);
|
||||
});
|
||||
|
||||
@@ -128,7 +133,7 @@ int main(int argc, char *argv[]) {
|
||||
otrMode = ArchiveType::None;
|
||||
}
|
||||
|
||||
const auto instance = Companion::Instance = new Companion(filename, otrMode, debug, true);
|
||||
const auto instance = Companion::Instance = new Companion(filename, otrMode, debug, true, srcdir, destdir);
|
||||
if (mode == "code") {
|
||||
instance->Init(ExportType::Code);
|
||||
} else if (mode == "otr" || mode == "o2r") {
|
||||
@@ -144,7 +149,7 @@ int main(int argc, char *argv[]) {
|
||||
modding_export->add_option("<baserom.z64>", filename, "")->required()->check(CLI::ExistingFile);
|
||||
|
||||
modding_export->parse_complete_callback([&] {
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::None, debug);
|
||||
const auto instance = Companion::Instance = new Companion(filename, ArchiveType::None, debug, srcdir, destdir);
|
||||
if (xmlMode) {
|
||||
instance->Init(ExportType::XML);
|
||||
} else {
|
||||
@@ -166,4 +171,4 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user