2023-10-31 21:15:03 -05:00

65 lines
1.7 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PrefabGen.hpp"
using namespace Dawn;
void PrefabGen::generate(
std::vector<std::string> *out,
struct Prefab *info,
std::string tabs
) {
struct ClassGenInfo classInfo;
classInfo.clazz = info->name;
classInfo.extend = "SceneItemPrefab<" + info->name + ">";
classInfo.constructorArgs = "Scene *scene, sceneitemid_t id";
classInfo.extendArgs = "scene, id";
struct MethodGenInfo methodAssets;
methodAssets.name = "prefabAssets";
methodAssets.isStatic = true;
methodAssets.type = "std::vector<Asset*>";
methodAssets.args = "AssetManager *man";
line(&methodAssets.body, "std::vector<Asset*> assets;", "");
struct MethodGenInfo methodInit;
methodInit.name = "prefabInit";
methodInit.isOverride = true;
methodInit.args = "AssetManager *man";
classInfo.includes.push_back("prefab/SceneItemPrefab.hpp");
// Generate
int32_t assetNumber = 0;
int32_t childNumber = 0;
int32_t componentNumber = 0;
std::map<std::string, std::string> assetMap;
info->root.ref = "this";
SceneItemGenerator::generate(
assetNumber,
componentNumber,
childNumber,
assetMap,
classInfo.includes,
&classInfo.publicProperties,
&methodInit.body,
&methodAssets.body,
"",
"scene",
&info->root,
""
);
// Seal methods
line(&methodAssets.body, "return assets;", "");
// Add in methods
CodeGen::methodGen(&classInfo.publicCode, methodAssets);
line(&classInfo.publicCode, "", "");
CodeGen::methodGen(&classInfo.publicCode, methodInit);
CodeGen::classGen(out, classInfo);
}