VN Scene update prog.

This commit is contained in:
2023-05-18 09:35:03 -07:00
parent fc303b3b47
commit e5b7bb9eec
3 changed files with 196 additions and 199 deletions

View File

@ -14,138 +14,139 @@ void VNSceneGen::test(
std::vector<std::string> *body,
std::vector<std::string> *includes
) {
std::string initType = "";
std::string toInclude = "";
std::string initArgs = "";
std::vector<std::string> afterLines;
switch(event->type) {
case VN_SCENE_EVENT_TYPE_TEXT:
initType = "VNTextEvent";
toInclude = "games/vn/events/VNTextEvent.hpp";
line(&afterLines, eventName + "->" + "text = \"" + event->text.texts.begin()->text + "\";", "");
break;
// std::string initType = "";
// std::string toInclude = "";
// std::string initArgs = "";
// std::vector<std::string> afterLines;
case VN_SCENE_EVENT_TYPE_POSITION:
initType = "VNPositionEvent";
toInclude = "games/vn/events/VNPositionEvent.hpp";
line(&afterLines, eventName + "->item = " + event->position.item + ";", "");
if(event->position.x != "") line(&afterLines, eventName + "->" + "to.x = " + event->position.x + ";", "");
if(event->position.y != "") line(&afterLines, eventName + "->" + "to.y = " + event->position.y + ";", "");
if(event->position.z != "") line(&afterLines, eventName + "->" + "to.z = " + event->position.z + ";", "");
break;
// switch(event->type) {
// case VN_SCENE_EVENT_TYPE_TEXT:
// initType = "VNTextEvent";
// toInclude = "games/vn/events/VNTextEvent.hpp";
// line(&afterLines, eventName + "->" + "text = \"" + event->text.texts.begin()->text + "\";", "");
// break;
case VN_SCENE_EVENT_TYPE_SET:
initType = "VNSetEvent<" + event->set.type + ">";
toInclude = "games/vn/events/VNSetEvent.hpp";
line(&afterLines, eventName + "->modifies = &" + event->set.property + ";", "");
line(&afterLines, eventName + "->to = " + event->set.to + ";", "");
if(event->set.from != "") line(&afterLines, eventName + "->from = " + event->set.from + ";", "");
if(event->set.duration != "") line(&afterLines, eventName + "->duration = " + event->set.duration + ";", "");
break;
// case VN_SCENE_EVENT_TYPE_POSITION:
// initType = "VNPositionEvent";
// toInclude = "games/vn/events/VNPositionEvent.hpp";
// line(&afterLines, eventName + "->item = " + event->position.item + ";", "");
// if(event->position.x != "") line(&afterLines, eventName + "->" + "to.x = " + event->position.x + ";", "");
// if(event->position.y != "") line(&afterLines, eventName + "->" + "to.y = " + event->position.y + ";", "");
// if(event->position.z != "") line(&afterLines, eventName + "->" + "to.z = " + event->position.z + ";", "");
// break;
case VN_SCENE_EVENT_TYPE_WAIT:
initType = "VNWaitEvent";
toInclude = "games/vn/events/VNWaitEvent.hpp";
line(&afterLines, eventName + "->duration = " + event->wait.duration + ";", "");
break;
// case VN_SCENE_EVENT_TYPE_SET:
// initType = "VNSetEvent<" + event->set.type + ">";
// toInclude = "games/vn/events/VNSetEvent.hpp";
// line(&afterLines, eventName + "->modifies = &" + event->set.property + ";", "");
// line(&afterLines, eventName + "->to = " + event->set.to + ";", "");
// if(event->set.from != "") line(&afterLines, eventName + "->from = " + event->set.from + ";", "");
// if(event->set.duration != "") line(&afterLines, eventName + "->duration = " + event->set.duration + ";", "");
// break;
case VN_SCENE_EVENT_TYPE_PARALLEL: {
initType = "VNParallelEvent";
toInclude = "games/vn/events/VNParallelEvent.hpp";
// case VN_SCENE_EVENT_TYPE_WAIT:
// initType = "VNWaitEvent";
// toInclude = "games/vn/events/VNWaitEvent.hpp";
// line(&afterLines, eventName + "->duration = " + event->wait.duration + ";", "");
// break;
auto itParallel = event->parallel.events.events.begin();
while(itParallel != event->parallel.events.events.end()) {
std::string pEventName = "pEvent" + std::to_string((*eventIndex)++);
VNSceneGen::test(
pEventName,
&(*itParallel),
eventIndex,
&afterLines,
includes
);
line(&afterLines, eventName + "->events.push_back(" + pEventName + ");", "");
line(&afterLines, "", "");
++itParallel;
}
break;
}
// case VN_SCENE_EVENT_TYPE_PARALLEL: {
// initType = "VNParallelEvent";
// toInclude = "games/vn/events/VNParallelEvent.hpp";
case VN_SCENE_EVENT_TYPE_MARKER:
initType = "VNDummyEvent";
toInclude = "games/vn/events/VNDummyEvent.hpp";
line(&afterLines, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
break;
// auto itParallel = event->parallel.events.events.begin();
// while(itParallel != event->parallel.events.events.end()) {
// std::string pEventName = "pEvent" + std::to_string((*eventIndex)++);
// VNSceneGen::test(
// pEventName,
// &(*itParallel),
// eventIndex,
// &afterLines,
// includes
// );
// line(&afterLines, eventName + "->events.push_back(" + pEventName + ");", "");
// line(&afterLines, "", "");
// ++itParallel;
// }
// break;
// }
case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
initType = "VNDummyEvent";
toInclude = "games/vn/events/VNDummyEvent.hpp";
line(&afterLines, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
break;
// case VN_SCENE_EVENT_TYPE_MARKER:
// initType = "VNDummyEvent";
// toInclude = "games/vn/events/VNDummyEvent.hpp";
// line(&afterLines, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
// break;
case VN_SCENE_EVENT_TYPE_CHOICES: {
initType = "VNChoiceEvent";
toInclude = "games/vn/events/VNChoiceEvent.hpp";
line(&afterLines, eventName + "->key = \"" + event->choices.key+ "\";", "");
line(&afterLines, eventName + "->text = \"" + event->choices.titles.begin()->text + "\";", "");
auto itChoices = event->choices.choices.begin();
while(itChoices != event->choices.choices.end()) {
line(&afterLines, eventName + "->choices[\"" + itChoices->value + "\"] = \"" + itChoices->texts.begin()->text + "\";", "");
++itChoices;
}
break;
}
// case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
// initType = "VNDummyEvent";
// toInclude = "games/vn/events/VNDummyEvent.hpp";
// line(&afterLines, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
// break;
case VN_SCENE_EVENT_TYPE_CHOICE_SET:
initType = "VNChoiceSetEvent";
toInclude = "games/vn/events/VNChoiceSetEvent.hpp";
line(&afterLines, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
line(&afterLines, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
break;
// case VN_SCENE_EVENT_TYPE_CHOICES: {
// initType = "VNChoiceEvent";
// toInclude = "games/vn/events/VNChoiceEvent.hpp";
// line(&afterLines, eventName + "->key = \"" + event->choices.key+ "\";", "");
// line(&afterLines, eventName + "->text = \"" + event->choices.titles.begin()->text + "\";", "");
// auto itChoices = event->choices.choices.begin();
// while(itChoices != event->choices.choices.end()) {
// line(&afterLines, eventName + "->choices[\"" + itChoices->value + "\"] = \"" + itChoices->texts.begin()->text + "\";", "");
// ++itChoices;
// }
// break;
// }
case VN_SCENE_EVENT_TYPE_IF: {
initType = "VNIfEvent";
toInclude = "games/vn/events/VNIfEvent.hpp";
line(&afterLines, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
line(&afterLines, eventName + "->value = \"" + event->ifEvent.value + "\";", "");
// case VN_SCENE_EVENT_TYPE_CHOICE_SET:
// initType = "VNChoiceSetEvent";
// toInclude = "games/vn/events/VNChoiceSetEvent.hpp";
// line(&afterLines, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
// line(&afterLines, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
// break;
std::string ifPrevious = "";
std::string ifFirst = "";
auto itIf = event->ifEvent.events.events.begin();
while(itIf != event->ifEvent.events.events.end()) {
std::string ifEventName = "ifEvent" + std::to_string((*eventIndex)++);
VNSceneGen::test(
ifEventName,
&(*itIf),
eventIndex,
&afterLines,
includes
);
if(!ifPrevious.empty()) line(&afterLines, ifPrevious + "->then(" + ifEventName + ");", "");
ifPrevious = ifEventName;
if(ifFirst == "") ifFirst = ifEventName;
++itIf;
}
// case VN_SCENE_EVENT_TYPE_IF: {
// initType = "VNIfEvent";
// toInclude = "games/vn/events/VNIfEvent.hpp";
// line(&afterLines, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
// line(&afterLines, eventName + "->value = \"" + event->ifEvent.value + "\";", "");
if(ifFirst == "" || ifPrevious == "") {
std::cout << "If event must have at least one event" << std::endl;
assertUnreachable();
}
// std::string ifPrevious = "";
// std::string ifFirst = "";
// auto itIf = event->ifEvent.events.events.begin();
// while(itIf != event->ifEvent.events.events.end()) {
// std::string ifEventName = "ifEvent" + std::to_string((*eventIndex)++);
// VNSceneGen::test(
// ifEventName,
// &(*itIf),
// eventIndex,
// &afterLines,
// includes
// );
// if(!ifPrevious.empty()) line(&afterLines, ifPrevious + "->then(" + ifEventName + ");", "");
// ifPrevious = ifEventName;
// if(ifFirst == "") ifFirst = ifEventName;
// ++itIf;
// }
line(&afterLines, eventName + "->ifTrue = " + ifFirst + ";", "");
line(&afterLines, eventName + "->ifEnd = " + ifPrevious + ";", "");
break;
}
// if(ifFirst == "" || ifPrevious == "") {
// std::cout << "If event must have at least one event" << std::endl;
// assertUnreachable();
// }
default:
std::cout << "Unknown event type: " << event->type << std::endl;
assertUnreachable();
}
// line(&afterLines, eventName + "->ifTrue = " + ifFirst + ";", "");
// line(&afterLines, eventName + "->ifEnd = " + ifPrevious + ";", "");
// break;
// }
if(!toInclude.empty()) includes->push_back(toInclude);
// default:
// std::cout << "Unknown event type: " << event->type << std::endl;
// assertUnreachable();
// }
line(body, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
lines(body, afterLines, "");
// if(!toInclude.empty()) includes->push_back(toInclude);
// line(body, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
// lines(body, afterLines, "");
}
void VNSceneGen::generate(
@ -153,84 +154,86 @@ void VNSceneGen::generate(
struct VNScene *scene,
std::string tabs
) {
struct ClassGenInfo classInfo;
classInfo.clazz = "TestScene";
classInfo.extend = "Scene";
classInfo.constructorArgs = "DawnGame *game";
classInfo.extendArgs = "game";
std::cout << "Gen Scene" << std::endl;
classInfo.includes.push_back("scene/Scene.hpp");
// struct ClassGenInfo classInfo;
// classInfo.clazz = "TestScene";
// 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;", "");
line(&methodAssets.body, "return assets;", "");
// classInfo.includes.push_back("scene/Scene.hpp");
struct MethodGenInfo methodStage;
methodStage.name = "stage";
methodStage.isOverride = "true";
line(&methodStage.body, "// test", "");
// 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;", "");
// line(&methodAssets.body, "return assets;", "");
// TEST
line(&methodStage.body, "auto canvas = UICanvas::create(this);", "");
line(&methodStage.body, "", "");
// struct MethodGenInfo methodStage;
// methodStage.name = "stage";
// methodStage.isOverride = "true";
// line(&methodStage.body, "// test", "");
classInfo.includes.push_back("scene/components/display/Camera.hpp");
line(&methodStage.body, "auto camera = Camera::create(this);", "");
line(&methodStage.body, "camera->fov = 0.436332f;", "");
line(&methodStage.body, "camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));", "");
// // TEST
// line(&methodStage.body, "auto canvas = UICanvas::create(this);", "");
// line(&methodStage.body, "", "");
// Items
int32_t itemRefIndex = 0;
auto itItems = scene->items.begin();
while(itItems != scene->items.end()) {
struct VNSceneItem item = *itItems;
if(item.ref.empty()) item.ref = "item" + std::to_string(itemRefIndex++);
classInfo.includes.push_back(item.prefab + ".hpp");
// classInfo.includes.push_back("scene/components/display/Camera.hpp");
// line(&methodStage.body, "auto camera = Camera::create(this);", "");
// line(&methodStage.body, "camera->fov = 0.436332f;", "");
// line(&methodStage.body, "camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));", "");
// // Items
// int32_t itemRefIndex = 0;
// auto itItems = scene->items.begin();
// while(itItems != scene->items.end()) {
// struct VNSceneItem item = *itItems;
// if(item.ref.empty()) item.ref = "item" + std::to_string(itemRefIndex++);
// classInfo.includes.push_back(item.prefab + ".hpp");
line(&methodStage.body, "", "");
line(&methodStage.body, "auto " + item.ref + " = " + item.className + "::create(this);", "");
// line(&methodStage.body, "", "");
// line(&methodStage.body, "auto " + item.ref + " = " + item.className + "::create(this);", "");
++itItems;
}
// ++itItems;
// }
line(&methodStage.body, "", "");
// line(&methodStage.body, "", "");
// Events
classInfo.includes.push_back("games/vn/components/VNManager.hpp");
line(&methodStage.body, "auto vnItem = this->createSceneItem();", "");
line(&methodStage.body, "auto vnManager = vnItem->addComponent<VNManager>();", "");
line(&methodStage.body, "VNEvent *previous = vnManager->createEvent<VNDummyEvent>();", "");
line(&methodStage.body, "auto eventStart = previous;", "");
// // Events
// classInfo.includes.push_back("games/vn/components/VNManager.hpp");
// line(&methodStage.body, "auto vnItem = this->createSceneItem();", "");
// line(&methodStage.body, "auto vnManager = vnItem->addComponent<VNManager>();", "");
// line(&methodStage.body, "VNEvent *previous = vnManager->createEvent<VNDummyEvent>();", "");
// line(&methodStage.body, "auto eventStart = previous;", "");
int32_t eventIndex = 0;
auto itEvents = scene->events.events.begin();
std::string previous = "eventStart";
while(itEvents != scene->events.events.end()) {
line(&methodStage.body, "", "");
std::string eventName = "event" + std::to_string(eventIndex++);
VNSceneGen::test(
eventName,
&(*itEvents),
&eventIndex,
&methodStage.body,
&classInfo.includes
);
line(&methodStage.body, previous + "->then(" + eventName + ");", "");
previous = eventName;
++itEvents;
}
// int32_t eventIndex = 0;
// auto itEvents = scene->events.events.begin();
// std::string previous = "eventStart";
// while(itEvents != scene->events.events.end()) {
// line(&methodStage.body, "", "");
// std::string eventName = "event" + std::to_string(eventIndex++);
// VNSceneGen::test(
// eventName,
// &(*itEvents),
// &eventIndex,
// &methodStage.body,
// &classInfo.includes
// );
// line(&methodStage.body, previous + "->then(" + eventName + ");", "");
// previous = eventName;
// ++itEvents;
// }
line(&methodStage.body, "", "");
line(&methodStage.body, "vnManager->setEvent(eventStart);", "");
// line(&methodStage.body, "", "");
// line(&methodStage.body, "vnManager->setEvent(eventStart);", "");
// Add in methods
CodeGen::methodGen(&classInfo.protectedCode, methodAssets);
line(&classInfo.protectedCode, "", "");
CodeGen::methodGen(&classInfo.protectedCode, methodStage);
// // Add in methods
// CodeGen::methodGen(&classInfo.protectedCode, methodAssets);
// line(&classInfo.protectedCode, "", "");
// CodeGen::methodGen(&classInfo.protectedCode, methodStage);
CodeGen::classGen(out, classInfo);
// CodeGen::classGen(out, classInfo);
}

View File

@ -24,27 +24,21 @@ int32_t VNSceneParser::onParse(
//
int32_t ret;
// First, pass as a standard scene
ret = (SceneParser()).parse(node, &out->scene, error);
if(ret != 0) return ret;
// Now pass the VN Events
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
Xml *child = *itChildren;
// Parse event(s)
if(child->node == "item") {
struct VNSceneItem item;
ret = (VNSceneItemParser()).parse(child, &item, error);
if(ret != 0) return ret;
out->items.push_back(item);
} else if(child->node == "events") {
ret = (VNSceneEventsParser()).parse(child, &out->events, error);
if(ret != 0) return ret;
} else {
// Unknown node
*error = "Unknown node '" + child->node + "' in <vnscene>";
return -1;
if(child->node != "events") {
++itChildren;
continue;
}
itChildren++;
ret = (VNSceneEventsParser()).parse(child, &out->events, error);
if(ret != 0) return ret;
break;
}
return 0;

View File

@ -4,9 +4,9 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "util/parser/SceneParser.hpp"
#include "VNSceneItemParser.hpp"
#include "events/VNSceneEventsParser.hpp"
#include "util/parser/SceneItemParser.hpp"
namespace Dawn {
struct VNScene {