/** * Copyright (c) 2023 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "SceneItemComponentRegister.hpp" using namespace Dawn; void SceneItemComponentRootGen::generate( std::vector *out, std::vector *info, std::string tabs = "" ) { line(out, "#include \"scene/SceneItemComponentList.hpp\"", tabs); line(out, "", tabs); auto it = info->begin(); while(it != info->end()) { auto c = *it; line(out, "#include \"" + c.header + "\"", tabs); ++it; } line(out, "", tabs); line(out, "using namespace Dawn;", tabs); line(out, "", tabs); line(out, "SceneItemComponentList::SceneItemComponentList() {", tabs); it = info->begin(); while(it != info->end()) { auto c = *it; line(out, "this->append<" + c.clazz + ">();", tabs + " "); ++it; } line(out, "}", tabs); } std::vector SceneItemComponentRegister::getRequiredFlags() { return std::vector{ "input", "output" }; } int32_t SceneItemComponentRegister::start() { File fileIn(flags["input"]); if(!fileIn.exists()) { std::cout << "Input scene item component file does not exist." << std::endl; return 1; } std::string buffer; if(!fileIn.readString(&buffer)) { std::cout << "Failed to read input scene item component file" << std::endl; return 1; } std::vector components; struct SceneItemComponent sci; size_t i = 0; std::string t; uint8_t state = 0x00; while(i < buffer.size()) { char c = buffer[i++]; if(c != ';') { t.push_back(c); continue; } switch(state) { case 0x00: sci.clazz = t; t.clear(); state = 0x01; break; case 0x01: sci.header = t; t.clear(); state = 0x00; components.push_back(sci); break; default: assertUnreachable(); } } if(state == 0x01) { sci.header = t; components.push_back(sci); } else { assertUnreachable(); } std::vector lines; SceneItemComponentRootGen::generate(&lines, &components, ""); // Generate buffer std::string bufferOut; auto itLine = lines.begin(); while(itLine != lines.end()) { bufferOut += *itLine + "\n"; ++itLine; } File fileOut(flags["output"]); if(!fileOut.mkdirp()) { std::cout << "Failed to create Scene Item Component List Dir" << std::endl; return 1; } if(!fileOut.writeString(bufferOut)) { std::cout << "Failed to write SceneItemComponentList file" << std::endl; return 1; } return 0; }