Added default font editing to VN

This commit is contained in:
2023-07-12 22:17:11 -07:00
parent 4649469fee
commit 54932cd348
12 changed files with 129 additions and 8 deletions

View File

@@ -140,11 +140,27 @@ void VNSceneGen::test(
break;
}
case VN_SCENE_EVENT_TYPE_SCENE_CHANGE:
case VN_SCENE_EVENT_TYPE_SCENE_CHANGE: {
initType = "VNSceneChangeEvent<" + event->sceneChange.scene + ">";
toInclude = "games/vn/events/VNSceneChangeEvent.hpp";
includes->push_back(event->sceneChange.include);
break;
}
case VN_SCENE_EVENT_SET_DEFAULT_FONT: {
initType = "VNSetDefaultFontEvent";
toInclude = "games/vn/events/VNSetDefaultFontEvent.hpp";
printf("GENERATING\n\n\n");
std::string strFont = "<font ";
auto sdf = event->setDefaultFont;
if(!sdf.font.empty()) strFont += "font=" + stringParser(sdf.font, NULL);
if(!sdf.fontSize.empty()) strFont += " size=\"" + floatParser(sdf.fontSize, NULL) + "\"";
if(!sdf.color.empty()) strFont += " color=\"" + colorParser(sdf.color, NULL) + "\"";
if(!sdf.style.empty()) strFont += " style=" + stringParser(sdf.style, NULL);
strFont += ">{{ text }}</font>";
line(&eventInitAfter, eventName + "->font = " + stringParser(strFont, NULL) + ";", "");
break;
}
default:
std::cout << "Unknown event type: " << event->type << std::endl;

View File

@@ -18,4 +18,5 @@ target_sources(vnscenetool
VNChoiceSetEventParser.cpp
VNIfEventParser.cpp
VNSceneChangeEventParser.cpp
VNSetDefaultFontEventParser.cpp
)

View File

@@ -90,6 +90,11 @@ int32_t VNSceneEventsParser::onParse(
ret = (VNSceneChangeEventParser()).parse(child, &event.sceneChange, error);
if(ret != 0) return ret;
} else if(child->node == "set-default-font" || child->node == "set-font") {
event.type = VN_SCENE_EVENT_SET_DEFAULT_FONT;
ret = (VNSetDefaultFontEventParser()).parse(child, &event.setDefaultFont, error);
if(ret != 0) return ret;
} else {
*error = "Unknown child node '" + child->node + "'";
return -1;

View File

@@ -15,6 +15,7 @@
#include "VNChoiceSetEventParser.hpp"
#include "VNIfEventParser.hpp"
#include "VNSceneChangeEventParser.hpp"
#include "VNSetDefaultFontEventParser.hpp"
namespace Dawn {
struct VNSceneEvent;
@@ -34,7 +35,8 @@ namespace Dawn {
VN_SCENE_EVENT_TYPE_CHOICES,
VN_SCENE_EVENT_TYPE_CHOICE_SET,
VN_SCENE_EVENT_TYPE_IF,
VN_SCENE_EVENT_TYPE_SCENE_CHANGE
VN_SCENE_EVENT_TYPE_SCENE_CHANGE,
VN_SCENE_EVENT_SET_DEFAULT_FONT
};
struct VNParallelEvent {
@@ -61,6 +63,7 @@ namespace Dawn {
struct VNChoiceSetEvent choiceSet;
struct VNIfEvent ifEvent;
struct VNSceneChangeEvent sceneChange;
struct VNSetFont setDefaultFont;
};
class VNSceneEventsParser : public XmlParser<struct VNSceneEventList> {

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNSetDefaultFontEventParser.hpp"
using namespace Dawn;
std::map<std::string, std::string> VNSetDefaultFontEventParser::getOptionalAttributes() {
return {
{ "font", "font_main" },
{ "style", "" },
{ "size", "" },
{ "color", "" }
};
}
std::vector<std::string> VNSetDefaultFontEventParser::getRequiredAttributes() {
return {};
}
int32_t VNSetDefaultFontEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSetFont *out,
std::string *error
) {
//Get the font
out->font = values["font"];
if(out->font.empty()) {
*error = "Font is required.";
return 1;
}
//Get the style
out->style = values["style"];
//Get the size
out->fontSize = values["size"];
//Get the color
out->color = values["color"];
return 0;
}

View File

@@ -0,0 +1,28 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNSetFont {
std::string font;
std::string style;
std::string fontSize;
std::string color;
};
class VNSetDefaultFontEventParser : public XmlParser<struct VNSetFont> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSetFont *out,
std::string *error
) override;
};
}

View File

@@ -22,9 +22,6 @@ int32_t VNTextParser::onParse(
struct VNText *out,
std::string *error
) {
std::cout << "TEST" << node->innerXml << std::endl;
out->language = values["lang"];
out->text = stringParser(node->innerXml, error);
return error->length() == 0 ? 0 : -1;