VNSceneGen is more or less working
This commit is contained in:
		@@ -1,101 +0,0 @@
 | 
			
		||||
<vnscene name="ExampleScene">
 | 
			
		||||
  <item ref="eth" prefab="preafbs/charactersEthereality" />
 | 
			
		||||
  <item ref="craig" prefab="preafbs/characters/Craig" />
 | 
			
		||||
  <item ref="bg" prefab="preafbs/backgrounds/School" />
 | 
			
		||||
  <item ref="square" prefab="prefabs/visualnovel/VisualNovelSquare" />
 | 
			
		||||
  <property type="" ref="easeOut" value="easeOutQuad" />
 | 
			
		||||
 | 
			
		||||
  <events>
 | 
			
		||||
    <!-- Set the default values -->
 | 
			
		||||
    <position item="bg" x="0" y="0" z="0"  />
 | 
			
		||||
    <position item="craig" x="0" y="0" z="1" />
 | 
			
		||||
    <position item="eth" x="0" y="0" z="1" />
 | 
			
		||||
    <position item="square" x="0" y="0" z="10" />
 | 
			
		||||
 | 
			
		||||
    <set property="square->material->color" value="COLOR_BLACK" />
 | 
			
		||||
    <set property="craig->material->color.a" value="0" />
 | 
			
		||||
 | 
			
		||||
    <!-- Fade out the black overlay -->
 | 
			
		||||
    <set property="square->material->color.a" from="1" to="0" duration="1" curve="easeOut" />
 | 
			
		||||
    
 | 
			
		||||
    <!-- Example Text, also showing how in future we can support multiple languages -->
 | 
			
		||||
    <text character="eth">
 | 
			
		||||
      <string lang="en">Hi, I'm Ethereality.</string>
 | 
			
		||||
    </text>
 | 
			
		||||
    
 | 
			
		||||
    <!-- Fade in craig -->
 | 
			
		||||
    <set item="craig->material->color.a" from="0" to="1" duration="1" curve="easeOut" />
 | 
			
		||||
    <text character="craig">
 | 
			
		||||
      <string lang="en">Hi, I'm Craig.</string>
 | 
			
		||||
    </text>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
      Because each event stops things happening until it's complete, let's
 | 
			
		||||
      assume we want to do two things at once, say move and fade out a character
 | 
			
		||||
      at the same time. This will make craig exit screen left.
 | 
			
		||||
    -->
 | 
			
		||||
    <parallel>
 | 
			
		||||
      <set item="craig->material->color.a" from="1" to="0" duration="1" curve="easeOut" />
 | 
			
		||||
      <position item="craig" x="-2" duration="1" curve="easeOut" />
 | 
			
		||||
    </parallel>
 | 
			
		||||
 | 
			
		||||
    <!-- Now Craig is gone, so sad, let's now fade the screen out and present some choices -->
 | 
			
		||||
    <set item="square->material->color.a" from="0" to="1" duration="1" curve="easeOut" />
 | 
			
		||||
 | 
			
		||||
    <!-- Here I am creating a marker -->
 | 
			
		||||
    <marker name="craigCool" />
 | 
			
		||||
 | 
			
		||||
    <choices character="eth" key="isCraigCool">
 | 
			
		||||
      <title>
 | 
			
		||||
        <string lang="en">Do you think Craig is cool?</string>
 | 
			
		||||
      </title>
 | 
			
		||||
      <choice value="no">
 | 
			
		||||
        <string lang="en">Yes</string>
 | 
			
		||||
      </choice>
 | 
			
		||||
      <choice value="yes">
 | 
			
		||||
        <string lang="en">No</string>
 | 
			
		||||
      </choice>
 | 
			
		||||
      <choice value="maybe">
 | 
			
		||||
        <string lang="en">Maybe</string>
 | 
			
		||||
      </choice>
 | 
			
		||||
    </choices>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
      Now we have a choice, we can use the key to get the value of the choice
 | 
			
		||||
      and do something with it. In this case, we'll just show a different
 | 
			
		||||
      message depending on the choice.
 | 
			
		||||
 | 
			
		||||
      If the user selects "Maybe", we basically just display a message and then
 | 
			
		||||
      go back to the choices indefinitely.
 | 
			
		||||
    -->
 | 
			
		||||
    <if key="isCraigCool" value="maybe">
 | 
			
		||||
      <text character="eth">
 | 
			
		||||
        <string lang="en">Are you unsure?</string>
 | 
			
		||||
      </text>
 | 
			
		||||
      <goto-marker name="craigCool" />
 | 
			
		||||
    </if>
 | 
			
		||||
 | 
			
		||||
    <if key="isCraigCool" value="yes">
 | 
			
		||||
      <text character="eth">
 | 
			
		||||
        <string lang="en">I agree, Craig is cool.</string>
 | 
			
		||||
      </text>
 | 
			
		||||
    </if>
 | 
			
		||||
    <if key="isCraigCool" value="no">
 | 
			
		||||
      <text character="eth">
 | 
			
		||||
        <string lang="en">I disagree, Craig is cool.</string>
 | 
			
		||||
      </text>
 | 
			
		||||
    </if>
 | 
			
		||||
    
 | 
			
		||||
    <!-- We can also modify values/set values too. -->
 | 
			
		||||
    <choice-set key="isCraigCool" value="yes" />
 | 
			
		||||
 | 
			
		||||
    <!-- We can also wait some time -->
 | 
			
		||||
    <wait duration="1" />
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
      Now change scenes. Changing scenes is handled in-engine to stop the game
 | 
			
		||||
      crashing from a lack of memory.
 | 
			
		||||
    -->
 | 
			
		||||
    <scene-change name="scenes/ExampleScene2" />
 | 
			
		||||
  </events>
 | 
			
		||||
