Updating part of the VN Gen tool to better lay out the generated code
This commit is contained in:
@ -11,41 +11,43 @@ void VNSceneGen::test(
|
|||||||
std::string eventName,
|
std::string eventName,
|
||||||
struct VNSceneEvent *event,
|
struct VNSceneEvent *event,
|
||||||
int32_t *eventIndex,
|
int32_t *eventIndex,
|
||||||
std::vector<std::string> *body,
|
std::vector<std::string> *eventInit,
|
||||||
|
std::vector<std::string> *eventChain,
|
||||||
std::vector<std::string> *includes
|
std::vector<std::string> *includes
|
||||||
) {
|
) {
|
||||||
std::string initType = "";
|
std::string initType = "";
|
||||||
std::string toInclude = "";
|
std::string toInclude = "";
|
||||||
std::string initArgs = "";
|
std::string initArgs = "";
|
||||||
std::vector<std::string> afterLines;
|
|
||||||
|
std::vector<std::string> eventInitAfter;
|
||||||
|
|
||||||
switch(event->type) {
|
switch(event->type) {
|
||||||
case VN_SCENE_EVENT_TYPE_TEXT:
|
case VN_SCENE_EVENT_TYPE_TEXT:
|
||||||
initType = "VNTextEvent";
|
initType = "VNTextEvent";
|
||||||
toInclude = "games/vn/events/VNTextEvent.hpp";
|
toInclude = "games/vn/events/VNTextEvent.hpp";
|
||||||
line(&afterLines, eventName + "->" + "text = " + event->text.texts.begin()->text + ";", "");
|
line(&eventInitAfter, eventName + "->" + "text = " + event->text.texts.begin()->text + ";", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_POSITION:
|
case VN_SCENE_EVENT_TYPE_POSITION:
|
||||||
initType = "VNPositionEvent";
|
initType = "VNPositionEvent";
|
||||||
toInclude = "games/vn/events/VNPositionEvent.hpp";
|
toInclude = "games/vn/events/VNPositionEvent.hpp";
|
||||||
line(&afterLines, eventName + "->item = " + event->position.item + ";", "");
|
line(&eventInitAfter, eventName + "->item = " + event->position.item + ";", "");
|
||||||
if(event->position.x != "") line(&afterLines, eventName + "->" + "to.x = " + event->position.x + ";", "");
|
if(event->position.x != "") line(&eventInitAfter, eventName + "->" + "to.x = " + event->position.x + ";", "");
|
||||||
if(event->position.y != "") line(&afterLines, eventName + "->" + "to.y = " + event->position.y + ";", "");
|
if(event->position.y != "") line(&eventInitAfter, eventName + "->" + "to.y = " + event->position.y + ";", "");
|
||||||
if(event->position.z != "") line(&afterLines, eventName + "->" + "to.z = " + event->position.z + ";", "");
|
if(event->position.z != "") line(&eventInitAfter, eventName + "->" + "to.z = " + event->position.z + ";", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_SET:
|
case VN_SCENE_EVENT_TYPE_SET:
|
||||||
initType = "VNSetEvent<" + event->set.type + ">";
|
initType = "VNSetEvent<" + event->set.type + ">";
|
||||||
toInclude = "games/vn/events/VNSetEvent.hpp";
|
toInclude = "games/vn/events/VNSetEvent.hpp";
|
||||||
line(&afterLines, eventName + "->modifies = &" + event->set.property + ";", "");
|
line(&eventInitAfter, eventName + "->modifies = &" + event->set.property + ";", "");
|
||||||
line(&afterLines, eventName + "->value = " + event->set.to + ";", "");
|
line(&eventInitAfter, eventName + "->value = " + event->set.to + ";", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_WAIT:
|
case VN_SCENE_EVENT_TYPE_WAIT:
|
||||||
initType = "VNWaitEvent";
|
initType = "VNWaitEvent";
|
||||||
toInclude = "games/vn/events/VNWaitEvent.hpp";
|
toInclude = "games/vn/events/VNWaitEvent.hpp";
|
||||||
line(&afterLines, eventName + "->duration = " + event->wait.duration + ";", "");
|
line(&eventInitAfter, eventName + "->duration = " + event->wait.duration + ";", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_PARALLEL: {
|
case VN_SCENE_EVENT_TYPE_PARALLEL: {
|
||||||
@ -59,11 +61,12 @@ void VNSceneGen::test(
|
|||||||
pEventName,
|
pEventName,
|
||||||
&(*itParallel),
|
&(*itParallel),
|
||||||
eventIndex,
|
eventIndex,
|
||||||
&afterLines,
|
eventInit,
|
||||||
|
eventChain,
|
||||||
includes
|
includes
|
||||||
);
|
);
|
||||||
line(&afterLines, eventName + "->events.push_back(" + pEventName + ");", "");
|
line(&eventInitAfter, eventName + "->events.push_back(" + pEventName + ");", "");
|
||||||
line(&afterLines, "", "");
|
line(&eventInitAfter, "", "");
|
||||||
++itParallel;
|
++itParallel;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -72,24 +75,24 @@ void VNSceneGen::test(
|
|||||||
case VN_SCENE_EVENT_TYPE_MARKER:
|
case VN_SCENE_EVENT_TYPE_MARKER:
|
||||||
initType = "VNDummyEvent";
|
initType = "VNDummyEvent";
|
||||||
toInclude = "games/vn/events/VNDummyEvent.hpp";
|
toInclude = "games/vn/events/VNDummyEvent.hpp";
|
||||||
line(&afterLines, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
|
line(&eventInitAfter, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
|
case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
|
||||||
initType = "VNDummyEvent";
|
initType = "VNDummyEvent";
|
||||||
toInclude = "games/vn/events/VNDummyEvent.hpp";
|
toInclude = "games/vn/events/VNDummyEvent.hpp";
|
||||||
line(&afterLines, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
|
line(eventChain, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_CHOICES: {
|
case VN_SCENE_EVENT_TYPE_CHOICES: {
|
||||||
initType = "VNChoiceEvent";
|
initType = "VNChoiceEvent";
|
||||||
toInclude = "games/vn/events/VNChoiceEvent.hpp";
|
toInclude = "games/vn/events/VNChoiceEvent.hpp";
|
||||||
|
|
||||||
line(&afterLines, eventName + "->key = \"" + event->choices.key+ "\";", "");
|
line(&eventInitAfter, eventName + "->key = \"" + event->choices.key+ "\";", "");
|
||||||
line(&afterLines, eventName + "->text = " + event->choices.titles.begin()->text + ";", "");
|
line(&eventInitAfter, eventName + "->text = " + event->choices.titles.begin()->text + ";", "");
|
||||||
auto itChoices = event->choices.choices.begin();
|
auto itChoices = event->choices.choices.begin();
|
||||||
while(itChoices != event->choices.choices.end()) {
|
while(itChoices != event->choices.choices.end()) {
|
||||||
line(&afterLines, eventName + "->choices[\"" + itChoices->value + "\"] = " + itChoices->texts.begin()->text + ";", "");
|
line(&eventInitAfter, eventName + "->choices[\"" + itChoices->value + "\"] = " + itChoices->texts.begin()->text + ";", "");
|
||||||
++itChoices;
|
++itChoices;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -98,15 +101,15 @@ void VNSceneGen::test(
|
|||||||
case VN_SCENE_EVENT_TYPE_CHOICE_SET:
|
case VN_SCENE_EVENT_TYPE_CHOICE_SET:
|
||||||
initType = "VNChoiceSetEvent";
|
initType = "VNChoiceSetEvent";
|
||||||
toInclude = "games/vn/events/VNChoiceSetEvent.hpp";
|
toInclude = "games/vn/events/VNChoiceSetEvent.hpp";
|
||||||
line(&afterLines, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
|
line(&eventInitAfter, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
|
||||||
line(&afterLines, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
|
line(&eventInitAfter, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VN_SCENE_EVENT_TYPE_IF: {
|
case VN_SCENE_EVENT_TYPE_IF: {
|
||||||
initType = "VNIfEvent";
|
initType = "VNIfEvent";
|
||||||
toInclude = "games/vn/events/VNIfEvent.hpp";
|
toInclude = "games/vn/events/VNIfEvent.hpp";
|
||||||
line(&afterLines, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
|
line(&eventInitAfter, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
|
||||||
line(&afterLines, eventName + "->value = \"" + event->ifEvent.value + "\";", "");
|
line(&eventInitAfter, eventName + "->value = \"" + event->ifEvent.value + "\";", "");
|
||||||
|
|
||||||
std::string ifPrevious = "";
|
std::string ifPrevious = "";
|
||||||
std::string ifFirst = "";
|
std::string ifFirst = "";
|
||||||
@ -117,10 +120,11 @@ void VNSceneGen::test(
|
|||||||
ifEventName,
|
ifEventName,
|
||||||
&(*itIf),
|
&(*itIf),
|
||||||
eventIndex,
|
eventIndex,
|
||||||
&afterLines,
|
eventInit,
|
||||||
|
eventChain,
|
||||||
includes
|
includes
|
||||||
);
|
);
|
||||||
if(!ifPrevious.empty()) line(&afterLines, ifPrevious + "->then(" + ifEventName + ");", "");
|
if(!ifPrevious.empty()) line(eventChain, ifPrevious + "->then(" + ifEventName + ");", "");
|
||||||
ifPrevious = ifEventName;
|
ifPrevious = ifEventName;
|
||||||
if(ifFirst == "") ifFirst = ifEventName;
|
if(ifFirst == "") ifFirst = ifEventName;
|
||||||
++itIf;
|
++itIf;
|
||||||
@ -131,8 +135,8 @@ void VNSceneGen::test(
|
|||||||
assertUnreachable();
|
assertUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
line(&afterLines, eventName + "->ifTrue = " + ifFirst + ";", "");
|
line(eventChain, eventName + "->ifTrue = " + ifFirst + ";", "");
|
||||||
line(&afterLines, eventName + "->ifEnd = " + ifPrevious + ";", "");
|
line(eventChain, eventName + "->ifEnd = " + ifPrevious + ";", "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,8 +153,8 @@ void VNSceneGen::test(
|
|||||||
|
|
||||||
if(!toInclude.empty()) includes->push_back(toInclude);
|
if(!toInclude.empty()) includes->push_back(toInclude);
|
||||||
|
|
||||||
line(body, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
|
line(eventInit, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
|
||||||
lines(body, afterLines, "");
|
lines(eventInit, eventInitAfter, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void VNSceneGen::generate(
|
void VNSceneGen::generate(
|
||||||
@ -162,7 +166,6 @@ void VNSceneGen::generate(
|
|||||||
struct MethodGenInfo methodAssets;
|
struct MethodGenInfo methodAssets;
|
||||||
struct MethodGenInfo methodInit;
|
struct MethodGenInfo methodInit;
|
||||||
|
|
||||||
|
|
||||||
// Load Scene
|
// Load Scene
|
||||||
SceneGenerator::generate(
|
SceneGenerator::generate(
|
||||||
&scene->scene,
|
&scene->scene,
|
||||||
@ -181,23 +184,30 @@ void VNSceneGen::generate(
|
|||||||
int32_t eventIndex = 0;
|
int32_t eventIndex = 0;
|
||||||
auto itEvents = scene->events.events.begin();
|
auto itEvents = scene->events.events.begin();
|
||||||
std::string previous = "eventStart";
|
std::string previous = "eventStart";
|
||||||
|
|
||||||
|
std::vector<std::string> eventInit;
|
||||||
|
std::vector<std::string> eventChain;
|
||||||
|
|
||||||
while(itEvents != scene->events.events.end()) {
|
while(itEvents != scene->events.events.end()) {
|
||||||
line(&methodInit.body, "", "");
|
line(&eventInit, "", "");
|
||||||
std::string eventName = "event" + std::to_string(eventIndex++);
|
std::string eventName = "event" + std::to_string(eventIndex++);
|
||||||
VNSceneGen::test(
|
VNSceneGen::test(
|
||||||
eventName,
|
eventName,
|
||||||
&(*itEvents),
|
&(*itEvents),
|
||||||
&eventIndex,
|
&eventIndex,
|
||||||
&methodInit.body,
|
&eventInit,
|
||||||
|
&eventChain,
|
||||||
&classInfo.includes
|
&classInfo.includes
|
||||||
);
|
);
|
||||||
line(&methodInit.body, previous + "->then(" + eventName + ");", "");
|
if(!previous.empty()) line(&eventChain, previous + "->then(" + eventName + ");", "");
|
||||||
previous = eventName;
|
previous = eventName;
|
||||||
|
if(itEvents->type == VN_SCENE_EVENT_TYPE_GOTO_MARKER) previous = "";
|
||||||
++itEvents;
|
++itEvents;
|
||||||
}
|
}
|
||||||
line(&methodInit.body, "", "");
|
|
||||||
line(&methodInit.body, "vnManager->setEvent(eventStart);", "");
|
|
||||||
|
|
||||||
|
lines(&methodInit.body, eventInit, "");
|
||||||
|
lines(&methodInit.body, eventChain, "");
|
||||||
|
line(&methodInit.body, "vnManager->setEvent(eventStart);", "");
|
||||||
|
|
||||||
// Add in methods
|
// Add in methods
|
||||||
CodeGen::methodGen(&classInfo.publicCode, methodAssets);
|
CodeGen::methodGen(&classInfo.publicCode, methodAssets);
|
||||||
|
@ -15,7 +15,8 @@ namespace Dawn {
|
|||||||
std::string eventName,
|
std::string eventName,
|
||||||
struct VNSceneEvent *event,
|
struct VNSceneEvent *event,
|
||||||
int32_t *eventIndex,
|
int32_t *eventIndex,
|
||||||
std::vector<std::string> *body,
|
std::vector<std::string> *eventInit,
|
||||||
|
std::vector<std::string> *eventChain,
|
||||||
std::vector<std::string> *includes
|
std::vector<std::string> *includes
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user