Added a great scene generator
This commit is contained in:
@@ -16,6 +16,7 @@ target_sources(scenetool
|
||||
${DAWN_TOOL_SOURCES}
|
||||
SceneTool.cpp
|
||||
SceneParser.cpp
|
||||
SceneGen.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
||||
69
src/dawntools/scenetool/SceneGen.cpp
Normal file
69
src/dawntools/scenetool/SceneGen.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneGen.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SceneGen::generate(
|
||||
std::vector<std::string> *out,
|
||||
struct Scene *scene,
|
||||
std::string tabs
|
||||
) {
|
||||
struct ClassGenInfo classInfo;
|
||||
classInfo.clazz = scene->name;
|
||||
classInfo.extend = "Scene";
|
||||
classInfo.constructorArgs = "DawnGame *game";
|
||||
classInfo.extendArgs = "game";
|
||||
|
||||
struct MethodGenInfo methodAssets;
|
||||
methodAssets.name = "getRequiredAssets";
|
||||
methodAssets.isOverride = true;
|
||||
methodAssets.type = "std::vector<Asset*>";
|
||||
line(&methodAssets.body, "auto assMan = &this->game->assetManager;", "");
|
||||
line(&methodAssets.body, "std::vector<Asset*> assets;", "");
|
||||
|
||||
struct MethodGenInfo methodInit;
|
||||
methodInit.name = "stage";
|
||||
methodInit.isOverride = true;
|
||||
|
||||
classInfo.includes.push_back("scene/Scene.hpp");
|
||||
|
||||
|
||||
// Generate
|
||||
int32_t assetNumber = 0;
|
||||
int32_t childNumber = 0;
|
||||
int32_t componentNumber = 0;
|
||||
std::map<std::string, std::string> assetMap;
|
||||
|
||||
auto sceneItems = scene->items.begin();
|
||||
while(sceneItems != scene->items.end()) {
|
||||
SceneItemGenerator::generate(
|
||||
assetNumber,
|
||||
componentNumber,
|
||||
childNumber,
|
||||
assetMap,
|
||||
classInfo.includes,
|
||||
&classInfo.publicProperties,
|
||||
&methodInit.body,
|
||||
&methodAssets.body,
|
||||
"",
|
||||
"this",
|
||||
&(*sceneItems),
|
||||
""
|
||||
);
|
||||
++sceneItems;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
19
src/dawntools/scenetool/SceneGen.hpp
Normal file
19
src/dawntools/scenetool/SceneGen.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneParser.hpp"
|
||||
#include "util/generator/SceneItemGenerator.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneGen : public CodeGen {
|
||||
public:
|
||||
static void generate(
|
||||
std::vector<std::string> *out,
|
||||
struct Scene *scene,
|
||||
std::string tabs
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -42,10 +42,9 @@ int32_t SceneTool::start() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Generate output
|
||||
std::vector<std::string> outputData;
|
||||
// VNSceneGen::generate(&outputData, &scene, "");
|
||||
SceneGen::generate(&outputData, &scene, "");
|
||||
|
||||
// Load output file from name and type
|
||||
File outputFile = File(flags["output"] + "/scenes/TestScene.hpp");
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "util/File.hpp"
|
||||
#include "util/Xml.hpp"
|
||||
#include "SceneParser.hpp"
|
||||
#include "SceneGen.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneTool : public DawnTool {
|
||||
|
||||
Reference in New Issue
Block a user