</vnscene>
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
<vnscene name="ExampleScene" extend="scene/ExtendedScene">
 | 
			
		||||
<vnscene name="VNSceneTest" extend="scenes/ExtendedScene">
 | 
			
		||||
  <item ref="eth" prefab="prefabs/SimpleSpinningCubePrefab" />
 | 
			
		||||
  <item ref="craig" prefab="prefabs/SimpleSpinningCubePrefab" />
 | 
			
		||||
  <item ref="bg" prefab="prefabs/SimpleSpinningCubePrefab" />
 | 
			
		||||
 
 | 
			
		||||
@@ -5,11 +5,11 @@
 | 
			
		||||
 | 
			
		||||
#include "game/DawnGame.hpp"
 | 
			
		||||
#include "scenes/HelloWorldScene.hpp"
 | 
			
		||||
#include "scenes/ExtendedScene.hpp"
 | 
			
		||||
#include "vnscenes/VNSceneTest.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
 | 
			
		||||
  // return new HelloWorldScene(game);
 | 
			
		||||
  return new ExtendedScene(game);
 | 
			
		||||
  return new VNSceneTest(game);
 | 
			
		||||
}
 | 
			
		||||
@@ -13,73 +13,15 @@ void SceneGen::generate(
 | 
			
		||||
  std::string tabs
 | 
			
		||||
) {
 | 
			
		||||
  struct ClassGenInfo classInfo;
 | 
			
		||||
  classInfo.clazz = scene->name;
 | 
			
		||||
  classInfo.constructorArgs = "DawnGame *game";
 | 
			
		||||
  classInfo.extendArgs = "game";
 | 
			
		||||
 | 
			
		||||
  std::string baseClassName = "Scene";
 | 
			
		||||
 | 
			
		||||
  // Determine extends
 | 
			
		||||
  if(scene->extend.empty()) {
 | 
			
		||||
    classInfo.includes.push_back("scene/Scene.hpp");
 | 
			
		||||
  } else {
 | 
			
		||||
    classInfo.includes.push_back(scene->extend + ".hpp");
 | 
			
		||||
 | 
			
		||||
    // Get last slash of scene->extend
 | 
			
		||||
    auto lastSlash = scene->extend.find_last_of('/');
 | 
			
		||||
    if(lastSlash != std::string::npos) {
 | 
			
		||||
      baseClassName = scene->extend.substr(lastSlash + 1);
 | 
			
		||||
    } else {
 | 
			
		||||
      baseClassName = scene->extend;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  classInfo.extend = baseClassName;
 | 
			
		||||
  // classInfo.extend = "Scene";
 | 
			
		||||
 | 
			
		||||
  struct MethodGenInfo methodAssets;
 | 
			
		||||
  methodAssets.name = "getRequiredAssets";
 | 
			
		||||
  methodAssets.isOverride = true;
 | 
			
		||||
  methodAssets.type = "std::vector<Asset*>";
 | 
			
		||||
  line(&methodAssets.body, "auto assMan = &this->game->assetManager;", "");
 | 
			
		||||
 | 
			
		||||
  struct MethodGenInfo methodInit;
 | 
			
		||||
  methodInit.name = "stage";
 | 
			
		||||
  methodInit.isOverride = true;
 | 
			
		||||
 | 
			
		||||
  if(scene->extend.empty()) {
 | 
			
		||||
    line(&methodAssets.body, "std::vector<Asset*> assets;", "");
 | 
			
		||||
  } else {
 | 
			
		||||
    line(&methodAssets.body, "std::vector<Asset*> assets = " + baseClassName + "::getRequiredAssets();", "");
 | 
			
		||||
    line(&methodInit.body, baseClassName + "::stage();", "");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Generate
 | 
			
		||||
  int32_t assetNumber = 0;
 | 
			
		||||
  int32_t childNumber = 0;
 | 
			
		||||
  int32_t componentNumber = 0;
 | 
			
		||||
  std::map<std::string, std::string> assetMap;
 | 
			
		||||
 | 
			
		||||
  auto sceneItems = scene->items.begin();
 | 
			
		||||
  while(sceneItems != scene->items.end()) {
 | 
			
		||||
    SceneItemGenerator::generate(
 | 
			
		||||
      assetNumber,
 | 
			
		||||
      componentNumber,
 | 
			
		||||
      childNumber,
 | 
			
		||||
      assetMap,
 | 
			
		||||
      classInfo.includes,
 | 
			
		||||
      &classInfo.publicProperties,
 | 
			
		||||
      &methodInit.body,
 | 
			
		||||
      &methodAssets.body,
 | 
			
		||||
      "",
 | 
			
		||||
      "this",
 | 
			
		||||
      &(*sceneItems),
 | 
			
		||||
      ""
 | 
			
		||||
    );
 | 
			
		||||
    ++sceneItems;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Seal methods
 | 
			
		||||
  line(&methodAssets.body, "return assets;", "");
 | 
			
		||||
  SceneGenerator::generate(
 | 
			
		||||
    scene,
 | 
			
		||||
    classInfo,
 | 
			
		||||
    methodAssets,
 | 
			
		||||
    methodInit
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // Add in methods
 | 
			
		||||
  CodeGen::methodGen(&classInfo.publicCode, methodAssets);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,7 @@
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "util/parser/SceneParser.hpp"
 | 
			
		||||
#include "util/generator/SceneItemGenerator.hpp"
 | 
			
		||||
#include "util/generator/SceneGenerator.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class SceneGen : public CodeGen {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ set(
 | 
			
		||||
    ${DAWN_TOOL_SOURCES}
 | 
			
		||||
    ${D}/SceneItemGenerator.cpp
 | 
			
		||||
    ${D}/SceneAssetGenerator.cpp
 | 
			
		||||
    ${D}/SceneGenerator.cpp
 | 
			
		||||
    ${D}/SceneItemComponentGenerator.cpp
 | 
			
		||||
 | 
			
		||||
  CACHE INTERNAL
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										79
									
								
								src/dawntools/util/generator/SceneGenerator.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								src/dawntools/util/generator/SceneGenerator.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#include "SceneGenerator.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
void SceneGenerator::generate(
 | 
			
		||||
  struct Scene *scene,
 | 
			
		||||
  struct ClassGenInfo &classInfo,
 | 
			
		||||
  struct MethodGenInfo &methodAssets,
 | 
			
		||||
  struct MethodGenInfo &methodInit
 | 
			
		||||
) {
 | 
			
		||||
  classInfo.clazz = scene->name;
 | 
			
		||||
  classInfo.constructorArgs = "DawnGame *game";
 | 
			
		||||
  classInfo.extendArgs = "game";
 | 
			
		||||
 | 
			
		||||
  std::string baseClassName = "Scene";
 | 
			
		||||
 | 
			
		||||
  // Determine extends
 | 
			
		||||
  if(scene->extend.empty()) {
 | 
			
		||||
    classInfo.includes.push_back("scene/Scene.hpp");
 | 
			
		||||
  } else {
 | 
			
		||||
    classInfo.includes.push_back(scene->extend + ".hpp");
 | 
			
		||||
 | 
			
		||||
    // Get last slash of scene->extend
 | 
			
		||||
    auto lastSlash = scene->extend.find_last_of('/');
 | 
			
		||||
    baseClassName = scene->extend;
 | 
			
		||||
    if(lastSlash != std::string::npos) {
 | 
			
		||||
      baseClassName = scene->extend.substr(lastSlash + 1);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  classInfo.extend = baseClassName;
 | 
			
		||||
 | 
			
		||||
  methodAssets.name = "getRequiredAssets";
 | 
			
		||||
  methodAssets.isOverride = true;
 | 
			
		||||
  methodAssets.type = "std::vector<Asset*>";
 | 
			
		||||
  line(&methodAssets.body, "auto assMan = &this->game->assetManager;", "");
 | 
			
		||||
 | 
			
		||||
  methodInit.name = "stage";
 | 
			
		||||
  methodInit.isOverride = true;
 | 
			
		||||
 | 
			
		||||
  if(scene->extend.empty()) {
 | 
			
		||||
    line(&methodAssets.body, "std::vector<Asset*> assets;", "");
 | 
			
		||||
  } else {
 | 
			
		||||
    line(&methodAssets.body, "std::vector<Asset*> assets = " + baseClassName + "::getRequiredAssets();", "");
 | 
			
		||||
    line(&methodInit.body, baseClassName + "::stage();", "");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Generate
 | 
			
		||||
  int32_t assetNumber = 0;
 | 
			
		||||
  int32_t childNumber = 0;
 | 
			
		||||
  int32_t componentNumber = 0;
 | 
			
		||||
  std::map<std::string, std::string> assetMap;
 | 
			
		||||
 | 
			
		||||
  auto sceneItems = scene->items.begin();
 | 
			
		||||
  while(sceneItems != scene->items.end()) {
 | 
			
		||||
    SceneItemGenerator::generate(
 | 
			
		||||
      assetNumber,
 | 
			
		||||
      componentNumber,
 | 
			
		||||
      childNumber,
 | 
			
		||||
      assetMap,
 | 
			
		||||
      classInfo.includes,
 | 
			
		||||
      &classInfo.publicProperties,
 | 
			
		||||
      &methodInit.body,
 | 
			
		||||
      &methodAssets.body,
 | 
			
		||||
      "",
 | 
			
		||||
      "this",
 | 
			
		||||
      &(*sceneItems),
 | 
			
		||||
      ""
 | 
			
		||||
    );
 | 
			
		||||
    ++sceneItems;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Seal methods
 | 
			
		||||
  line(&methodAssets.body, "return assets;", "");
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								src/dawntools/util/generator/SceneGenerator.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/dawntools/util/generator/SceneGenerator.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/parser/SceneParser.hpp"
 | 
			
		||||
#include "SceneItemGenerator.hpp"
 | 
			
		||||
#include "util/CodeGen.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class SceneGenerator : public CodeGen {
 | 
			
		||||
    public:
 | 
			
		||||
      static void generate(
 | 
			
		||||
        struct Scene *scene,
 | 
			
		||||
        struct ClassGenInfo &classInfo,
 | 
			
		||||
        struct MethodGenInfo &methodAssets,
 | 
			
		||||
        struct MethodGenInfo &methodInit
 | 
			
		||||
      );
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -14,139 +14,138 @@ void VNSceneGen::test(
 | 
			
		||||
  std::vector<std::string> *body,
 | 
			
		||||
  std::vector<std::string> *includes
 | 
			
		||||
) {
 | 
			
		||||
  std::string initType = "";
 | 
			
		||||
  std::string toInclude = "";
 | 
			
		||||
  std::string initArgs = "";
 | 
			
		||||
  std::vector<std::string> afterLines;
 | 
			
		||||
 | 
			
		||||
//   std::string initType = "";
 | 
			
		||||
//   std::string toInclude = "";
 | 
			
		||||
//   std::string initArgs = "";
 | 
			
		||||
//   std::vector<std::string> afterLines;
 | 
			
		||||
  switch(event->type) {
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_TEXT:
 | 
			
		||||
      initType = "VNTextEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNTextEvent.hpp";
 | 
			
		||||
      line(&afterLines, eventName + "->" + "text = \"" + event->text.texts.begin()->text + "\";", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//   switch(event->type) {
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_TEXT:
 | 
			
		||||
//       initType = "VNTextEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNTextEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->" + "text = \"" + event->text.texts.begin()->text + "\";", "");
 | 
			
		||||
//       break;
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_POSITION:
 | 
			
		||||
      initType = "VNPositionEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNPositionEvent.hpp";
 | 
			
		||||
      line(&afterLines, eventName + "->item = " + event->position.item + ";", "");
 | 
			
		||||
      if(event->position.x != "") line(&afterLines, eventName + "->" + "to.x = " + event->position.x + ";", "");
 | 
			
		||||
      if(event->position.y != "") line(&afterLines, eventName + "->" + "to.y = " + event->position.y + ";", "");
 | 
			
		||||
      if(event->position.z != "") line(&afterLines, eventName + "->" + "to.z = " + event->position.z + ";", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_POSITION:
 | 
			
		||||
//       initType = "VNPositionEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNPositionEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->item = " + event->position.item + ";", "");
 | 
			
		||||
//       if(event->position.x != "") line(&afterLines, eventName + "->" + "to.x = " + event->position.x + ";", "");
 | 
			
		||||
//       if(event->position.y != "") line(&afterLines, eventName + "->" + "to.y = " + event->position.y + ";", "");
 | 
			
		||||
//       if(event->position.z != "") line(&afterLines, 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(&afterLines, eventName + "->modifies = &" + event->set.property + ";", "");
 | 
			
		||||
      line(&afterLines, eventName + "->to = " + event->set.to + ";", "");
 | 
			
		||||
      if(event->set.from != "") line(&afterLines, eventName + "->from = " + event->set.from + ";", "");
 | 
			
		||||
      if(event->set.duration != "") line(&afterLines, eventName + "->duration = " + event->set.duration + ";", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_SET:
 | 
			
		||||
//       initType = "VNSetEvent<" + event->set.type + ">";
 | 
			
		||||
//       toInclude = "games/vn/events/VNSetEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->modifies = &" + event->set.property + ";", "");
 | 
			
		||||
//       line(&afterLines, eventName + "->to = " + event->set.to + ";", "");
 | 
			
		||||
//       if(event->set.from != "") line(&afterLines, eventName + "->from = " + event->set.from + ";", "");
 | 
			
		||||
//       if(event->set.duration != "") line(&afterLines, eventName + "->duration = " + event->set.duration + ";", "");
 | 
			
		||||
//       break;
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_WAIT:
 | 
			
		||||
      initType = "VNWaitEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNWaitEvent.hpp";
 | 
			
		||||
      line(&afterLines, eventName + "->duration = " + event->wait.duration + ";", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_WAIT:
 | 
			
		||||
//       initType = "VNWaitEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNWaitEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->duration = " + event->wait.duration + ";", "");
 | 
			
		||||
//       break;
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_PARALLEL: {
 | 
			
		||||
      initType = "VNParallelEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNParallelEvent.hpp";
 | 
			
		||||
 | 
			
		||||
//     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,
 | 
			
		||||
          &afterLines,
 | 
			
		||||
          includes
 | 
			
		||||
        );
 | 
			
		||||
        line(&afterLines, eventName + "->events.push_back(" + pEventName + ");", "");
 | 
			
		||||
        line(&afterLines, "", "");
 | 
			
		||||
        ++itParallel;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//       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,
 | 
			
		||||
//           &afterLines,
 | 
			
		||||
//           includes
 | 
			
		||||
//         );
 | 
			
		||||
//         line(&afterLines, eventName + "->events.push_back(" + pEventName + ");", "");
 | 
			
		||||
//         line(&afterLines, "", "");
 | 
			
		||||
//         ++itParallel;
 | 
			
		||||
//       }
 | 
			
		||||
//       break;
 | 
			
		||||
//     }
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_MARKER:
 | 
			
		||||
      initType = "VNDummyEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNDummyEvent.hpp";
 | 
			
		||||
      line(&afterLines, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_MARKER:
 | 
			
		||||
//       initType = "VNDummyEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNDummyEvent.hpp";
 | 
			
		||||
//       line(&afterLines, "auto marker_" + event->marker.name + " = " + eventName + ";", "");
 | 
			
		||||
//       break;
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
 | 
			
		||||
      initType = "VNDummyEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNDummyEvent.hpp";
 | 
			
		||||
      line(&afterLines, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_GOTO_MARKER:
 | 
			
		||||
//       initType = "VNDummyEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNDummyEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->then(marker_" + event->gotoMarker.name + ");", "");
 | 
			
		||||
//       break;
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_CHOICES: {
 | 
			
		||||
      initType = "VNChoiceEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNChoiceEvent.hpp";
 | 
			
		||||
      line(&afterLines, eventName + "->key = \"" + event->choices.key+ "\";", "");
 | 
			
		||||
      line(&afterLines, eventName + "->text = \"" + event->choices.titles.begin()->text + "\";", "");
 | 
			
		||||
      auto itChoices = event->choices.choices.begin();
 | 
			
		||||
      while(itChoices != event->choices.choices.end()) {
 | 
			
		||||
        line(&afterLines, eventName + "->choices[\"" + itChoices->value + "\"] = \"" + itChoices->texts.begin()->text + "\";", "");
 | 
			
		||||
        ++itChoices;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_CHOICES: {
 | 
			
		||||
//       initType = "VNChoiceEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNChoiceEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->key = \"" + event->choices.key+ "\";", "");
 | 
			
		||||
//       line(&afterLines, eventName + "->text = \"" + event->choices.titles.begin()->text + "\";", "");
 | 
			
		||||
//       auto itChoices = event->choices.choices.begin();
 | 
			
		||||
//       while(itChoices != event->choices.choices.end()) {
 | 
			
		||||
//         line(&afterLines, 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(&afterLines, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
 | 
			
		||||
      line(&afterLines, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_CHOICE_SET:
 | 
			
		||||
//       initType = "VNChoiceSetEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNChoiceSetEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->key = \"" + event->choiceSet.key + "\";", "");
 | 
			
		||||
//       line(&afterLines, eventName + "->value = \"" + event->choiceSet.value + "\";", "");
 | 
			
		||||
//       break;
 | 
			
		||||
    case VN_SCENE_EVENT_TYPE_IF: {
 | 
			
		||||
      initType = "VNIfEvent";
 | 
			
		||||
      toInclude = "games/vn/events/VNIfEvent.hpp";
 | 
			
		||||
      line(&afterLines, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
 | 
			
		||||
      line(&afterLines, eventName + "->value = \"" + event->ifEvent.value + "\";", "");
 | 
			
		||||
 | 
			
		||||
//     case VN_SCENE_EVENT_TYPE_IF: {
 | 
			
		||||
//       initType = "VNIfEvent";
 | 
			
		||||
//       toInclude = "games/vn/events/VNIfEvent.hpp";
 | 
			
		||||
//       line(&afterLines, eventName + "->key = \"" + event->ifEvent.key + "\";", "");
 | 
			
		||||
//       line(&afterLines, 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,
 | 
			
		||||
          &afterLines,
 | 
			
		||||
          includes
 | 
			
		||||
        );
 | 
			
		||||
        if(!ifPrevious.empty()) line(&afterLines, ifPrevious + "->then(" + ifEventName + ");", "");
 | 
			
		||||
        ifPrevious = ifEventName;
 | 
			
		||||
        if(ifFirst == "") ifFirst = ifEventName;
 | 
			
		||||
        ++itIf;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
//       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,
 | 
			
		||||
//           &afterLines,
 | 
			
		||||
//           includes
 | 
			
		||||
//         );
 | 
			
		||||
//         if(!ifPrevious.empty()) line(&afterLines, 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();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
//       if(ifFirst == "" || ifPrevious == "") {
 | 
			
		||||
//         std::cout << "If event must have at least one event" << std::endl;
 | 
			
		||||
//         assertUnreachable();
 | 
			
		||||
//       }
 | 
			
		||||
      line(&afterLines, eventName + "->ifTrue = " + ifFirst + ";", "");
 | 
			
		||||
      line(&afterLines, eventName + "->ifEnd = " + ifPrevious + ";", "");
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//       line(&afterLines, eventName + "->ifTrue = " + ifFirst + ";", "");
 | 
			
		||||
//       line(&afterLines, eventName + "->ifEnd = " + ifPrevious + ";", "");
 | 
			
		||||
//       break;
 | 
			
		||||
//     }
 | 
			
		||||
    default:
 | 
			
		||||
      std::cout << "Unknown event type: " << event->type << std::endl;
 | 
			
		||||
      assertUnreachable();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
//     default:
 | 
			
		||||
//       std::cout << "Unknown event type: " << event->type << std::endl;
 | 
			
		||||
//       assertUnreachable();
 | 
			
		||||
//   }
 | 
			
		||||
  if(!toInclude.empty()) includes->push_back(toInclude);
 | 
			
		||||
 | 
			
		||||
//   if(!toInclude.empty()) includes->push_back(toInclude);
 | 
			
		||||
 | 
			
		||||
//   line(body, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
 | 
			
		||||
//   lines(body, afterLines, "");
 | 
			
		||||
  line(body, "auto " + eventName + " = vnManager->createEvent<" + initType + ">(" + initArgs + ");", "");
 | 
			
		||||
  lines(body, afterLines, "");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void VNSceneGen::generate(
 | 
			
		||||
@@ -154,86 +153,52 @@ void VNSceneGen::generate(
 | 
			
		||||
  struct VNScene *scene,
 | 
			
		||||
  std::string tabs
 | 
			
		||||
) {
 | 
			
		||||
  std::cout << "Gen Scene" << std::endl;
 | 
			
		||||
  struct ClassGenInfo classInfo;
 | 
			
		||||
  struct MethodGenInfo methodAssets;
 | 
			
		||||
  struct MethodGenInfo methodInit;
 | 
			
		||||
 | 
			
		||||
//   struct ClassGenInfo classInfo;
 | 
			
		||||
//   classInfo.clazz = "TestScene";
 | 
			
		||||
//   classInfo.extend = "Scene";
 | 
			
		||||
//   classInfo.constructorArgs = "DawnGame *game";
 | 
			
		||||
//   classInfo.extendArgs = "game";
 | 
			
		||||
 | 
			
		||||
//   classInfo.includes.push_back("scene/Scene.hpp");
 | 
			
		||||
  // Load Scene
 | 
			
		||||
  SceneGenerator::generate(
 | 
			
		||||
    &scene->scene,
 | 
			
		||||
    classInfo,
 | 
			
		||||
    methodAssets,
 | 
			
		||||
    methodInit
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
//   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", "");
 | 
			
		||||
  // Events
 | 
			
		||||
  classInfo.includes.push_back("games/vn/components/VNManager.hpp");
 | 
			
		||||
  line(&methodInit.body, "auto vnItem = this->createSceneItem();", "");
 | 
			
		||||
  line(&methodInit.body, "auto vnManager = vnItem->addComponent<VNManager>();", "");
 | 
			
		||||
  line(&methodInit.body, "VNEvent *previous = vnManager->createEvent<VNDummyEvent>();", "");
 | 
			
		||||
  line(&methodInit.body, "auto eventStart = previous;", "");
 | 
			
		||||
 | 
			
		||||
//   // TEST
 | 
			
		||||
//   line(&methodStage.body, "auto canvas = UICanvas::create(this);", "");
 | 
			
		||||
//   line(&methodStage.body, "", "");
 | 
			
		||||
  int32_t eventIndex = 0;
 | 
			
		||||
  auto itEvents = scene->events.events.begin();
 | 
			
		||||
  std::string previous = "eventStart";
 | 
			
		||||
  while(itEvents != scene->events.events.end()) {
 | 
			
		||||
    line(&methodInit.body, "", "");
 | 
			
		||||
    std::string eventName = "event" + std::to_string(eventIndex++);
 | 
			
		||||
    VNSceneGen::test(
 | 
			
		||||
      eventName,
 | 
			
		||||
      &(*itEvents),
 | 
			
		||||
      &eventIndex,
 | 
			
		||||
      &methodInit.body,
 | 
			
		||||
      &classInfo.includes
 | 
			
		||||
    );
 | 
			
		||||
    line(&methodInit.body, previous + "->then(" + eventName + ");", "");
 | 
			
		||||
    previous = eventName;
 | 
			
		||||
    ++itEvents;
 | 
			
		||||
  }
 | 
			
		||||
  line(&methodInit.body, "", "");
 | 
			
		||||
  line(&methodInit.body, "vnManager->setEvent(eventStart);", "");
 | 
			
		||||
 | 
			
		||||
//   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));", "");
 | 
			
		||||
 | 
			
		||||
//   // Items
 | 
			
		||||
//   int32_t itemRefIndex = 0;
 | 
			
		||||
//   auto itItems = scene->items.begin();
 | 
			
		||||
//   while(itItems != scene->items.end()) {
 | 
			
		||||
//     struct VNSceneItem item = *itItems;
 | 
			
		||||
//     if(item.ref.empty()) item.ref = "item" + std::to_string(itemRefIndex++);
 | 
			
		||||
//     classInfo.includes.push_back(item.prefab + ".hpp");
 | 
			
		||||
    
 | 
			
		||||
//     line(&methodStage.body, "", "");
 | 
			
		||||
//     line(&methodStage.body, "auto " + item.ref + " = " + item.className + "::create(this);", "");
 | 
			
		||||
  // Add in methods
 | 
			
		||||
  CodeGen::methodGen(&classInfo.publicCode, methodAssets);
 | 
			
		||||
  line(&classInfo.publicCode, "", "");
 | 
			
		||||
  CodeGen::methodGen(&classInfo.publicCode, methodInit);
 | 
			
		||||
 | 
			
		||||
//     ++itItems;
 | 
			
		||||
//   }
 | 
			
		||||
 | 
			
		||||
//   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();
 | 
			
		||||
//   std::string previous = "eventStart";
 | 
			
		||||
//   while(itEvents != scene->events.events.end()) {
 | 
			
		||||
//     line(&methodStage.body, "", "");
 | 
			
		||||
//     std::string eventName = "event" + std::to_string(eventIndex++);
 | 
			
		||||
//     VNSceneGen::test(
 | 
			
		||||
//       eventName,
 | 
			
		||||
//       &(*itEvents),
 | 
			
		||||
//       &eventIndex,
 | 
			
		||||
//       &methodStage.body,
 | 
			
		||||
//       &classInfo.includes
 | 
			
		||||
//     );
 | 
			
		||||
//     line(&methodStage.body, previous + "->then(" + eventName + ");", "");
 | 
			
		||||
//     previous = eventName;
 | 
			
		||||
//     ++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);
 | 
			
		||||
  CodeGen::classGen(out, classInfo);
 | 
			
		||||
}
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "VNSceneParser.hpp"
 | 
			
		||||
#include "util/CodeGen.hpp"
 | 
			
		||||
#include "util/generator/SceneGenerator.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class VNSceneGen : public CodeGen {
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,7 @@ int32_t VNSceneTool::start() {
 | 
			
		||||
  VNSceneGen::generate(&outputData, &scene, "");
 | 
			
		||||
 | 
			
		||||
  // Load output file from name and type
 | 
			
		||||
  File outputFile = File(flags["output"] + "/vnscenes/TestScene.hpp");
 | 
			
		||||
  File outputFile = File(flags["output"] + "/vnscenes/" + scene.scene.name +  ".hpp");
 | 
			
		||||
  if(!outputFile.mkdirp()) {
 | 
			
		||||
    std::cout << "Failed to create output directory!" << std::endl;
 | 
			
		||||
    return 1;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user