Moved C++ tools out
This commit is contained in:
64
archive/dawntools/vnscenetool/CMakeLists.txt
Normal file
64
archive/dawntools/vnscenetool/CMakeLists.txt
Normal file
@ -0,0 +1,64 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Texture Build Tool
|
||||
project(vnscenetool VERSION 1.0)
|
||||
add_executable(vnscenetool)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(events)
|
||||
|
||||
# Sources
|
||||
target_sources(vnscenetool
|
||||
PRIVATE
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
VNSceneTool.cpp
|
||||
VNSceneParser.cpp
|
||||
VNSceneGen.cpp
|
||||
VNSceneItemParser.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(vnscenetool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_INCLUDES}
|
||||
${DAWN_TOOL_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Definitions
|
||||
target_compile_definitions(vnscenetool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_DEFINITIONS}
|
||||
DAWN_TOOL_INSTANCE=VNSceneTool
|
||||
DAWN_TOOL_HEADER="VNSceneTool.hpp"
|
||||
)
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(vnscenetool
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
||||
|
||||
# Tool Function
|
||||
function(tool_vnscene in)
|
||||
set(DEPS "")
|
||||
if(DAWN_BUILD_TOOLS)
|
||||
set(DEPS vnscenetool)
|
||||
endif()
|
||||
|
||||
STRING(REGEX REPLACE "[\.|\\|\/|\:]" "-" scene_name ${in})
|
||||
add_custom_target(scene_${scene_name}
|
||||
COMMAND vnscenetool --input="${in}" --output="${DAWN_GENERATED_DIR}/generatedscenes"
|
||||
COMMENT "Generating vnscene from ${in}"
|
||||
DEPENDS ${DEPS}
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_GENERATED_DIR}/generatedscenes
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} scene_${scene_name})
|
||||
endfunction()
|
233
archive/dawntools/vnscenetool/VNSceneGen.cpp
Normal file
233
archive/dawntools/vnscenetool/VNSceneGen.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneGen.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void VNSceneGen::test(
|
||||
std::string eventName,
|
||||
struct VNSceneEvent *event,
|
||||
int32_t *eventIndex,
|
||||
std::vector<std::string> *eventInit,
|
||||
std::vector<std::string> *eventChain,
|
||||
std::vector<std::string> *includes
|
||||
) {
|
||||
std::string initType = "";
|
||||
std::string toInclude = "";
|
||||
std::string initArgs = "";
|
||||
|
||||
std::vector<std::string> eventInitAfter;
|
||||
|
||||
switch(event->type) {
|
||||
case VN_SCENE_EVENT_TYPE_TEXT:
|
||||
initType = "VNTextEvent";
|
||||
toInclude = "games/vn/events/VNTextEvent.hpp";
|
||||
line(&eventInitAfter, eventName + "->" + "text = " + event->text.texts.begin()->text + ";", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_POSITION:
|
||||
initType = "VNPositionEvent";
|
||||
toInclude = "games/vn/events/VNPositionEvent.hpp";
|
||||
line(&eventInitAfter, eventName + "->item = " + event->position.item + ";", "");
|
||||
if(event->position.x != "") line(&eventInitAfter, eventName + "->" + "to.x = " + event->position.x + ";", "");
|
||||
if(event->position.y != "") line(&eventInitAfter, eventName + "->" + "to.y = " + event->position.y + ";", "");
|
||||
if(event->position.z != "") line(&eventInitAfter, eventName + "->" + "to.z = " + event->position.z + ";", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_SET:
|
||||
initType = "VNSetEvent<" + event->set.type + ">";
|
||||
toInclude = "games/vn/events/VNSetEvent.hpp";
|
||||
line(&eventInitAfter, eventName + "->modifies = &" + event->set.property + ";", "");
|
||||
line(&eventInitAfter, eventName + "->value = " + event->set.to + ";", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_WAIT:
|
||||
initType = "VNWaitEvent";
|
||||
toInclude = "games/vn/events/VNWaitEvent.hpp";
|
||||
line(&eventInitAfter, eventName + "->duration = " + event->wait.duration + ";", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_PARALLEL: {
|
||||
initType = "VNParallelEvent";
|
||||
toInclude = "games/vn/events/VNParallelEvent.hpp";
|
||||
|
||||
auto itParallel = event->parallel.events.events.begin();
|
||||
while(itParallel != event->parallel.events.events.end()) {
|
||||
std::string pEventName = "pEvent" + std::to_string((*eventIndex)++);
|
||||
VNSceneGen::test(
|
||||
pEventName,
|
||||
&(*itParallel),
|
||||
eventIndex,
|
||||
eventInit,
|
||||
eventChain,
|
||||
includes
|
||||
);
|
||||
line(&eventInitAfter, eventName + "->events.push_back(" + pEventName + ");", "");
|
||||
line(&eventInitAfter, "", "");
|
||||
++itParallel;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_MARKER:
|
||||
initType = "VNDummyEvent";
|
||||
toInclude = "games/vn/events/VNDummyEvent.hpp";
|
||||
line(&eventInitAfter, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
|
||||
initType = "VNDummyEvent";
|
||||
toInclude = "games/vn/events/VNDummyEvent.hpp";
|
||||
line(eventChain, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_CHOICES: {
|
||||
initType = "VNChoiceEvent";
|
||||
toInclude = "games/vn/events/VNChoiceEvent.hpp";
|
||||
|
||||
line(&eventInitAfter, eventName + "->key = \"" + event->choices.key+ "\";", "");
|
||||
line(&eventInitAfter, eventName + "->text = " + event->choices.titles.begin()->text + ";", "");
|
||||
auto itChoices = event->choices.choices.begin();
|
||||
while(itChoices != event->choices.choices.end()) {
|
||||
line(&eventInitAfter, eventName + "->choices[\"" + itChoices->value + "\"] = " + itChoices->texts.begin()->text + ";", "");
|
||||
++itChoices;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_CHOICE_SET:
|
||||
initType = "VNChoiceSetEvent";
|
||||
toInclude = "games/vn/events/VNChoiceSetEvent.hpp";
|
||||
line(&eventInitAfter, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
|
||||
line(&eventInitAfter, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
|
||||
break;
|
||||
|
||||
case VN_SCENE_EVENT_TYPE_IF: {
|
||||
initType = "VNIfEvent";
|
||||
toInclude = "games/vn/events/VNIfEvent.hpp";
|
||||
line(&eventInitAfter, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
|
||||
line(&eventInitAfter, eventName + "->value = \"" + event->ifEvent.value + "\";", "");
|
||||
|
||||
std::string ifPrevious = "";
|
||||
std::string ifFirst = "";
|
||||
auto itIf = event->ifEvent.events.events.begin();
|
||||
while(itIf != event->ifEvent.events.events.end()) {
|
||||
std::string ifEventName = "ifEvent" + std::to_string((*eventIndex)++);
|
||||
VNSceneGen::test(
|
||||
ifEventName,
|
||||
&(*itIf),
|
||||
eventIndex,
|
||||
eventInit,
|
||||
eventChain,
|
||||
includes
|
||||
);
|
||||
if(!ifPrevious.empty()) line(eventChain, ifPrevious + "->then(" + ifEventName + ");", "");
|
||||
ifPrevious = ifEventName;
|
||||
if(ifFirst == "") ifFirst = ifEventName;
|
||||
++itIf;
|
||||
}
|
||||
|
||||
if(ifFirst == "" || ifPrevious == "") {
|
||||
std::cout << "If event must have at least one event" << std::endl;
|
||||
assertUnreachable("VNSCeneGen::test: If event must have at least one event");
|
||||
}
|
||||
|
||||
line(eventChain, eventName + "->ifTrue = " + ifFirst + ";", "");
|
||||
line(eventChain, eventName + "->ifEnd = " + ifPrevious + ";", "");
|
||||
break;
|
||||
}
|
||||
|
||||
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";
|
||||
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;
|
||||
assertUnreachable("VNSceneGen::test: Unknown event type");
|
||||
}
|
||||
|
||||
if(!toInclude.empty()) includes->push_back(toInclude);
|
||||
|
||||
line(eventInit, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
|
||||
lines(eventInit, eventInitAfter, "");
|
||||
}
|
||||
|
||||
void VNSceneGen::generate(
|
||||
std::vector<std::string> *out,
|
||||
struct VNScene *scene,
|
||||
std::string tabs
|
||||
) {
|
||||
struct ClassGenInfo classInfo;
|
||||
struct MethodGenInfo methodAssets;
|
||||
struct MethodGenInfo methodInit;
|
||||
|
||||
// Load Scene
|
||||
SceneGenerator::generate(
|
||||
&scene->scene,
|
||||
classInfo,
|
||||
methodAssets,
|
||||
methodInit
|
||||
);
|
||||
|
||||
|
||||
// Events
|
||||
classInfo.includes.push_back("games/vn/events/VNDummyEvent.hpp");
|
||||
line(&methodInit.body, "assertNotNull(vnManager, \"VNSceneGenInit - VN Manager is null?\");", "");
|
||||
line(&methodInit.body, "VNEvent *previous = vnManager->createEvent<VNDummyEvent>();", "");
|
||||
line(&methodInit.body, "auto eventStart = previous;", "");
|
||||
|
||||
int32_t eventIndex = 0;
|
||||
auto itEvents = scene->events.events.begin();
|
||||
std::string previous = "eventStart";
|
||||
|
||||
std::vector<std::string> eventInit;
|
||||
std::vector<std::string> eventChain;
|
||||
|
||||
while(itEvents != scene->events.events.end()) {
|
||||
line(&eventInit, "", "");
|
||||
std::string eventName = "event" + std::to_string(eventIndex++);
|
||||
VNSceneGen::test(
|
||||
eventName,
|
||||
&(*itEvents),
|
||||
&eventIndex,
|
||||
&eventInit,
|
||||
&eventChain,
|
||||
&classInfo.includes
|
||||
);
|
||||
if(!previous.empty()) line(&eventChain, previous + "->then(" + eventName + ");", "");
|
||||
previous = eventName;
|
||||
if(itEvents->type == VN_SCENE_EVENT_TYPE_GOTO_MARKER) previous = "";
|
||||
++itEvents;
|
||||
}
|
||||
|
||||
lines(&methodInit.body, eventInit, "");
|
||||
lines(&methodInit.body, eventChain, "");
|
||||
line(&methodInit.body, "vnManager->setEvent(eventStart);", "");
|
||||
|
||||
// Add in methods
|
||||
CodeGen::methodGen(&classInfo.publicCode, methodAssets);
|
||||
line(&classInfo.publicCode, "", "");
|
||||
CodeGen::methodGen(&classInfo.publicCode, methodInit);
|
||||
|
||||
CodeGen::classGen(out, classInfo);
|
||||
}
|
29
archive/dawntools/vnscenetool/VNSceneGen.hpp
Normal file
29
archive/dawntools/vnscenetool/VNSceneGen.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "VNSceneParser.hpp"
|
||||
#include "util/CodeGen.hpp"
|
||||
#include "util/generator/SceneGenerator.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNSceneGen : public CodeGen {
|
||||
public:
|
||||
static void test(
|
||||
std::string eventName,
|
||||
struct VNSceneEvent *event,
|
||||
int32_t *eventIndex,
|
||||
std::vector<std::string> *eventInit,
|
||||
std::vector<std::string> *eventChain,
|
||||
std::vector<std::string> *includes
|
||||
);
|
||||
|
||||
static void generate(
|
||||
std::vector<std::string> *out,
|
||||
struct VNScene *scene,
|
||||
std::string tabs
|
||||
);
|
||||
};
|
||||
}
|
47
archive/dawntools/vnscenetool/VNSceneItemParser.cpp
Normal file
47
archive/dawntools/vnscenetool/VNSceneItemParser.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneItemParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneItemParser::getRequiredAttributes() {
|
||||
return { "prefab" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneItemParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "ref", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t VNSceneItemParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneItem *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->ref = values["ref"];
|
||||
out->prefab = values["prefab"];
|
||||
|
||||
// Split prefab by / and use the last part as the class name
|
||||
std::string clazz = out->prefab;
|
||||
size_t pos = clazz.find_last_of('/');
|
||||
if(pos != std::string::npos) clazz = clazz.substr(pos+1);
|
||||
out->className = clazz;
|
||||
|
||||
// Make sure prefab and className is not empty
|
||||
if(out->prefab.empty()) {
|
||||
*error = "Prefab cannot be empty.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(out->className.empty()) {
|
||||
*error = "Class name cannot be empty.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
27
archive/dawntools/vnscenetool/VNSceneItemParser.hpp
Normal file
27
archive/dawntools/vnscenetool/VNSceneItemParser.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// 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 VNSceneItem {
|
||||
std::string ref;
|
||||
std::string prefab;
|
||||
std::string className;
|
||||
};
|
||||
|
||||
class VNSceneItemParser : public XmlParser<struct VNSceneItem> {
|
||||
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 VNSceneItem *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
50
archive/dawntools/vnscenetool/VNSceneParser.cpp
Normal file
50
archive/dawntools/vnscenetool/VNSceneParser.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNSceneParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNScene *out,
|
||||
std::string *error
|
||||
) {
|
||||
//
|
||||
int32_t ret;
|
||||
|
||||
// First, pass as a standard scene
|
||||
ret = (SceneParser()).parse(node, &out->scene, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
// Now pass the VN Events
|
||||
auto itChildren = node->childNodes.begin();
|
||||
while(itChildren != node->childNodes.end()) {
|
||||
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
|
||||
++itChildren;
|
||||
continue;
|
||||
}
|
||||
|
||||
Xml *child = itChildren->child;
|
||||
if(child->node != "events") {
|
||||
++itChildren;
|
||||
continue;
|
||||
}
|
||||
ret = (VNSceneEventsParser()).parse(child, &out->events, error);
|
||||
if(ret != 0) return ret;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
28
archive/dawntools/vnscenetool/VNSceneParser.hpp
Normal file
28
archive/dawntools/vnscenetool/VNSceneParser.hpp
Normal 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/parser/SceneParser.hpp"
|
||||
#include "VNSceneItemParser.hpp"
|
||||
#include "events/VNSceneEventsParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNScene {
|
||||
struct Scene scene;
|
||||
struct VNSceneEventList events;
|
||||
};
|
||||
|
||||
class VNSceneParser : public XmlParser<struct VNScene> {
|
||||
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 VNScene *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
65
archive/dawntools/vnscenetool/VNSceneTool.cpp
Normal file
65
archive/dawntools/vnscenetool/VNSceneTool.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneTool.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneTool::getRequiredFlags() {
|
||||
return { "input", "output" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneTool::getOptionalFlags() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t VNSceneTool::start() {
|
||||
File input = File(flags["input"]);
|
||||
if(!input.exists()) {
|
||||
std::cout << "Input file " + input.filename + " does not exist!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string data;
|
||||
if(!input.readString(&data)) {
|
||||
std::cout << "Failed to read input file!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto xml = Xml::load(data);
|
||||
std::string error;
|
||||
struct VNScene scene;
|
||||
auto result = ((VNSceneParser()).parse(&xml, &scene, &error));
|
||||
if(result != 0) {
|
||||
std::cout << "Failed to parse scene: " << error << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generate output
|
||||
std::vector<std::string> outputData;
|
||||
VNSceneGen::generate(&outputData, &scene, "");
|
||||
|
||||
// Load output file from name and type
|
||||
File outputFile = File(flags["output"] + "/vnscenes/" + scene.scene.name + ".hpp");
|
||||
if(!outputFile.mkdirp()) {
|
||||
std::cout << "Failed to create output directory!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Combine vector into single string
|
||||
std::string outputDataStr = "";
|
||||
auto it = outputData.begin();
|
||||
while(it != outputData.end()) {
|
||||
outputDataStr += *it + "\n";
|
||||
++it;
|
||||
}
|
||||
|
||||
if(!outputFile.writeString(outputDataStr)) {
|
||||
std::cout << "Failed to write output file!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
21
archive/dawntools/vnscenetool/VNSceneTool.hpp
Normal file
21
archive/dawntools/vnscenetool/VNSceneTool.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "VNSceneParser.hpp"
|
||||
#include "VNSceneGen.hpp"
|
||||
#include "util/File.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNSceneTool : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
std::map<std::string, std::string> getOptionalFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start();
|
||||
};
|
||||
}
|
22
archive/dawntools/vnscenetool/events/CMakeLists.txt
Normal file
22
archive/dawntools/vnscenetool/events/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(vnscenetool
|
||||
PRIVATE
|
||||
VNMarkerParser.cpp
|
||||
VNSceneEventsParser.cpp
|
||||
VNPositionEventParser.cpp
|
||||
VNTextEventParser.cpp
|
||||
VNSetEventParser.cpp
|
||||
VNWaitEventParser.cpp
|
||||
VNParallelEventParser.cpp
|
||||
VNGoToMarkerEventParser.cpp
|
||||
VNChoiceEventParser.cpp
|
||||
VNChoiceSetEventParser.cpp
|
||||
VNIfEventParser.cpp
|
||||
VNSceneChangeEventParser.cpp
|
||||
VNSetDefaultFontEventParser.cpp
|
||||
)
|
110
archive/dawntools/vnscenetool/events/VNChoiceEventParser.cpp
Normal file
110
archive/dawntools/vnscenetool/events/VNChoiceEventParser.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNChoiceEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNChoiceParser::getRequiredAttributes() {
|
||||
return { "value" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNChoiceParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNChoiceParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNChoice *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
auto itChildren = node->childNodes.begin();
|
||||
while(itChildren != node->childNodes.end()) {
|
||||
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
|
||||
++itChildren;
|
||||
continue;
|
||||
}
|
||||
|
||||
Xml *child = itChildren->child;
|
||||
|
||||
// Parse strings
|
||||
if(child->node == "string") {
|
||||
VNText text;
|
||||
ret = (VNTextParser()).parse(child, &text, error);
|
||||
if(ret != 0) return ret;
|
||||
out->texts.push_back(text);
|
||||
} else {
|
||||
*error = "Unknown child node for choice event '" + child->node + "'";
|
||||
return -1;
|
||||
}
|
||||
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
out->value = values["value"];
|
||||
return 0;
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
std::vector<std::string> VNChoicesEventParser::getRequiredAttributes() {
|
||||
return { "key" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNChoicesEventParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNChoicesEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNChoiceEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
auto itChildren = node->childNodes.begin();
|
||||
while(itChildren != node->childNodes.end()) {
|
||||
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
|
||||
++itChildren;
|
||||
continue;
|
||||
}
|
||||
|
||||
Xml *child = itChildren->child;
|
||||
|
||||
// Parse strings
|
||||
if(child->node == "title") {
|
||||
auto itChildren2 = child->childNodes.begin();
|
||||
while(itChildren2 != child->childNodes.end()) {
|
||||
if(itChildren2->nodeType != XML_NODE_TYPE_ELEMENT) {
|
||||
++itChildren2;
|
||||
continue;
|
||||
}
|
||||
|
||||
VNText text;
|
||||
ret = (VNTextParser()).parse(itChildren2->child, &text, error);
|
||||
if(ret != 0) return ret;
|
||||
out->titles.push_back(text);
|
||||
++itChildren2;
|
||||
}
|
||||
|
||||
} else if(child->node == "choice") {
|
||||
VNChoice choice;
|
||||
ret = (VNChoiceParser()).parse(child, &choice, error);
|
||||
if(ret != 0) return ret;
|
||||
out->choices.push_back(choice);
|
||||
|
||||
} else {
|
||||
*error = "Unknown child node for choices event '" + child->node + "'";
|
||||
return -1;
|
||||
}
|
||||
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
out->key = values["key"];
|
||||
return 0;
|
||||
}
|
44
archive/dawntools/vnscenetool/events/VNChoiceEventParser.hpp
Normal file
44
archive/dawntools/vnscenetool/events/VNChoiceEventParser.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "VNTextEventParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNChoice {
|
||||
std::vector<struct VNText> texts;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct VNChoiceEvent {
|
||||
std::vector<struct VNText> titles;
|
||||
std::vector<struct VNChoice> choices;
|
||||
std::string key;
|
||||
};
|
||||
|
||||
class VNChoiceParser : public XmlParser<struct VNChoice> {
|
||||
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 VNChoice *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
|
||||
class VNChoicesEventParser : public XmlParser<struct VNChoiceEvent> {
|
||||
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 VNChoiceEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNChoiceSetEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNChoiceSetEventParser::getRequiredAttributes() {
|
||||
return { "key", "value" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNChoiceSetEventParser::getOptionalAttributes() {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t VNChoiceSetEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNChoiceSetEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->key = values["key"];
|
||||
out->value = values["value"];
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// 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 VNChoiceSetEvent {
|
||||
std::string key;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class VNChoiceSetEventParser : public XmlParser<VNChoiceSetEvent> {
|
||||
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 VNChoiceSetEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNGoToMarkerEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNGoToMarkerEventParser::getRequiredAttributes() {
|
||||
return { "name" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNGoToMarkerEventParser::getOptionalAttributes() {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t VNGoToMarkerEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNGoToMarkerEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->name = values["name"];
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// 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 VNGoToMarkerEvent {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class VNGoToMarkerEventParser : public XmlParser<struct VNGoToMarkerEvent> {
|
||||
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 VNGoToMarkerEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
30
archive/dawntools/vnscenetool/events/VNIfEventParser.cpp
Normal file
30
archive/dawntools/vnscenetool/events/VNIfEventParser.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNIfEventParser.hpp"
|
||||
#include "VNSceneEventsParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNIfEventParser::getRequiredAttributes() {
|
||||
return { "key", "value" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNIfEventParser::getOptionalAttributes() {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t VNIfEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNIfEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
//Get the key and value
|
||||
out->key = values["key"];
|
||||
out->value = values["value"];
|
||||
|
||||
return (VNSceneEventsParser()).parse(node, &out->events, error);
|
||||
}
|
23
archive/dawntools/vnscenetool/events/VNIfEventParser.hpp
Normal file
23
archive/dawntools/vnscenetool/events/VNIfEventParser.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
// 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 VNIfEvent;
|
||||
|
||||
class VNIfEventParser : public XmlParser<struct VNIfEvent> {
|
||||
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 VNIfEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
32
archive/dawntools/vnscenetool/events/VNMarkerParser.cpp
Normal file
32
archive/dawntools/vnscenetool/events/VNMarkerParser.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNMarkerParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNMarkerParser::getRequiredAttributes() {
|
||||
return { "name" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNMarkerParser::getOptionalAttributes() {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t VNMarkerParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNMarker *out,
|
||||
std::string *error
|
||||
) {
|
||||
// Ensure name only contains letters, and numbers, no spaces or symbols
|
||||
if(!std::regex_match(values["name"], std::regex("^[a-zA-Z0-9]+$"))) {
|
||||
*error = "Marker name " + values["name"] + " must only contain letters and numbers.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
out->name = values["name"];
|
||||
return 0;
|
||||
}
|
26
archive/dawntools/vnscenetool/events/VNMarkerParser.hpp
Normal file
26
archive/dawntools/vnscenetool/events/VNMarkerParser.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/XmlParser.hpp"
|
||||
#include <regex>
|
||||
|
||||
namespace Dawn {
|
||||
struct VNMarker {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class VNMarkerParser : public XmlParser<struct VNMarker> {
|
||||
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 VNMarker *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNParallelEventParser.hpp"
|
||||
#include "VNSceneEventsParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNParallelEventParser::getRequiredAttributes() {
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNParallelEventParser::getOptionalAttributes() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t VNParallelEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNParallelEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
// Parse all children
|
||||
return (VNSceneEventsParser()).parse(node, &out->events, error);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// 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 VNParallelEvent;
|
||||
|
||||
class VNParallelEventParser : public XmlParser<struct VNParallelEvent> {
|
||||
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 VNParallelEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNPositionEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNPositionEventParser::getRequiredAttributes() {
|
||||
return { "item" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNPositionEventParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "x", "" },
|
||||
{ "y", "" },
|
||||
{ "z", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t VNPositionEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNPositionEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->x = values["x"];
|
||||
out->y = values["y"];
|
||||
out->z = values["z"];
|
||||
out->item = values["item"];
|
||||
return 0;
|
||||
}
|
@ -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 VNPositionEvent {
|
||||
std::string x = "";
|
||||
std::string y = "";
|
||||
std::string z = "";
|
||||
std::string item = "";
|
||||
};
|
||||
|
||||
class VNPositionEventParser : public XmlParser<struct VNPositionEvent> {
|
||||
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 VNPositionEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneChangeEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneChangeEventParser::getRequiredAttributes() {
|
||||
return { "scene" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneChangeEventParser::getOptionalAttributes() {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t VNSceneChangeEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneChangeEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->include = values["scene"] + ".hpp";
|
||||
|
||||
// Find last slash and take all string after that
|
||||
size_t lastSlash = values["scene"].find_last_of('/');
|
||||
if(lastSlash != std::string::npos) {
|
||||
out->scene = values["scene"].substr(lastSlash+1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// 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 VNSceneChangeEvent {
|
||||
std::string scene;
|
||||
std::string include;
|
||||
};
|
||||
|
||||
class VNSceneChangeEventParser : public XmlParser<struct VNSceneChangeEvent> {
|
||||
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 VNSceneChangeEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
109
archive/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
Normal file
109
archive/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneEventsParser.hpp"
|
||||
#include "VNParallelEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneEventsParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneEventsParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNSceneEventsParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneEventList *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
|
||||
auto itChildren = node->childNodes.begin();
|
||||
while(itChildren != node->childNodes.end()) {
|
||||
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
|
||||
++itChildren;
|
||||
continue;
|
||||
}
|
||||
|
||||
Xml *child = itChildren->child;
|
||||
struct VNSceneEvent event;
|
||||
|
||||
// Parse event(s)
|
||||
if(child->node == "text") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_TEXT;
|
||||
ret = (VNTextEventParser()).parse(child, &event.text, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "position") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_POSITION;
|
||||
ret = (VNPositionEventParser()).parse(child, &event.position, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "set") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_SET;
|
||||
ret = (VNSetEventParser()).parse(child, &event.set, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "wait") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_WAIT;
|
||||
ret = (VNWaitEventParser()).parse(child, &event.wait, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "parallel") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_PARALLEL;
|
||||
ret = (VNParallelEventParser()).parse(child, &event.parallel, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "marker") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_MARKER;
|
||||
ret = (VNMarkerParser()).parse(child, &event.marker, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "goto-marker") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_GOTO_MARKER;
|
||||
ret = (VNGoToMarkerEventParser()).parse(child, &event.gotoMarker, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "choices") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_CHOICES;
|
||||
ret = (VNChoicesEventParser()).parse(child, &event.choices, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "choice-set") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_CHOICE_SET;
|
||||
ret = (VNChoiceSetEventParser()).parse(child, &event.choiceSet, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "if") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_IF;
|
||||
ret = (VNIfEventParser()).parse(child, &event.ifEvent, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "scene-change") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_SCENE_CHANGE;
|
||||
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;
|
||||
}
|
||||
|
||||
if(ret != 0) return ret;
|
||||
out->events.push_back(event);
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
80
archive/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
Normal file
80
archive/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
Normal file
@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "VNTextEventParser.hpp"
|
||||
#include "VNPositionEventParser.hpp"
|
||||
#include "VNSetEventParser.hpp"
|
||||
#include "VNWaitEventParser.hpp"
|
||||
#include "VNParallelEventParser.hpp"
|
||||
#include "VNMarkerParser.hpp"
|
||||
#include "VNGoToMarkerEventParser.hpp"
|
||||
#include "VNChoiceEventParser.hpp"
|
||||
#include "VNChoiceSetEventParser.hpp"
|
||||
#include "VNIfEventParser.hpp"
|
||||
#include "VNSceneChangeEventParser.hpp"
|
||||
#include "VNSetDefaultFontEventParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNSceneEvent;
|
||||
|
||||
struct VNSceneEventList {
|
||||
std::vector<struct VNSceneEvent> events;
|
||||
};
|
||||
|
||||
enum VNSceneEventType {
|
||||
VN_SCENE_EVENT_TYPE_TEXT,
|
||||
VN_SCENE_EVENT_TYPE_POSITION,
|
||||
VN_SCENE_EVENT_TYPE_SET,
|
||||
VN_SCENE_EVENT_TYPE_WAIT,
|
||||
VN_SCENE_EVENT_TYPE_PARALLEL,
|
||||
VN_SCENE_EVENT_TYPE_MARKER,
|
||||
VN_SCENE_EVENT_TYPE_GOTO_MARKER,
|
||||
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_SET_DEFAULT_FONT
|
||||
};
|
||||
|
||||
struct VNParallelEvent {
|
||||
struct VNSceneEventList events;
|
||||
};
|
||||
|
||||
struct VNIfEvent {
|
||||
std::string key;
|
||||
std::string value;
|
||||
struct VNSceneEventList events;
|
||||
};
|
||||
|
||||
struct VNSceneEvent {
|
||||
enum VNSceneEventType type;
|
||||
|
||||
struct VNTextEvent text;
|
||||
struct VNPositionEvent position;
|
||||
struct VNSetEvent set;
|
||||
struct VNWaitEvent wait;
|
||||
struct VNParallelEvent parallel;
|
||||
struct VNMarker marker;
|
||||
struct VNGoToMarkerEvent gotoMarker;
|
||||
struct VNChoiceEvent choices;
|
||||
struct VNChoiceSetEvent choiceSet;
|
||||
struct VNIfEvent ifEvent;
|
||||
struct VNSceneChangeEvent sceneChange;
|
||||
struct VNSetFont setDefaultFont;
|
||||
};
|
||||
|
||||
class VNSceneEventsParser : public XmlParser<struct VNSceneEventList> {
|
||||
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 VNSceneEventList *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
};
|
||||
}
|
39
archive/dawntools/vnscenetool/events/VNSetEventParser.cpp
Normal file
39
archive/dawntools/vnscenetool/events/VNSetEventParser.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSetEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSetEventParser::getRequiredAttributes() {
|
||||
return { "property", "type" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSetEventParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "to", "" },
|
||||
{ "value", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t VNSetEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSetEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
if(values["to"] != "") {
|
||||
out->to = values["to"];
|
||||
} else if(values["value"] != "") {
|
||||
out->to = values["value"];
|
||||
} else {
|
||||
*error = "Either 'to' or 'value' must be specified";
|
||||
return -1;
|
||||
}
|
||||
|
||||
out->type = values["type"];
|
||||
out->property = values["property"];
|
||||
return 0;
|
||||
}
|
27
archive/dawntools/vnscenetool/events/VNSetEventParser.hpp
Normal file
27
archive/dawntools/vnscenetool/events/VNSetEventParser.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// 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 VNSetEvent {
|
||||
std::string property = "";
|
||||
std::string to = "";
|
||||
std::string type = "";
|
||||
};
|
||||
|
||||
class VNSetEventParser : public XmlParser<struct VNSetEvent> {
|
||||
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 VNSetEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
82
archive/dawntools/vnscenetool/events/VNTextEventParser.cpp
Normal file
82
archive/dawntools/vnscenetool/events/VNTextEventParser.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNTextEventParser.hpp"
|
||||
#include "util/parser/TypeParsers.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNTextParser::getRequiredAttributes() {
|
||||
return { "lang" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNTextParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNTextParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNText *out,
|
||||
std::string *error
|
||||
) {
|
||||
std::string innerXml = node->innerXml;
|
||||
|
||||
// Split by newlines, then trim each line.
|
||||
std::vector<std::string> lines = stringSplit(innerXml, "\n");
|
||||
std::vector<std::string> finalLines;
|
||||
for(auto it = lines.begin(); it != lines.end(); ++it) {
|
||||
auto newLine = stringTrim(*it);
|
||||
if(newLine.length() > 0) finalLines.push_back(newLine);
|
||||
}
|
||||
std::string finalXml = stringJoin(finalLines, "\n");
|
||||
|
||||
out->language = values["lang"];
|
||||
out->text = stringParser(finalXml, error);
|
||||
return error->length() == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
std::vector<std::string> VNTextEventParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNTextEventParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNTextEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNTextEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
auto itChildren = node->childNodes.begin();
|
||||
while(itChildren != node->childNodes.end()) {
|
||||
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
|
||||
++itChildren;
|
||||
continue;
|
||||
}
|
||||
|
||||
Xml *child = itChildren->child;
|
||||
|
||||
// Parse strings
|
||||
if(child->node == "string") {
|
||||
VNText text;
|
||||
ret = (VNTextParser()).parse(child, &text, error);
|
||||
if(ret != 0) return ret;
|
||||
out->texts.push_back(text);
|
||||
} else {
|
||||
*error = "Unknown child node for text event '" + child->node + "'";
|
||||
return -1;
|
||||
}
|
||||
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
42
archive/dawntools/vnscenetool/events/VNTextEventParser.hpp
Normal file
42
archive/dawntools/vnscenetool/events/VNTextEventParser.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
// 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 VNText {
|
||||
std::string language;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct VNTextEvent {
|
||||
std::vector<VNText> texts;
|
||||
};
|
||||
|
||||
class VNTextParser : public XmlParser<struct VNText> {
|
||||
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 VNText *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
|
||||
class VNTextEventParser : public XmlParser<struct VNTextEvent> {
|
||||
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 VNTextEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
35
archive/dawntools/vnscenetool/events/VNWaitEventParser.cpp
Normal file
35
archive/dawntools/vnscenetool/events/VNWaitEventParser.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNWaitEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNWaitEventParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNWaitEventParser::getOptionalAttributes() {
|
||||
return { { "duration", "" }, { "time", "" } };
|
||||
}
|
||||
|
||||
int32_t VNWaitEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
VNWaitEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
//Get the duration
|
||||
if(!values["duration"].empty()) {
|
||||
out->duration = values["duration"];
|
||||
} else if(!values["time"].empty()) {
|
||||
out->duration = values["time"];
|
||||
} else {
|
||||
*error = "No duration specified.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
25
archive/dawntools/vnscenetool/events/VNWaitEventParser.hpp
Normal file
25
archive/dawntools/vnscenetool/events/VNWaitEventParser.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
// 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 VNWaitEvent {
|
||||
std::string duration;
|
||||
};
|
||||
|
||||
class VNWaitEventParser : public XmlParser<VNWaitEvent> {
|
||||
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,
|
||||
VNWaitEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user