About to break VN Scene Parser
This commit is contained in:
@@ -15,7 +15,6 @@ target_sources(scenetool
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
SceneTool.cpp
|
||||
SceneParser.cpp
|
||||
SceneGen.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -14,23 +14,44 @@ void SceneGen::generate(
|
||||
) {
|
||||
struct ClassGenInfo classInfo;
|
||||
classInfo.clazz = scene->name;
|
||||
classInfo.extend = "Scene";
|
||||
classInfo.constructorArgs = "DawnGame *game";
|
||||
classInfo.extendArgs = "game";
|
||||
|
||||
std::string baseClassName = "Scene";
|
||||
|
||||
// Determine extends
|
||||
if(scene->extend.empty()) {
|
||||
classInfo.includes.push_back("scene/Scene.hpp");
|
||||
} else {
|
||||
classInfo.includes.push_back(scene->extend + ".hpp");
|
||||
|
||||
// Get last slash of scene->extend
|
||||
auto lastSlash = scene->extend.find_last_of('/');
|
||||
if(lastSlash != std::string::npos) {
|
||||
baseClassName = scene->extend.substr(lastSlash + 1);
|
||||
} else {
|
||||
baseClassName = scene->extend;
|
||||
}
|
||||
}
|
||||
classInfo.extend = baseClassName;
|
||||
// classInfo.extend = "Scene";
|
||||
|
||||
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");
|
||||
|
||||
if(scene->extend.empty()) {
|
||||
line(&methodAssets.body, "std::vector<Asset*> assets;", "");
|
||||
} else {
|
||||
line(&methodAssets.body, "std::vector<Asset*> assets = " + baseClassName + "::getRequiredAssets();", "");
|
||||
line(&methodInit.body, baseClassName + "::stage();", "");
|
||||
}
|
||||
|
||||
// Generate
|
||||
int32_t assetNumber = 0;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneParser.hpp"
|
||||
#include "util/parser/SceneParser.hpp"
|
||||
#include "util/generator/SceneItemGenerator.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> SceneParser::getRequiredAttributes() {
|
||||
return { "name" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> SceneParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "extend", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t SceneParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct Scene *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
|
||||
//Create the scene item
|
||||
out->name = values["name"];
|
||||
out->extend = values["extend"];
|
||||
|
||||
//Parse the children
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
Xml *child = *itChildren;
|
||||
|
||||
if(child->node == "item") {
|
||||
struct SceneItem item;
|
||||
item.registry = out->registry;
|
||||
ret = (SceneItemParser()).parse(child, &item, error);
|
||||
if(ret != 0) return 1;
|
||||
out->items.push_back(item);
|
||||
} else {
|
||||
*error = "Unknown node type " + child->node;
|
||||
return 1;
|
||||
}
|
||||
|
||||
++itChildren;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/parser/SceneItemParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Scene {
|
||||
std::string name;
|
||||
std::string extend;
|
||||
std::vector<struct SceneItem> items;
|
||||
struct SceneItemComponentRegistry *registry;
|
||||
};
|
||||
|
||||
class SceneParser : public XmlParser<struct Scene> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct Scene *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
||||
@@ -47,7 +47,7 @@ int32_t SceneTool::start() {
|
||||
SceneGen::generate(&outputData, &scene, "");
|
||||
|
||||
// Load output file from name and type
|
||||
File outputFile = File(flags["output"] + "/scenes/TestScene.hpp");
|
||||
File outputFile = File(flags["output"] + "/scenes/" + scene.name + ".hpp");
|
||||
if(!outputFile.mkdirp()) {
|
||||
std::cout << "Failed to create output directory!" << std::endl;
|
||||
return 1;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/File.hpp"
|
||||
#include "util/Xml.hpp"
|
||||
#include "SceneParser.hpp"
|
||||
#include "util/parser/SceneParser.hpp"
|
||||
#include "SceneGen.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
|
||||
Reference in New Issue
Block a user