XML structured much better
This commit is contained in:
		| @@ -1,36 +0,0 @@ | |||||||
| # Copyright (c) 2023 Dominic Msters |  | ||||||
| #  |  | ||||||
| # This software is released under the MIT License. |  | ||||||
| # https://opensource.org/licenses/MIT |  | ||||||
|  |  | ||||||
| project(sceneitemcomponentgen VERSION 1.0) |  | ||||||
| add_executable(sceneitemcomponentgen) |  | ||||||
|  |  | ||||||
| # Sources |  | ||||||
| target_sources(sceneitemcomponentgen |  | ||||||
|   PRIVATE |  | ||||||
|     ${DAWN_SHARED_SOURCES} |  | ||||||
|     ${DAWN_TOOL_SOURCES} |  | ||||||
|     SceneItemComponentRegister.cpp |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| # Includes |  | ||||||
| target_include_directories(sceneitemcomponentgen |  | ||||||
|   PUBLIC |  | ||||||
|     ${DAWN_SHARED_INCLUDES} |  | ||||||
|     ${DAWN_TOOL_INCLUDES} |  | ||||||
|     ${CMAKE_CURRENT_LIST_DIR} |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| # Definitions |  | ||||||
| target_compile_definitions(sceneitemcomponentgen |  | ||||||
|   PUBLIC |  | ||||||
|     DAWN_TOOL_INSTANCE=SceneItemComponentRegister |  | ||||||
|     DAWN_TOOL_HEADER="SceneItemComponentRegister.hpp" |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| # Libraries |  | ||||||
| target_link_libraries(sceneitemcomponentgen |  | ||||||
|   PUBLIC |  | ||||||
|     ${DAWN_BUILD_HOST_LIBS} |  | ||||||
| ) |  | ||||||
| @@ -1,119 +0,0 @@ | |||||||
| /** |  | ||||||
|  * Copyright (c) 2023 Dominic Masters |  | ||||||
|  *  |  | ||||||
|  * This software is released under the MIT License. |  | ||||||
|  * https://opensource.org/licenses/MIT |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include "SceneItemComponentRegister.hpp" |  | ||||||
|  |  | ||||||
| using namespace Dawn; |  | ||||||
|  |  | ||||||
| void SceneItemComponentRootGen::generate( |  | ||||||
|   std::vector<std::string> *out, |  | ||||||
|   std::vector<struct SceneItemComponent> *info, |  | ||||||
|   std::string tabs = "" |  | ||||||
| ) { |  | ||||||
|   line(out, "#include \"scene/SceneItemComponentList.hpp\"", tabs); |  | ||||||
|   line(out, "", tabs); |  | ||||||
|  |  | ||||||
|   auto it = info->begin(); |  | ||||||
|   while(it != info->end()) { |  | ||||||
|     auto c = *it; |  | ||||||
|     line(out, "#include \"" + c.header + "\"", tabs); |  | ||||||
|     ++it; |  | ||||||
|   } |  | ||||||
|   line(out, "", tabs); |  | ||||||
|   line(out, "using namespace Dawn;", tabs); |  | ||||||
|   line(out, "", tabs); |  | ||||||
|  |  | ||||||
|   line(out, "SceneItemComponentList::SceneItemComponentList() {", tabs); |  | ||||||
|   it = info->begin(); |  | ||||||
|   while(it != info->end()) { |  | ||||||
|     auto c = *it; |  | ||||||
|     line(out, "this->append<" + c.clazz + ">();", tabs + "  "); |  | ||||||
|     ++it; |  | ||||||
|   } |  | ||||||
|   line(out, "}", tabs); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::vector<std::string> SceneItemComponentRegister::getRequiredFlags() { |  | ||||||
|   return std::vector<std::string>{ "input", "output" }; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int32_t SceneItemComponentRegister::start() { |  | ||||||
|   File fileIn(flags["input"]); |  | ||||||
|   if(!fileIn.exists()) { |  | ||||||
|     std::cout << "Input scene item component file does not exist." << std::endl; |  | ||||||
|     return 1; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   std::string buffer; |  | ||||||
|   if(!fileIn.readString(&buffer)) { |  | ||||||
|     std::cout << "Failed to read input scene item component file" << std::endl; |  | ||||||
|     return 1; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   std::vector<struct SceneItemComponent> components; |  | ||||||
|   struct SceneItemComponent sci; |  | ||||||
|   size_t i = 0; |  | ||||||
|   std::string t; |  | ||||||
|   uint8_t state = 0x00; |  | ||||||
|   while(i < buffer.size()) { |  | ||||||
|     char c = buffer[i++]; |  | ||||||
|     if(c != ';') { |  | ||||||
|       t.push_back(c); |  | ||||||
|       continue; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     switch(state) { |  | ||||||
|       case 0x00: |  | ||||||
|         sci.clazz = t; |  | ||||||
|         t.clear(); |  | ||||||
|         state = 0x01; |  | ||||||
|         break; |  | ||||||
|  |  | ||||||
|       case 0x01: |  | ||||||
|         sci.header = t; |  | ||||||
|         t.clear(); |  | ||||||
|         state = 0x00; |  | ||||||
|         components.push_back(sci); |  | ||||||
|         break; |  | ||||||
|  |  | ||||||
|       default: |  | ||||||
|         assertUnreachable(); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if(state == 0x01) { |  | ||||||
|     sci.header = t; |  | ||||||
|     components.push_back(sci); |  | ||||||
|   } else { |  | ||||||
|     assertUnreachable(); |  | ||||||
|   } |  | ||||||
|    |  | ||||||
|  |  | ||||||
|   std::vector<std::string> lines; |  | ||||||
|   SceneItemComponentRootGen::generate(&lines, &components, ""); |  | ||||||
|  |  | ||||||
|   // Generate buffer |  | ||||||
|   std::string bufferOut; |  | ||||||
|   auto itLine = lines.begin(); |  | ||||||
|   while(itLine != lines.end()) { |  | ||||||
|     bufferOut += *itLine + "\n"; |  | ||||||
|     ++itLine; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   File fileOut(flags["output"]); |  | ||||||
|   if(!fileOut.mkdirp()) { |  | ||||||
|     std::cout << "Failed to create Scene Item Component List Dir" << std::endl; |  | ||||||
|     return 1; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if(!fileOut.writeString(bufferOut)) { |  | ||||||
|     std::cout << "Failed to write SceneItemComponentList file" << std::endl; |  | ||||||
|     return 1; |  | ||||||
|   } |  | ||||||
|    |  | ||||||
|   return 0; |  | ||||||
| } |  | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| // 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 "util/File.hpp" |  | ||||||
| #include "util/CodeGen.hpp" |  | ||||||
|  |  | ||||||
| namespace Dawn { |  | ||||||
|   struct SceneItemComponent { |  | ||||||
|     std::string clazz; |  | ||||||
|     std::string header; |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   class SceneItemComponentRootGen : public CodeGen { |  | ||||||
|     public: |  | ||||||
|       static void generate( |  | ||||||
|         std::vector<std::string> *out, |  | ||||||
|         std::vector<struct SceneItemComponent> *info, |  | ||||||
|         std::string tabs |  | ||||||
|       ); |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   class SceneItemComponentRegister : public DawnTool { |  | ||||||
|     protected: |  | ||||||
|       std::vector<std::string> getRequiredFlags() override; |  | ||||||
|        |  | ||||||
|     public: |  | ||||||
|       int32_t start() override; |  | ||||||
|   }; |  | ||||||
| } |  | ||||||
| @@ -1,9 +1,14 @@ | |||||||
| <scene name="TestScene"> | <scene name="SceneBase"> | ||||||
|   <item lookAt="10, 10, 10, 0, 0, 0"> |   <item lookAt="10, 10, 10, 0, 0, 0"> | ||||||
|     <Camera ref="camera" /> |     <Camera ref="camera" /> | ||||||
|   </item> |   </item> | ||||||
| 
 | 
 | ||||||
|   <!-- <item lookAt="0, 0, 5, 0, 0, 0" > |   <item ref="eth" prefab="prefabs/EthPrefab" /> | ||||||
|  |   <item ref="craig" prefab="prefabs/SimpleSpinningCubePrefab" /> | ||||||
|  |   <item ref="bg" prefab="prefabs/SimpleSpinningCubePrefab" /> | ||||||
|  |   <item ref="square" prefab="prefabs/SimpleSpinningCubePrefab" /> | ||||||
|  |    | ||||||
|  |   <item lookAt="0, 0, 5, 0, 0, 0" > | ||||||
|     <Camera fov="0.436332" ref="cameraNew" /> |     <Camera fov="0.436332" ref="cameraNew" /> | ||||||
|     <CameraTexture /> |     <CameraTexture /> | ||||||
|   </item> |   </item> | ||||||
| @@ -21,5 +26,5 @@ | |||||||
|         ref="image" |         ref="image" | ||||||
|       /> |       /> | ||||||
|     </item> |     </item> | ||||||
|   </item> --> |   </item> | ||||||
| </scene> | </scene> | ||||||
							
								
								
									
										9
									
								
								assets/games/liminal/scenes/VNSceneTest.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								assets/games/liminal/scenes/VNSceneTest.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | <vnscene name="VNSceneTest" extend="scenes/SceneBase"> | ||||||
|  |   <events> | ||||||
|  |     <position item="eth" x="0" y="0" z="5" /> | ||||||
|  |  | ||||||
|  |     <text character="eth"> | ||||||
|  |       <string lang="en">Hi, I'm Ethereality.</string> | ||||||
|  |     </text> | ||||||
|  |   </events> | ||||||
|  | </vnscene> | ||||||
| @@ -1,3 +0,0 @@ | |||||||
| <scene name="ExtendedScene" extend="scenes/TestScene"> |  | ||||||
|   <item ref="eth" prefab="prefabs/EthPrefab" /> |  | ||||||
| </scene> |  | ||||||
| @@ -1,103 +0,0 @@ | |||||||
| <vnscene name="VNSceneTest" extend="scenes/ExtendedScene"> |  | ||||||
|   <item ref="eth" prefab="prefabs/SimpleSpinningCubePrefab" /> |  | ||||||
|   <item ref="craig" prefab="prefabs/SimpleSpinningCubePrefab" /> |  | ||||||
|   <item ref="bg" prefab="prefabs/SimpleSpinningCubePrefab" /> |  | ||||||
|   <item ref="square" prefab="prefabs/SimpleSpinningCubePrefab" /> |  | ||||||
|  |  | ||||||
|   <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" type="struct Color" /> |  | ||||||
|     <set property="craig->material->color.a" value="0" type="uint8_t" /> |  | ||||||
|  |  | ||||||
|     <!-- Fade out the black overlay --> |  | ||||||
|     <set property="square->material->color.a" to="0" duration="1" curve="easeOut" type="uint8_t" /> |  | ||||||
|      |  | ||||||
|     <!-- 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 property="craig->material->color.a" to="255" duration="1" curve="easeOut" type="uint8_t" /> |  | ||||||
|     <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 property="craig->material->color.a" to="0" duration="1" curve="easeOut" type="uint8_t" /> |  | ||||||
|       <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 property="square->material->color.a" to="255" duration="1" curve="easeOut" type="uint8_t" /> |  | ||||||
|  |  | ||||||
|     <!-- 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> |  | ||||||
|    |  | ||||||
|     <text character="eth"> |  | ||||||
|       <string lang="en">bruh9000</string> |  | ||||||
|     </text> |  | ||||||
|      |  | ||||||
|     <!-- 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> |  | ||||||
| @@ -18,13 +18,13 @@ add_subdirectory(save) | |||||||
|  |  | ||||||
| # Assets | # Assets | ||||||
| set(LIMINAL_ASSETS_DIR ${DAWN_ASSETS_DIR}/games/liminal) | set(LIMINAL_ASSETS_DIR ${DAWN_ASSETS_DIR}/games/liminal) | ||||||
| tool_scene(${LIMINAL_ASSETS_DIR}/scenes/scene-base.xml) |  | ||||||
| tool_scene(${LIMINAL_ASSETS_DIR}/scenes/scene-extend.xml) |  | ||||||
| tool_vnscene(${LIMINAL_ASSETS_DIR}/test.xml) |  | ||||||
|  |  | ||||||
| tool_prefab(${LIMINAL_ASSETS_DIR}/VNTextbox.xml) |  | ||||||
| tool_truetype(font_main ${DAWN_ASSETS_DIR}/ark-pixel.ttf) | tool_truetype(font_main ${DAWN_ASSETS_DIR}/ark-pixel.ttf) | ||||||
|  | tool_texture(texture_eth ${LIMINAL_ASSETS_DIR}/textures/eth.png) | ||||||
|  | tool_texture(texture_border ${LIMINAL_ASSETS_DIR}/textures/texture_test.png) | ||||||
|  |  | ||||||
|  | tool_scene(${LIMINAL_ASSETS_DIR}/scenes/SceneBase.xml) | ||||||
|  | tool_vnscene(${LIMINAL_ASSETS_DIR}/scenes/VNSceneTest.xml) | ||||||
|  |  | ||||||
| tool_prefab(${LIMINAL_ASSETS_DIR}/prefabs/EthPrefab.xml) | tool_prefab(${LIMINAL_ASSETS_DIR}/prefabs/EthPrefab.xml) | ||||||
| tool_texture(texture_eth ${LIMINAL_ASSETS_DIR}/textures/eth.png) | tool_prefab(${LIMINAL_ASSETS_DIR}/prefabs/VNTextbox.xml) | ||||||
| tool_texture(texture_border ${LIMINAL_ASSETS_DIR}/textures/texture_test.png) |  | ||||||
| @@ -18,7 +18,7 @@ std::map<std::string, std::string> PrefabTool::getOptionalFlags() { | |||||||
| int32_t PrefabTool::start() { | int32_t PrefabTool::start() { | ||||||
|   File input = File(flags["input"]); |   File input = File(flags["input"]); | ||||||
|   if(!input.exists()) { |   if(!input.exists()) { | ||||||
|     std::cout << "Input file does not exist!" << std::endl; |     std::cout << "Input file " + input.filename + " does not exist!" << std::endl; | ||||||
|     return 1; |     return 1; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ std::map<std::string, std::string> SceneTool::getOptionalFlags() { | |||||||
| int32_t SceneTool::start() { | int32_t SceneTool::start() { | ||||||
|   File input = File(flags["input"]); |   File input = File(flags["input"]); | ||||||
|   if(!input.exists()) { |   if(!input.exists()) { | ||||||
|     std::cout << "Input file does not exist!" << std::endl; |     std::cout << "Input file " + input.filename + " does not exist!" << std::endl; | ||||||
|     return 1; |     return 1; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ std::map<std::string, std::string> VNSceneTool::getOptionalFlags() { | |||||||
| int32_t VNSceneTool::start() { | int32_t VNSceneTool::start() { | ||||||
|   File input = File(flags["input"]); |   File input = File(flags["input"]); | ||||||
|   if(!input.exists()) { |   if(!input.exists()) { | ||||||
|     std::cout << "Input file does not exist!" << std::endl; |     std::cout << "Input file " + input.filename + " does not exist!" << std::endl; | ||||||
|     return 1; |     return 1; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user