Dawn/archive/uigen/UIGen.cpp
2023-03-14 22:27:46 -07:00

60 lines
1.5 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIGen.hpp"
using namespace Dawn;
std::vector<std::string> UIGen::getRequiredFlags() {
return std::vector<std::string>{ "input", "output" };
}
int32_t UIGen::start() {
std::cout << "UI Gen tool is basically unfinished unfortunately" << std::endl;
return 1;
// Open input file.
File file(flags["input"]);
std::string buffer;
if(!file.readString(&buffer)) {
std::cout << "Failed to read " << file.filename << std::endl;
return 1;
}
// Parse XML
Xml xml = Xml::load(buffer);
std::string error;
struct RootInformation info;
auto ret = (RootParser()).parse(&xml, &info, &error);
if(ret != 0) {
std::cout << error << std::endl;
return ret;
}
std::vector<std::string> lines;
RootGen::generate(&lines, &info, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
// Finished with XML data, now we can write data out.
File fileOut(flags["output"] + ".hpp");
if(!fileOut.mkdirp()) {
std::cout << "Failed to make scene output dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to generate scene " << fileOut.filename << std::endl;
return 1;
}
return 0;
}