First real pass at VN Event Parsing
This commit is contained in:
		@@ -18,6 +18,7 @@ target_sources(vnscenetool
 | 
			
		||||
    VNSceneTool.cpp
 | 
			
		||||
    VNSceneParser.cpp
 | 
			
		||||
    VNSceneEventsParser.cpp
 | 
			
		||||
    VNSceneGen.cpp
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Includes
 | 
			
		||||
@@ -49,15 +50,15 @@ function(tool_vnscene in)
 | 
			
		||||
    set(DEPS vnscenetool)
 | 
			
		||||
  endif()
 | 
			
		||||
 | 
			
		||||
  STRING(REGEX REPLACE "[\.|\\|\/]" "-" prefab_name ${in})
 | 
			
		||||
  add_custom_target(prefab_${prefab_name}
 | 
			
		||||
    COMMAND vnscenetool --input="${DAWN_ASSETS_SOURCE_DIR}/${in}"
 | 
			
		||||
  STRING(REGEX REPLACE "[\.|\\|\/]" "-" scene_name ${in})
 | 
			
		||||
  add_custom_target(scene_${scene_name}
 | 
			
		||||
    COMMAND vnscenetool --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_GENERATED_DIR}/generatedscenes"
 | 
			
		||||
    COMMENT "Generating prefab from ${in}"
 | 
			
		||||
    DEPENDS ${DEPS}
 | 
			
		||||
  )
 | 
			
		||||
  target_include_directories(${DAWN_TARGET_NAME}
 | 
			
		||||
    PUBLIC
 | 
			
		||||
      ${DAWN_GENERATED_DIR}/generatedprefabs
 | 
			
		||||
      ${DAWN_GENERATED_DIR}/generatedscenes
 | 
			
		||||
  )
 | 
			
		||||
  add_dependencies(${DAWN_TARGET_NAME} prefab_${prefab_name})
 | 
			
		||||
  add_dependencies(${DAWN_TARGET_NAME} scene_${scene_name})
 | 
			
		||||
endfunction()
 | 
			
		||||
@@ -18,7 +18,7 @@ std::map<std::string, std::string> VNSceneEventsParser::getOptionalAttributes()
 | 
			
		||||
int32_t VNSceneEventsParser::onParse(
 | 
			
		||||
  Xml *node,
 | 
			
		||||
  std::map<std::string, std::string> values,
 | 
			
		||||
  struct VNSceneEvent *out,
 | 
			
		||||
  struct VNSceneEventList *out,
 | 
			
		||||
  std::string *error
 | 
			
		||||
) {
 | 
			
		||||
  int32_t ret;
 | 
			
		||||
@@ -26,15 +26,28 @@ int32_t VNSceneEventsParser::onParse(
 | 
			
		||||
  auto itChildren = node->children.begin();
 | 
			
		||||
  while(itChildren != node->children.end()) {
 | 
			
		||||
    Xml *child = *itChildren;
 | 
			
		||||
    struct VNSceneEvent event;
 | 
			
		||||
 | 
			
		||||
    // Parse event(s)
 | 
			
		||||
    if(child->node == "position") {
 | 
			
		||||
      struct VNPosition position;
 | 
			
		||||
      ret = (VNPositionParser()).parse(child, &position, error);
 | 
			
		||||
    if(child->node == "text") {
 | 
			
		||||
      VNTextEventParser parser;
 | 
			
		||||
      event.type = VN_SCENE_EVENT_TYPE_TEXT;
 | 
			
		||||
      ret = (VNTextEventParser()).parse(child, &event.text, error);
 | 
			
		||||
      if(ret != 0) return ret;
 | 
			
		||||
      out->position = position;
 | 
			
		||||
    
 | 
			
		||||
    } else if(child->node == "position") {
 | 
			
		||||
      VNPositionEventParser parser;
 | 
			
		||||
      event.type = VN_SCENE_EVENT_TYPE_POSITION;
 | 
			
		||||
      ret = (VNPositionEventParser()).parse(child, &event.position, 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++;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,22 +4,34 @@
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "util/XmlParser.hpp"
 | 
			
		||||
#include "events/VNPositionParser.hpp"
 | 
			
		||||
#include "events/VNTextEventParser.hpp"
 | 
			
		||||
#include "events/VNPositionEventParser.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  struct VNSceneEvent {
 | 
			
		||||
    int32_t bruh;
 | 
			
		||||
  enum VNSceneEventType {
 | 
			
		||||
    VN_SCENE_EVENT_TYPE_TEXT,
 | 
			
		||||
    VN_SCENE_EVENT_TYPE_POSITION
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  class VNSceneEventsParser : public XmlParser<struct VNSceneEvent> {
 | 
			
		||||
  struct VNSceneEvent {
 | 
			
		||||
    enum VNSceneEventType type;
 | 
			
		||||
    
 | 
			
		||||
    struct VNTextEvent text;
 | 
			
		||||
    struct VNPositionEvent position;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  struct VNSceneEventList {
 | 
			
		||||
    std::vector<struct VNSceneEvent> events;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  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 VNSceneEvent *out,
 | 
			
		||||
        struct VNSceneEventList *out,
 | 
			
		||||
        std::string *error
 | 
			
		||||
      ) override;
 | 
			
		||||
  };
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										106
									
								
								src/dawntools/vnscenetool/VNSceneGen.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								src/dawntools/vnscenetool/VNSceneGen.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,106 @@
 | 
			
		||||
// 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::generate(
 | 
			
		||||
  std::vector<std::string> *out,
 | 
			
		||||
  struct VNScene *scene,
 | 
			
		||||
  std::string tabs
 | 
			
		||||
) {
 | 
			
		||||
  struct ClassGenInfo classInfo;
 | 
			
		||||
  classInfo.clazz = "TestScene";
 | 
			
		||||
  classInfo.extend = "Scene";
 | 
			
		||||
  classInfo.constructorArgs = "DawnGame *game";
 | 
			
		||||
  classInfo.extendArgs = "game";
 | 
			
		||||
 | 
			
		||||
  classInfo.includes.push_back("scene/Scene.hpp");
 | 
			
		||||
 | 
			
		||||
  struct MethodGenInfo methodAssets;
 | 
			
		||||
  methodAssets.name = "getRequiredAssets";
 | 
			
		||||
  methodAssets.isOverride = true;
 | 
			
		||||
  methodAssets.type = "std::vector<Asset*>";
 | 
			
		||||
  line(&methodAssets.body, "auto assMan = &this->game->assetManager;", "");
 | 
			
		||||
  line(&methodAssets.body, "std::vector<Asset*> assets;", "");
 | 
			
		||||
  line(&methodAssets.body, "return assets;", "");
 | 
			
		||||
 | 
			
		||||
  struct MethodGenInfo methodStage;
 | 
			
		||||
  methodStage.name = "stage";
 | 
			
		||||
  methodStage.isOverride = "true";
 | 
			
		||||
  line(&methodStage.body, "// test", "");
 | 
			
		||||
 | 
			
		||||
  // TEST
 | 
			
		||||
  line(&methodStage.body, "auto canvas = UICanvas::create(this);", "");
 | 
			
		||||
  line(&methodStage.body, "", "");
 | 
			
		||||
 | 
			
		||||
  classInfo.includes.push_back("scene/components/display/Camera.hpp");
 | 
			
		||||
  line(&methodStage.body, "auto camera = Camera::create(this);", "");
 | 
			
		||||
  line(&methodStage.body, "camera->fov = 0.436332f;", "");
 | 
			
		||||
  line(&methodStage.body, "camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));", "");
 | 
			
		||||
  line(&methodStage.body, "", "");
 | 
			
		||||
 | 
			
		||||
  classInfo.includes.push_back("prefabs/SimpleSpinningCubePrefab.hpp");
 | 
			
		||||
  line(&methodStage.body, "auto cube = SimpleSpinningCubePrefab::create(this);", "");
 | 
			
		||||
  line(&methodStage.body, "", "");
 | 
			
		||||
 | 
			
		||||
  // Events
 | 
			
		||||
  classInfo.includes.push_back("games/vn/components/VNManager.hpp");
 | 
			
		||||
  line(&methodStage.body, "auto vnItem = this->createSceneItem();", "");
 | 
			
		||||
  line(&methodStage.body, "auto vnManager = vnItem->addComponent<VNManager>();", "");
 | 
			
		||||
  line(&methodStage.body, "VNEvent *previous = vnManager->createEvent<VNDummyEvent>();", "");
 | 
			
		||||
  line(&methodStage.body, "auto eventStart = previous;", "");
 | 
			
		||||
 | 
			
		||||
  int32_t eventIndex = 0;
 | 
			
		||||
  auto itEvents = scene->events.events.begin();
 | 
			
		||||
  while(itEvents != scene->events.events.end()) {
 | 
			
		||||
    std::string eventName = "event" + std::to_string(eventIndex);
 | 
			
		||||
    std::string initType = "";
 | 
			
		||||
    std::string initArgs = "";
 | 
			
		||||
    std::string prev = "previous";
 | 
			
		||||
    std::vector<std::string> afterLines;
 | 
			
		||||
 | 
			
		||||
    switch(itEvents->type) {
 | 
			
		||||
      case VN_SCENE_EVENT_TYPE_TEXT:
 | 
			
		||||
        initType = "VNTextEvent";
 | 
			
		||||
        line(&afterLines, eventName + "->" + "text = \"" + itEvents->text.texts.begin()->text + "\";", "");
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case VN_SCENE_EVENT_TYPE_POSITION:
 | 
			
		||||
        initType = "VNPositionEvent";
 | 
			
		||||
        line(&afterLines, eventName + "->item = " + itEvents->position.item + ";", "");
 | 
			
		||||
        if(itEvents->position.x != "") line(&afterLines, eventName + "->" + "to.x = " + itEvents->position.x + ";", "");
 | 
			
		||||
        if(itEvents->position.y != "") line(&afterLines, eventName + "->" + "to.y = " + itEvents->position.y + ";", "");
 | 
			
		||||
        if(itEvents->position.z != "") line(&afterLines, eventName + "->" + "to.z = " + itEvents->position.z + ";", "");
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      default:
 | 
			
		||||
        assertUnreachable();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    line(&methodStage.body, "", "");
 | 
			
		||||
    line(
 | 
			
		||||
      &methodStage.body,
 | 
			
		||||
      "auto " + eventName + " = " + prev + "->then(vnManager->createEvent<" + initType + ">(" + initArgs + "));",
 | 
			
		||||
      ""
 | 
			
		||||
    );
 | 
			
		||||
    line(&methodStage.body, "previous = " + eventName + ";", "");
 | 
			
		||||
    lines(&methodStage.body, afterLines, "");
 | 
			
		||||
    
 | 
			
		||||
    eventIndex++;
 | 
			
		||||
    ++itEvents;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  line(&methodStage.body, "", "");
 | 
			
		||||
  line(&methodStage.body, "vnManager->setEvent(eventStart);", "");
 | 
			
		||||
 | 
			
		||||
  // Add in methods
 | 
			
		||||
  CodeGen::methodGen(&classInfo.protectedCode, methodAssets);
 | 
			
		||||
  line(&classInfo.protectedCode, "", "");
 | 
			
		||||
  CodeGen::methodGen(&classInfo.protectedCode, methodStage);
 | 
			
		||||
 | 
			
		||||
  CodeGen::classGen(out, classInfo);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								src/dawntools/vnscenetool/VNSceneGen.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/dawntools/vnscenetool/VNSceneGen.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
// 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"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class VNSceneGen : public CodeGen {
 | 
			
		||||
    public:
 | 
			
		||||
      static void generate(
 | 
			
		||||
        std::vector<std::string> *out,
 | 
			
		||||
        struct VNScene *scene,
 | 
			
		||||
        std::string tabs
 | 
			
		||||
      );
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -30,13 +30,9 @@ int32_t VNSceneParser::onParse(
 | 
			
		||||
 | 
			
		||||
    // Parse event(s)
 | 
			
		||||
    if(child->node == "events") {
 | 
			
		||||
      struct VNSceneEvent scene;
 | 
			
		||||
      ret = (VNSceneEventsParser()).parse(child, &scene, error);
 | 
			
		||||
      ret = (VNSceneEventsParser()).parse(child, &out->events, error);
 | 
			
		||||
      if(ret != 0) return ret;
 | 
			
		||||
      out->events.push_back(scene);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    itChildren++;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  struct VNScene {
 | 
			
		||||
    std::vector<struct VNSceneEvent> events;
 | 
			
		||||
    struct VNSceneEventList events;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  class VNSceneParser : public XmlParser<struct VNScene> {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> VNSceneTool::getRequiredFlags() {
 | 
			
		||||
  return { "input" };
 | 
			
		||||
  return { "input", "output" };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::map<std::string, std::string> VNSceneTool::getOptionalFlags() {
 | 
			
		||||
@@ -38,6 +38,28 @@ int32_t VNSceneTool::start() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Generate output
 | 
			
		||||
  std::vector<std::string> outputData;
 | 
			
		||||
  VNSceneGen::generate(&outputData, &scene, "");
 | 
			
		||||
 | 
			
		||||
  // Load output file from name and type
 | 
			
		||||
  File outputFile = File(flags["output"] + "/vnscenes/TestScene.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;
 | 
			
		||||
}
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "util/DawnTool.hpp"
 | 
			
		||||
#include "VNSceneParser.hpp"
 | 
			
		||||
#include "VNSceneGen.hpp"
 | 
			
		||||
#include "util/File.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,5 +6,6 @@
 | 
			
		||||
# Sources
 | 
			
		||||
target_sources(vnscenetool
 | 
			
		||||
  PRIVATE
 | 
			
		||||
    VNPositionParser.cpp
 | 
			
		||||
    VNPositionEventParser.cpp
 | 
			
		||||
    VNTextEventParser.cpp
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										33
									
								
								src/dawntools/vnscenetool/events/VNPositionEventParser.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/dawntools/vnscenetool/events/VNPositionEventParser.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								src/dawntools/vnscenetool/events/VNPositionEventParser.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/dawntools/vnscenetool/events/VNPositionEventParser.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/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;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#include "VNPositionParser.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> VNPositionParser::getRequiredAttributes() {
 | 
			
		||||
  return { };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::map<std::string, std::string> VNPositionParser::getOptionalAttributes() {
 | 
			
		||||
  return { };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int32_t VNPositionParser::onParse(
 | 
			
		||||
  Xml *node,
 | 
			
		||||
  std::map<std::string, std::string> values,
 | 
			
		||||
  struct VNPosition *out,
 | 
			
		||||
  std::string *error
 | 
			
		||||
) {
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +0,0 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
							
								
								
									
										43
									
								
								src/dawntools/vnscenetool/events/VNTextEventParser.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/dawntools/vnscenetool/events/VNTextEventParser.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#include "VNTextEventParser.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
) {
 | 
			
		||||
  auto itChildren = node->children.begin();
 | 
			
		||||
  while(itChildren != node->children.end()) {
 | 
			
		||||
    Xml *child = *itChildren;
 | 
			
		||||
 | 
			
		||||
    // Parse strings
 | 
			
		||||
    if(child->node == "string") {
 | 
			
		||||
      VNText text;
 | 
			
		||||
      text.language = child->attributes["lang"];
 | 
			
		||||
      text.text = child->value;
 | 
			
		||||
      out->texts.push_back(text);
 | 
			
		||||
    } else {
 | 
			
		||||
      *error = "Unknown child node '" + child->node + "'";
 | 
			
		||||
      return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    itChildren++;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								src/dawntools/vnscenetool/events/VNTextEventParser.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/dawntools/vnscenetool/events/VNTextEventParser.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
// 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 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;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user