16 changed files with 383 additions and 101 deletions
			
			
		@ -1,50 +1,68 @@ | 
				
			|||||||
{ | 
					{ | 
				
			||||||
	"init": "assets/lua/scene1-init.lua", | 
						"init": "assets/lua/scene1-init.lua", | 
				
			||||||
	"camera": { | 
						"entities": [ | 
				
			||||||
		"name": "Camera", | 
					 | 
				
			||||||
		"translate": [ 0.0, 0.0, 1.0 ], | 
					 | 
				
			||||||
		"rotate": [ 0.0, 0.0, -1.0 ], | 
					 | 
				
			||||||
		"scale": [ 1.0, 1.0, 1.0 ], | 
					 | 
				
			||||||
		"type": "perspective", | 
					 | 
				
			||||||
		"script": { | 
					 | 
				
			||||||
			"type": "lua", | 
					 | 
				
			||||||
			"name": "assets/lua/cameracontroller.lua" | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
	}, | 
					 | 
				
			||||||
	"quad": [ | 
					 | 
				
			||||||
		{ | 
							{ | 
				
			||||||
			"name": "Quad", | 
								"id": { "id": 12312312 }, | 
				
			||||||
			"translate": [ 0.0, 0.0, 0.0 ], | 
								"tag": { "tag": "Camera" }, | 
				
			||||||
			"rotate": [ 0.0, 0.0, 0.0 ], | 
								"transform" : { | 
				
			||||||
			"scale": [ 1.0, 1.0, 1.0 ], | 
									"translate": [0.0, 0.0, 1.0], | 
				
			||||||
			"color": [ 1.0, 1.0, 1.0, 1.0 ], | 
									"rotate": [0.0, 0.0, -1.0], | 
				
			||||||
			"texture": "assets/gfx/test.png" | 
									"scale": [1.0, 1.0, 1.0] | 
				
			||||||
 | 
								}, | 
				
			||||||
 | 
								"camera": { "type": "perspective" }, | 
				
			||||||
 | 
								"lua-scripts": [ | 
				
			||||||
 | 
									{ "path": "assets/lua/cameracontroller.lua" } | 
				
			||||||
 | 
								] | 
				
			||||||
		}, | 
							}, | 
				
			||||||
		{ | 
							{ | 
				
			||||||
			"name": "Quad 2", | 
								"id": { "id": 564564564 }, | 
				
			||||||
			"translate": [ 1.1, 0.0, 0.0 ], | 
								"tag": { "tag": "Quad" }, | 
				
			||||||
			"rotate": [ 0.0, 0.0, 0.0 ], | 
								"transform" : { | 
				
			||||||
			"scale": [ 1.0, 1.0, 1.0 ], | 
									"translate": [ 0.0, 0.0, 0.0 ], | 
				
			||||||
			"color": [ 0.5, 0.6, 0.8, 1.0 ], | 
									"rotate": [ 0.0, 0.0, 0.0 ], | 
				
			||||||
			"texture": "assets/gfx/test.png" | 
									"scale": [ 1.0, 1.0, 1.0 ] | 
				
			||||||
 | 
								}, | 
				
			||||||
 | 
								"sprite": { | 
				
			||||||
 | 
									"color": [ 1.0, 1.0, 1.0, 1.0 ], | 
				
			||||||
 | 
									"texture": "assets/gfx/test.png" | 
				
			||||||
 | 
								} | 
				
			||||||
		}, | 
							}, | 
				
			||||||
		{ | 
							{ | 
				
			||||||
			"name": "Quad 3", | 
								"id": { "id": 97897897 }, | 
				
			||||||
			"translate": [ 2.2, 0.0, 0.0 ], | 
								"tag": { "tag": "Quad 2" }, | 
				
			||||||
			"rotate": [ 0.0, 0.0, 0.0 ], | 
								"transform" : { | 
				
			||||||
			"scale": [ 1.0, 1.0, 1.0 ], | 
									"translate": [ 1.1, 0.0, 0.0 ], | 
				
			||||||
			"color": [ 1.0, 1.0, 1.0, 1.0 ], | 
									"rotate": [ 0.0, 0.0, 0.0 ], | 
				
			||||||
			"texture": "assets/gfx/test-inverted.png" | 
									"scale": [ 1.0, 1.0, 1.0 ] | 
				
			||||||
		} | 
								}, | 
				
			||||||
	], | 
								"sprite": { | 
				
			||||||
	"text": [ | 
									"color": [ 0.5, 0.6, 0.8, 1.0 ], | 
				
			||||||
 | 
									"texture": "assets/gfx/test.png" | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
							}, | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								"id": { "id": 3424242 }, | 
				
			||||||
 | 
								"tag": { "tag": "Quad 3" }, | 
				
			||||||
 | 
								"transform" : { | 
				
			||||||
 | 
									"translate": [ 2.2, 0.0, 0.0 ], | 
				
			||||||
 | 
									"rotate": [ 0.0, 0.0, 0.0 ], | 
				
			||||||
 | 
									"scale": [ 1.0, 1.0, 1.0 ] | 
				
			||||||
 | 
								}, | 
				
			||||||
 | 
								"sprite": { | 
				
			||||||
 | 
									"color": [ 1.0, 1.0, 1.0, 1.0 ], | 
				
			||||||
 | 
									"texture": "assets/gfx/test-inverted.png" | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
							}, | 
				
			||||||
		{ | 
							{ | 
				
			||||||
			"name": "Text", | 
								"id": { "id": 675754 }, | 
				
			||||||
			"content": "Hello World!", | 
								"tag": { "tag": "Text" }, | 
				
			||||||
			"font": "assets/fnt/open-sans", | 
								"text": { | 
				
			||||||
			"font-size": 24, | 
									"content": "Hello World!", | 
				
			||||||
			"line-spacing": 1.0, | 
									"font": "assets/fnt/open-sans", | 
				
			||||||
			"width": 150 | 
									"font-size": 24, | 
				
			||||||
 | 
									"line-spacing": 1.0, | 
				
			||||||
 | 
									"width": 150 | 
				
			||||||
 | 
								} | 
				
			||||||
		} | 
							} | 
				
			||||||
	] | 
						] | 
				
			||||||
} | 
					} | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,26 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/format/print.h" | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/component/cameracomponent.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, CameraComponent& value) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						VERIFY(json.type() == ruc::Json::Type::Object); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (json.exists("type")) { | 
				
			||||||
 | 
							value.type = json.at("type").get<std::string>() == "orthographic" ? CameraType::Orthographic : CameraType::Perspective; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						if (json.exists("zoom-level")) { | 
				
			||||||
 | 
							json.at("zoom-level").getTo(value.zoomLevel); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,22 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/component/id-component.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, IDComponent& value) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						VERIFY(json.type() == ruc::Json::Type::Object); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (json.exists("id")) { | 
				
			||||||
 | 
							json.at("id").getTo(value.id); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,28 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/uid.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct IDComponent { | 
				
			||||||
 | 
						UID id; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						IDComponent() = default; | 
				
			||||||
 | 
						IDComponent(UID id) | 
				
			||||||
 | 
							: id(id) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						IDComponent(const IDComponent&) = default; | 
				
			||||||
 | 
					}; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, IDComponent& value); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,21 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/component/luascriptcomponent.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, LuaScriptComponent& value) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						VERIFY(json.type() == ruc::Json::Type::Object); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						VERIFY(json.exists("path"), "path not found"); | 
				
			||||||
 | 
						json.at("path").getTo(value.path); | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,21 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/component/nativescriptcomponent.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, NativeScriptComponent& value) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						VERIFY(json.type() == ruc::Json::Type::Object); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						VERIFY(json.exists("name"), "name not found"); | 
				
			||||||
 | 
						json.at("name").getTo(value.name); | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,22 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/component/tagcomponent.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, TagComponent& value) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						VERIFY(json.type() == ruc::Json::Type::Object); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (json.exists("tag")) { | 
				
			||||||
 | 
							json.at("tag").getTo(value.tag); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,38 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <cstdint> | 
				
			||||||
 | 
					#include <random> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/format/log.h" | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inferno/uid.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static std::random_device s_seed; | 
				
			||||||
 | 
					static std::mt19937_64 s_engine(s_seed()); | 
				
			||||||
 | 
					static std::uniform_int_distribution<uint64_t> s_distribution; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					UID::UID() | 
				
			||||||
 | 
						: m_uid(s_distribution(s_engine)) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					UID::UID(uint64_t uid) | 
				
			||||||
 | 
						: m_uid(uid) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, UID& value) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						VERIFY(json.type() == ruc::Json::Type::Number); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						value = UID((int64_t)json.asDouble()); | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
@ -0,0 +1,47 @@ | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2023 Riyyi | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <cstdint> // uint64_t | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ruc/json/json.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Inferno { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UID { | 
				
			||||||
 | 
					public: | 
				
			||||||
 | 
						UID(); | 
				
			||||||
 | 
						UID(uint64_t uid); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Comparison operator for std::map
 | 
				
			||||||
 | 
						bool operator<(const UID& other) const | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return m_uid < other.m_uid; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						operator uint64_t() const { return m_uid; } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private: | 
				
			||||||
 | 
						uint64_t m_uid; | 
				
			||||||
 | 
					}; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fromJson(const ruc::Json& json, UID& value); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Inferno
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace std { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Hash function for std::unordered_map
 | 
				
			||||||
 | 
					template<> | 
				
			||||||
 | 
					struct hash<Inferno::UID> { | 
				
			||||||
 | 
						size_t operator()(const Inferno::UID& uid) const | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return hash<uint64_t>()(static_cast<uint64_t>(uid)); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					}; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace std
 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue