105 lines
3.3 KiB
C++
105 lines
3.3 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "VnSceneParseEvent.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
std::string parseEase(std::string e) {
|
|
if(e == "out-quad") return "easeOutQuad";
|
|
std::cout << "Invalid ease defined" << std::endl;
|
|
return "";
|
|
}
|
|
|
|
std::string parseEvent(struct HeaderInformation *header, Xml *evt) {
|
|
std::string buffer;
|
|
std::string node(evt->node);
|
|
|
|
if(node == "pause") {
|
|
// Pause
|
|
header->includes.push_back("visualnovel/events/timing/VisualNovelPauseEvent.hpp");
|
|
|
|
auto attrDuration = evt->attributes.find("duration");
|
|
if(attrDuration == evt->attributes.end()) {
|
|
std::cout << "Pause event is missing duration argument." << std::endl;
|
|
return "";
|
|
}
|
|
auto dur = attrDuration->second;
|
|
if(dur.find('.') == std::string::npos) dur += ".0";
|
|
buffer += "new VisualNovelPauseEvent(vnManager, " + dur + "f)";
|
|
|
|
|
|
} else if(node == "text") {
|
|
// Text
|
|
header->includes.push_back("visualnovel/events/VisualNovelTextboxEvent.hpp");
|
|
|
|
auto attrChar = evt->attributes.find("character");
|
|
if(attrChar == evt->attributes.end()) {
|
|
std::cout << "Text event missing character attribute." << std::endl;
|
|
return "";
|
|
}
|
|
|
|
auto attrEmotion = evt->attributes.find("emotion");
|
|
if(attrEmotion == evt->attributes.end()) {
|
|
std::cout << "Text event missing emotion attribute." << std::endl;
|
|
return "";
|
|
}
|
|
|
|
auto attrString = evt->attributes.find("string");
|
|
if(attrString == evt->attributes.end()) {
|
|
std::cout << "Text event missing string attribute." << std::endl;
|
|
return "";
|
|
}
|
|
|
|
std::string emo = attrEmotion->second;
|
|
emo[0] = toupper(emo[0]);
|
|
|
|
buffer += "new VisualNovelTextboxEvent(vnManager, ";
|
|
buffer += "this->" + attrChar->second + "->vnCharacter, ";
|
|
buffer += "this->" + attrChar->second + "->emotion" + emo + ", ";
|
|
buffer += "\"" + attrString->second + "\"" ;
|
|
buffer += ")";
|
|
|
|
|
|
} else if(node == "character-fade") {
|
|
// Character Fade
|
|
header->includes.push_back("visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp");
|
|
auto attrChar = evt->attributes.find("character");
|
|
auto attrDuration = evt->attributes.find("duration");
|
|
auto attrEase = evt->attributes.find("ease");
|
|
auto attrFade = evt->attributes.find("fade");
|
|
|
|
if(attrChar == evt->attributes.end()) {
|
|
std::cout << "Character fade event missing character attribute." << std::endl;
|
|
return "";
|
|
}
|
|
|
|
std::string character = attrChar->second;
|
|
std::string easeIn = "true";
|
|
std::string ease = "easeLinear";
|
|
std::string duration = "1.0";
|
|
|
|
if(attrFade != evt->attributes.end()) easeIn = attrFade->second == "in" ? "true" : "false";
|
|
|
|
if(attrDuration != evt->attributes.end()) duration = attrDuration->second;
|
|
if(duration.find('.') == std::string::npos) duration += ".0";
|
|
|
|
if(attrEase != evt->attributes.end()) {
|
|
ease = parseEase(attrEase->second);
|
|
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;
|
|
} |