BETA scene generator
This commit is contained in:
@ -12,6 +12,9 @@ SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleVNScene::vnStage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
|
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
|
||||||
auto assMan = &this->game->assetManager;
|
auto assMan = &this->game->assetManager;
|
||||||
|
@ -30,7 +30,7 @@ namespace Dawn {
|
|||||||
/**
|
/**
|
||||||
* Internal method to stage the VN scene.
|
* Internal method to stage the VN scene.
|
||||||
*/
|
*/
|
||||||
virtual void vnStage() = 0;
|
virtual void vnStage();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "DawnGame.hpp"
|
#include "DawnGame.hpp"
|
||||||
#include "scenes/Scene_1.hpp"
|
#include "scenes/vnscene_1.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ int32_t DawnGame::init() {
|
|||||||
this->renderManager.init();
|
this->renderManager.init();
|
||||||
this->audioManager.init();
|
this->audioManager.init();
|
||||||
|
|
||||||
this->scene = new Scene_1(this);
|
this->scene = new vnscene_1(this);
|
||||||
|
|
||||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string filenameOut(argv[2]);
|
std::string filenameOut(argv[2]);
|
||||||
filenameOut += "/nlanguage_" + it->first + ".language";
|
filenameOut += "/language_" + it->first + ".language";
|
||||||
|
|
||||||
char *filenameOutC = (char *)malloc(sizeof(char) * (filenameOut.size() + 1));
|
char *filenameOutC = (char *)malloc(sizeof(char) * (filenameOut.size() + 1));
|
||||||
if(filenameOutC == NULL) {
|
if(filenameOutC == NULL) {
|
||||||
|
@ -11,6 +11,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
char c;
|
char c;
|
||||||
int32_t level = 0;
|
int32_t level = 0;
|
||||||
uint8_t doing = XML_DOING_NOTHING;
|
uint8_t doing = XML_DOING_NOTHING;
|
||||||
|
uint8_t doingBeforeComment;
|
||||||
bool insideTag = false;
|
bool insideTag = false;
|
||||||
char* buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
char* buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
||||||
int32_t bufferLength = 0;
|
int32_t bufferLength = 0;
|
||||||
@ -27,9 +28,10 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
// Look for either an opening tag (<) or a word for a value.
|
// Look for either an opening tag (<) or a word for a value.
|
||||||
if(c == '>') continue;
|
if(c == '>') continue;
|
||||||
if(c == '<') {
|
if(c == '<') {
|
||||||
if(data[i] == '!' && data[i+1] == '-') {
|
if(data[i] == '!' && data[i+1] == '-' && data[i+2] == '-') {
|
||||||
|
doingBeforeComment = doing;
|
||||||
doing = XML_PARSING_COMMENT;
|
doing = XML_PARSING_COMMENT;
|
||||||
i += 2;
|
i += 3;
|
||||||
} else if(insideTag) {
|
} else if(insideTag) {
|
||||||
i = xmlLoadChild(xml->children + xml->childrenCount++, data, i-1);
|
i = xmlLoadChild(xml->children + xml->childrenCount++, data, i-1);
|
||||||
doing = XML_PARSING_CHILD;
|
doing = XML_PARSING_CHILD;
|
||||||
@ -145,6 +147,13 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data[i] == '!' && data[i+1] == '-' && data[i+2] == '-') {
|
||||||
|
doingBeforeComment = doing;
|
||||||
|
doing = XML_PARSING_COMMENT;
|
||||||
|
i += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Likely another child.
|
// Likely another child.
|
||||||
i = xmlLoadChild(xml->children + xml->childrenCount++, data, i-1);
|
i = xmlLoadChild(xml->children + xml->childrenCount++, data, i-1);
|
||||||
}
|
}
|
||||||
@ -169,7 +178,8 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
if(data[i] != '-') continue;
|
if(data[i] != '-') continue;
|
||||||
if(data[i+1] != '>') continue;
|
if(data[i+1] != '>') continue;
|
||||||
i += 2;
|
i += 2;
|
||||||
doing = XML_DOING_NOTHING;
|
doing = doingBeforeComment;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -14,6 +14,6 @@ function(tool_vnscene target in)
|
|||||||
)
|
)
|
||||||
target_include_directories(${DAWN_TARGET_NAME}
|
target_include_directories(${DAWN_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${DAWN_GENERATED_DIR}/scenes
|
${DAWN_GENERATED_DIR}
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
@ -119,6 +119,101 @@ int32_t parseHeader(struct HeaderInformation *info, xml_t *node) {
|
|||||||
return 0;
|
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[]) {
|
int main(int32_t argc, char *args[]) {
|
||||||
if(argc != 3) {
|
if(argc != 3) {
|
||||||
std::cout << "Invalid number of args passed to VNScene Generator" << std::endl;
|
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;
|
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;
|
std::string bufferOut;
|
||||||
bufferOut += "#pragma once\n";
|
bufferOut += "#pragma once\n\n";
|
||||||
auto itInclude = header.includes.begin();
|
auto itInclude = header.includes.begin();
|
||||||
while(itInclude != header.includes.end()) {
|
while(itInclude != header.includes.end()) {
|
||||||
bufferOut += "#include \"" + (*itInclude) + "\"\n";
|
bufferOut += "#include \"" + (*itInclude) + "\"\n";
|
||||||
++itInclude;
|
++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.
|
// Finished with XML data, now we can write data out.
|
||||||
xmlDispose(&xml);
|
xmlDispose(&xml);
|
||||||
|
Reference in New Issue
Block a user