From 5ce9e1ea5df0a74125e55ba0ed4938b9f1ce96b4 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 25 Apr 2023 18:22:55 -0700 Subject: [PATCH] Marker progress --- src/dawntools/vnscenetool/VNSceneGen.cpp | 6 ++++ .../vnscenetool/events/CMakeLists.txt | 1 + .../events/VNGoToMarkerEventParser.cpp | 26 +++++++++++++++ .../events/VNGoToMarkerEventParser.hpp | 25 +++++++++++++++ .../vnscenetool/events/VNMarkerParser.cpp | 32 +++++++++++++++++++ .../vnscenetool/events/VNMarkerParser.hpp | 1 + .../events/VNSceneEventsParser.cpp | 5 +++ .../events/VNSceneEventsParser.hpp | 5 ++- 8 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.cpp create mode 100644 src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.hpp create mode 100644 src/dawntools/vnscenetool/events/VNMarkerParser.cpp diff --git a/src/dawntools/vnscenetool/VNSceneGen.cpp b/src/dawntools/vnscenetool/VNSceneGen.cpp index 83a7c999..0c70a001 100644 --- a/src/dawntools/vnscenetool/VNSceneGen.cpp +++ b/src/dawntools/vnscenetool/VNSceneGen.cpp @@ -71,6 +71,12 @@ void VNSceneGen::test( break; } + case VN_SCENE_EVENT_TYPE_MARKER: + initType = "VNDummyEvent"; + toInclude = "games/vn/events/VNDummyEvent.hpp"; + line(&afterLines, "auto marker_" + event->marker.name + " = " + eventName + ";", ""); + break; + default: std::cout << "Unknown event type: " << event->type << std::endl; assertUnreachable(); diff --git a/src/dawntools/vnscenetool/events/CMakeLists.txt b/src/dawntools/vnscenetool/events/CMakeLists.txt index 9703f802..42d57e61 100644 --- a/src/dawntools/vnscenetool/events/CMakeLists.txt +++ b/src/dawntools/vnscenetool/events/CMakeLists.txt @@ -6,6 +6,7 @@ # Sources target_sources(vnscenetool PRIVATE + VNMarkerParser.cpp VNSceneEventsParser.cpp VNPositionEventParser.cpp VNTextEventParser.cpp diff --git a/src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.cpp b/src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.cpp new file mode 100644 index 00000000..3aa025c3 --- /dev/null +++ b/src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.cpp @@ -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 VNGoToMarkerEventParser::getRequiredAttributes() { + return { "name" }; +} + +std::map VNGoToMarkerEventParser::getOptionalAttributes() { + return {}; +} + +int32_t VNGoToMarkerEventParser::onParse( + Xml *node, + std::map values, + struct VNGoToMarkerEvent *out, + std::string *error +) { + out->name = values["name"]; + return 0; +} \ No newline at end of file diff --git a/src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.hpp b/src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.hpp new file mode 100644 index 00000000..e44d0630 --- /dev/null +++ b/src/dawntools/vnscenetool/events/VNGoToMarkerEventParser.hpp @@ -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 { + protected: + std::vector getRequiredAttributes() override; + std::map getOptionalAttributes() override; + int32_t onParse( + Xml *node, + std::map values, + struct VNGoToMarkerEvent *out, + std::string *error + ) override; + }; +} \ No newline at end of file diff --git a/src/dawntools/vnscenetool/events/VNMarkerParser.cpp b/src/dawntools/vnscenetool/events/VNMarkerParser.cpp new file mode 100644 index 00000000..93921925 --- /dev/null +++ b/src/dawntools/vnscenetool/events/VNMarkerParser.cpp @@ -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 VNMarkerParser::getRequiredAttributes() { + return { "name" }; +} + +std::map VNMarkerParser::getOptionalAttributes() { + return {}; +} + +int32_t VNMarkerParser::onParse( + Xml *node, + std::map 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; +} \ No newline at end of file diff --git a/src/dawntools/vnscenetool/events/VNMarkerParser.hpp b/src/dawntools/vnscenetool/events/VNMarkerParser.hpp index f9b05c68..8fcc7840 100644 --- a/src/dawntools/vnscenetool/events/VNMarkerParser.hpp +++ b/src/dawntools/vnscenetool/events/VNMarkerParser.hpp @@ -5,6 +5,7 @@ #pragma once #include "util/XmlParser.hpp" +#include namespace Dawn { struct VNMarker { diff --git a/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp b/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp index e4c6ab34..51dd7532 100644 --- a/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp +++ b/src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp @@ -55,6 +55,11 @@ int32_t VNSceneEventsParser::onParse( 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 { *error = "Unknown child node '" + child->node + "'"; return -1; diff --git a/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp b/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp index 77f83642..49698b49 100644 --- a/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp +++ b/src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp @@ -9,6 +9,7 @@ #include "VNSetEventParser.hpp" #include "VNWaitEventParser.hpp" #include "VNParallelEventParser.hpp" +#include "VNMarkerParser.hpp" namespace Dawn { struct VNSceneEvent; @@ -22,7 +23,8 @@ namespace Dawn { VN_SCENE_EVENT_TYPE_POSITION, VN_SCENE_EVENT_TYPE_SET, VN_SCENE_EVENT_TYPE_WAIT, - VN_SCENE_EVENT_TYPE_PARALLEL + VN_SCENE_EVENT_TYPE_PARALLEL, + VN_SCENE_EVENT_TYPE_MARKER }; struct VNParallelEvent { @@ -37,6 +39,7 @@ namespace Dawn { struct VNSetEvent set; struct VNWaitEvent wait; struct VNParallelEvent parallel; + struct VNMarker marker; }; class VNSceneEventsParser : public XmlParser {