|
|
|
@ -119,6 +119,101 @@ int32_t parseHeader(struct HeaderInformation *info, xml_t *node) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string parseEase(std::string e) {
|
|
|
|
|
if(e == "out-quad") return "easeOutQuad";
|
|
|
|
|
std::cout << "Invalid ease defined" << std::endl;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string parseEvent(xml_t *evt, struct HeaderInformation *header) {
|
|
|
|
|
std::string buffer;
|
|
|
|
|
std::string node(evt->node);
|
|
|
|
|
|
|
|
|
|
if(node == "pause") {
|
|
|
|
|
header->includes.push_back("visualnovel/events/timing/VisualNovelPauseEvent.hpp");
|
|
|
|
|
|
|
|
|
|
auto attrDuration = xmlGetAttributeByName(evt, "duration");
|
|
|
|
|
if(attrDuration == -1) {
|
|
|
|
|
std::cout << "Pause event is missing duration argument." << std::endl;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
auto dur = std::string(evt->attributeDatas[attrDuration]);
|
|
|
|
|
if(dur.find('.') == std::string::npos) dur += ".0";
|
|
|
|
|
buffer += "new VisualNovelPauseEvent(vnManager, " + dur + "f)";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if(node == "text") {
|
|
|
|
|
header->includes.push_back("visualnovel/events/VisualNovelTextboxEvent.hpp");
|
|
|
|
|
|
|
|
|
|
auto attrChar = xmlGetAttributeByName(evt, "character");
|
|
|
|
|
if(attrChar == -1) {
|
|
|
|
|
std::cout << "Text event missing character attribute." << std::endl;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto attrEmotion = xmlGetAttributeByName(evt, "emotion");
|
|
|
|
|
if(attrEmotion == -1) {
|
|
|
|
|
std::cout << "Text event missing emotion attribute." << std::endl;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto attrString = xmlGetAttributeByName(evt, "string");
|
|
|
|
|
if(attrString == -1) {
|
|
|
|
|
std::cout << "Text event missing string attribute." << std::endl;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string charName(evt->attributeDatas[attrChar]);
|
|
|
|
|
std::string emo(evt->attributeDatas[attrEmotion]);
|
|
|
|
|
emo[0] = toupper(emo[0]);
|
|
|
|
|
|
|
|
|
|
buffer += "new VisualNovelTextboxEvent(vnManager, ";
|
|
|
|
|
buffer += "this->" + charName + "->vnCharacter, ";
|
|
|
|
|
buffer += "this->" + charName + "->emotion" + emo + ", ";
|
|
|
|
|
buffer += "\"" + std::string(evt->attributeDatas[attrString]) + "\"" ;
|
|
|
|
|
buffer += ")";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if(node == "character-fade") {
|
|
|
|
|
header->includes.push_back("visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp");
|
|
|
|
|
auto attrChar = xmlGetAttributeByName(evt, "character");
|
|
|
|
|
auto attrDuration = xmlGetAttributeByName(evt, "duration");
|
|
|
|
|
auto attrEase = xmlGetAttributeByName(evt, "ease");
|
|
|
|
|
auto attrFade = xmlGetAttributeByName(evt, "fade");
|
|
|
|
|
|
|
|
|
|
if(attrChar == -1) {
|
|
|
|
|
std::cout << "Character fade event missing character attribute." << std::endl;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string character = std::string(evt->attributeDatas[attrChar]);
|
|
|
|
|
std::string easeIn = "true";
|
|
|
|
|
std::string ease = "easeLinear";
|
|
|
|
|
std::string duration = "1.0";
|
|
|
|
|
|
|
|
|
|
if(attrFade != -1) easeIn = std::string(evt->attributeDatas[attrFade]) == "in" ? "true" : "false";
|
|
|
|
|
|
|
|
|
|
if(attrDuration != -1) duration = std::string(evt->attributeDatas[attrDuration]);
|
|
|
|
|
if(duration.find('.') == std::string::npos) duration += ".0";
|
|
|
|
|
|
|
|
|
|
if(attrEase != -1) {
|
|
|
|
|
ease = parseEase(std::string(evt->attributeDatas[attrEase]));
|
|
|
|
|
if(ease.size() == 0) return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer += "new VisualNovelFadeCharacterEvent(vnManager, ";
|
|
|
|
|
buffer += "this->" + character + "->vnCharacter, ";
|
|
|
|
|
buffer += easeIn + ", ";
|
|
|
|
|
buffer += "&" + ease + ", ";
|
|
|
|
|
buffer += duration + "f";
|
|
|
|
|
buffer += ")";
|
|
|
|
|
} else if(node == "scene-transition") {
|
|
|
|
|
buffer += " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int32_t argc, char *args[]) {
|
|
|
|
|
if(argc != 3) {
|
|
|
|
|
std::cout << "Invalid number of args passed to VNScene Generator" << std::endl;
|
|
|
|
@ -172,13 +267,80 @@ int main(int32_t argc, char *args[]) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse and load events.
|
|
|
|
|
std::string bufferEvents;
|
|
|
|
|
for(int32_t i = 0; i < xml.childrenCount; i++) {
|
|
|
|
|
auto events = xml.children + i;
|
|
|
|
|
if(std::string(events->node) != "events") continue;
|
|
|
|
|
bufferEvents += "\n start\n";
|
|
|
|
|
for(int32_t j = 0; j < events->childrenCount; j++) {
|
|
|
|
|
auto evt = events->children + j;
|
|
|
|
|
if(std::string(evt->node) == "scene-transition") continue;
|
|
|
|
|
auto evtParsed = parseEvent(evt, &header);
|
|
|
|
|
if(evtParsed.size() == 0) return 1;
|
|
|
|
|
bufferEvents += " ->then(" + evtParsed + ")\n";
|
|
|
|
|
}
|
|
|
|
|
bufferEvents += " ;\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now render output to file.
|
|
|
|
|
std::string bufferOut;
|
|
|
|
|
bufferOut += "#pragma once\n";
|
|
|
|
|
bufferOut += "#pragma once\n\n";
|
|
|
|
|
auto itInclude = header.includes.begin();
|
|
|
|
|
while(itInclude != header.includes.end()) {
|
|
|
|
|
bufferOut += "#include \"" + (*itInclude) + "\"\n";
|
|
|
|
|
++itInclude;
|
|
|
|
|
}
|
|
|
|
|
bufferOut += "\nnamespace Dawn{\n";
|
|
|
|
|
bufferOut += " class " + header.name + " : public " + header.type + " {\n";
|
|
|
|
|
bufferOut += " protected:\n";
|
|
|
|
|
|
|
|
|
|
// Characters (As properties)
|
|
|
|
|
auto itCharacters = header.characters.begin();
|
|
|
|
|
while(itCharacters != header.characters.end()) {
|
|
|
|
|
auto c = *itCharacters;
|
|
|
|
|
bufferOut += " " + c.clazz + " *" + c.name + ";\n";
|
|
|
|
|
++itCharacters;
|
|
|
|
|
}
|
|
|
|
|
bufferOut += "\n void vnStage() override {\n";
|
|
|
|
|
bufferOut += " " + header.type + "::vnStage();\n";
|
|
|
|
|
|
|
|
|
|
// Initialize the characters
|
|
|
|
|
itCharacters = header.characters.begin();
|
|
|
|
|
while(itCharacters != header.characters.end()) {
|
|
|
|
|
auto c = *itCharacters;
|
|
|
|
|
bufferOut += " this->" + c.name + " = " + c.clazz + "::create(this);\n";
|
|
|
|
|
++itCharacters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bufferOut += " }\n";
|
|
|
|
|
|
|
|
|
|
bufferOut += "\n public:\n";
|
|
|
|
|
bufferOut += " " + header.name + "(DawnGame *game) : " + header.type + "(game) {\n";
|
|
|
|
|
bufferOut += " }\n";
|
|
|
|
|
|
|
|
|
|
// Assets
|
|
|
|
|
bufferOut += "\n std::vector<Asset*> getRequiredAssets() override{\n";
|
|
|
|
|
bufferOut += " auto man = &this->game->assetManager;\n";
|
|
|
|
|
bufferOut += " std::vector<Asset*> assets = " + header.type + "::getRequiredAssets();\n";
|
|
|
|
|
itCharacters = header.characters.begin();
|
|
|
|
|
while(itCharacters != header.characters.end()) {
|
|
|
|
|
auto c = *itCharacters;
|
|
|
|
|
bufferOut += " vectorAppend(&assets, " + c.clazz + "::getRequiredAssets(man));\n";
|
|
|
|
|
++itCharacters;
|
|
|
|
|
}
|
|
|
|
|
bufferOut += " return assets;\n";
|
|
|
|
|
bufferOut += " }\n";
|
|
|
|
|
|
|
|
|
|
// VN Events
|
|
|
|
|
bufferOut += "\n IVisualNovelEvent * getVNEvent() override {\n";
|
|
|
|
|
bufferOut += " auto start = new VisualNovelPauseEvent(vnManager, 0.01f);\n";
|
|
|
|
|
bufferOut += bufferEvents;
|
|
|
|
|
bufferOut += "\n return start;\n";
|
|
|
|
|
bufferOut += " }\n";
|
|
|
|
|
|
|
|
|
|
bufferOut += " };\n";
|
|
|
|
|
bufferOut += "}";
|
|
|
|
|
|
|
|
|
|
// Finished with XML data, now we can write data out.
|
|
|
|
|
xmlDispose(&xml);
|
|
|
|
|