Moved C++ tools out
This commit is contained in:
69
archive/dawntools/prefabtool/PrefabTool.cpp
Normal file
69
archive/dawntools/prefabtool/PrefabTool.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "PrefabTool.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> PrefabTool::getRequiredFlags() {
|
||||
return { "input", "output", "sources" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> PrefabTool::getOptionalFlags() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t PrefabTool::start() {
|
||||
File input = File(flags["input"]);
|
||||
if(!input.exists()) {
|
||||
std::cout << "Input file " + input.filename + " does not exist!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string data;
|
||||
if(!input.readString(&data)) {
|
||||
std::cout << "Failed to read input file!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct SceneItemComponentRegistry registry;
|
||||
registry.sources = File::normalizeSlashes(flags["sources"]);
|
||||
|
||||
auto xml = Xml::load(data);
|
||||
std::string error;
|
||||
struct Prefab prefab;
|
||||
prefab.registry = ®istry;
|
||||
auto result = ((PrefabParser()).parse(&xml, &prefab, &error));
|
||||
if(result != 0) {
|
||||
std::cout << "Failed to parse prefab: " << error << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generate output
|
||||
std::vector<std::string> outputData;
|
||||
PrefabGen::generate(&outputData, &prefab, "");
|
||||
|
||||
// Load output file from name and type
|
||||
File outputFile = File(flags["output"] + "/prefabs/" + prefab.type + "/" + prefab.name + ".hpp");
|
||||
if(!outputFile.mkdirp()) {
|
||||
std::cout << "Failed to create output directory!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Combine vector into single string
|
||||
std::string outputDataStr = "";
|
||||
auto it = outputData.begin();
|
||||
while(it != outputData.end()) {
|
||||
outputDataStr += *it + "\n";
|
||||
++it;
|
||||
}
|
||||
|
||||
if(!outputFile.writeString(outputDataStr)) {
|
||||
std::cout << "Failed to write output file!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user