About to break VN Scene Parser

This commit is contained in:
2023-05-17 21:52:24 -07:00
parent 3b0ef97f89
commit 5a60c10049
11 changed files with 34 additions and 15 deletions

View File

@ -20,7 +20,7 @@ add_subdirectory(save)
set(LIMINAL_ASSETS_DIR ${DAWN_ASSETS_DIR}/games/liminal)
tool_scene(${LIMINAL_ASSETS_DIR}/scenes/scene-base.xml)
tool_scene(${LIMINAL_ASSETS_DIR}/scenes/scene-extend.xml)
# tool_vnscene(${LIMINAL_ASSETS_DIR}/test.xml)
tool_vnscene(${LIMINAL_ASSETS_DIR}/test.xml)
tool_prefab(${LIMINAL_ASSETS_DIR}/VNTextbox.xml)
tool_truetype(font_main ${DAWN_ASSETS_DIR}/ark-pixel.ttf)

View File

@ -5,11 +5,11 @@
#include "game/DawnGame.hpp"
#include "scenes/HelloWorldScene.hpp"
#include "scenes/TestScene.hpp"
#include "scenes/ExtendedScene.hpp"
using namespace Dawn;
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
// return new HelloWorldScene(game);
return new TestScene(game);
return new ExtendedScene(game);
}

View File

@ -15,7 +15,6 @@ target_sources(scenetool
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
SceneTool.cpp
SceneParser.cpp
SceneGen.cpp
)

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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 {

View File

@ -8,6 +8,7 @@ set(D ${CMAKE_CURRENT_LIST_DIR})
set(
DAWN_TOOL_SOURCES
${DAWN_TOOL_SOURCES}
${D}/SceneParser.cpp
${D}/SceneItemParser.cpp
${D}/SceneAssetParser.cpp
${D}/SceneItemComponentParser.cpp

View File

@ -40,9 +40,6 @@ int32_t SceneParser::onParse(
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;

View File

@ -6,10 +6,11 @@
#pragma once
#include "VNSceneItemParser.hpp"
#include "events/VNSceneEventsParser.hpp"
#include "util/parser/SceneItemParser.hpp"
namespace Dawn {
struct VNScene {
std::vector<struct VNSceneItem> items;
struct Scene scene;
struct VNSceneEventList events;
};