83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "parse/elements/children.hpp"
|
|
|
|
namespace Dawn {
|
|
struct RootInformation {
|
|
std::vector<std::string> includes;
|
|
struct ChildrenInfo children;
|
|
};
|
|
|
|
class RootParser : public XmlParser<struct RootInformation> {
|
|
protected:
|
|
std::vector<std::string> getRequiredAttributes() {
|
|
return std::vector<std::string>();
|
|
}
|
|
|
|
std::map<std::string, std::string> getOptionalAttributes() {
|
|
return std::map<std::string, std::string>();
|
|
}
|
|
|
|
int32_t onParse(
|
|
Xml *node,
|
|
std::map<std::string, std::string> values,
|
|
struct RootInformation *out,
|
|
std::string *error
|
|
) {
|
|
int32_t ret;
|
|
if(node->node != "root") {
|
|
*error = "Root node is of an invalid type";
|
|
return 1;
|
|
}
|
|
|
|
ret = (ChildrenParser()).parse(node, &out->children, error);
|
|
if(ret != 0) return ret;
|
|
|
|
return ret;
|
|
}
|
|
};
|
|
|
|
class RootGen : public CodeGen {
|
|
public:
|
|
static void generate(
|
|
std::vector<std::string> *out,
|
|
struct RootInformation *info,
|
|
std::string tabs = ""
|
|
) {
|
|
struct ClassGenInfo clazz;
|
|
clazz.clazz = "SimpleTestUI";
|
|
clazz.extend = "SceneItemPrefab<" + clazz.clazz + ">";
|
|
clazz.constructorArgs = "Scene *s, sceneitemid_t i";
|
|
clazz.extendArgs = "s, i";
|
|
clazz.includes.push_back("#include \"prefab/SceneItemPrefab.hpp\"");
|
|
|
|
// Assets
|
|
struct MethodGenInfo assetsInfo;
|
|
assetsInfo.name = "prefabAssets";
|
|
assetsInfo.isStatic = true;
|
|
assetsInfo.type = "std::vector<Asset*>";
|
|
assetsInfo.args = "AssetManager *ass";
|
|
line(&assetsInfo.body, "return {", "");
|
|
|
|
line(&assetsInfo.body, "};", "");
|
|
methodGen(&clazz.publicCode, assetsInfo);
|
|
|
|
line(&clazz.publicCode, "", "");
|
|
|
|
// Init
|
|
struct MethodGenInfo prefabInfo;
|
|
prefabInfo.name = "prefabInit";
|
|
prefabInfo.args = "AssetManager *ass";
|
|
prefabInfo.isOverride = true;
|
|
|
|
methodGen(&clazz.publicCode, prefabInfo);
|
|
|
|
|
|
classGen(out, clazz);
|
|
}
|
|
};
|
|
} |