XML structured much better
This commit is contained in:
@ -1,36 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
project(sceneitemcomponentgen VERSION 1.0)
|
||||
add_executable(sceneitemcomponentgen)
|
||||
|
||||
# Sources
|
||||
target_sources(sceneitemcomponentgen
|
||||
PRIVATE
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
SceneItemComponentRegister.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(sceneitemcomponentgen
|
||||
PUBLIC
|
||||
${DAWN_SHARED_INCLUDES}
|
||||
${DAWN_TOOL_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Definitions
|
||||
target_compile_definitions(sceneitemcomponentgen
|
||||
PUBLIC
|
||||
DAWN_TOOL_INSTANCE=SceneItemComponentRegister
|
||||
DAWN_TOOL_HEADER="SceneItemComponentRegister.hpp"
|
||||
)
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(sceneitemcomponentgen
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
@ -1,119 +0,0 @@
|
||||
/**
|
||||
* 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<std::string> *out,
|
||||
std::vector<struct SceneItemComponent> *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<std::string> SceneItemComponentRegister::getRequiredFlags() {
|
||||
return std::vector<std::string>{ "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<struct SceneItemComponent> 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<std::string> 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;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/File.hpp"
|
||||
#include "util/CodeGen.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct SceneItemComponent {
|
||||
std::string clazz;
|
||||
std::string header;
|
||||
};
|
||||
|
||||
class SceneItemComponentRootGen : public CodeGen {
|
||||
public:
|
||||
static void generate(
|
||||
std::vector<std::string> *out,
|
||||
std::vector<struct SceneItemComponent> *info,
|
||||
std::string tabs
|
||||
);
|
||||
};
|
||||
|
||||
class SceneItemComponentRegister : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user