Moved C++ tools out
This commit is contained in:
69
archive/dawntools/scenetool/SceneTool.cpp
Normal file
69
archive/dawntools/scenetool/SceneTool.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 "SceneTool.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> SceneTool::getRequiredFlags() {
|
||||
return { "input", "output", "sources" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> SceneTool::getOptionalFlags() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t SceneTool::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;
|
||||
}
|
||||
|
||||
auto xml = Xml::load(data);
|
||||
std::string error;
|
||||
|
||||
struct Scene scene;
|
||||
struct SceneItemComponentRegistry registry;
|
||||
registry.sources = File::normalizeSlashes(flags["sources"]);
|
||||
scene.registry = ®istry;
|
||||
auto result = ((SceneParser()).parse(&xml, &scene, &error));
|
||||
if(result != 0) {
|
||||
std::cout << "Failed to parse scene " << input.filename << "::" << error << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generate output
|
||||
std::vector<std::string> outputData;
|
||||
SceneGen::generate(&outputData, &scene, "");
|
||||
|
||||
// Load output file from name and type
|
||||
File outputFile = File(flags["output"] + "/scenes/" + scene.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! " << input.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user