Browse Source

Scene: Load quads from JSON

master
Riyyi 2 years ago
parent
commit
3db5845bb4
  1. 34
      src/inferno/scene/scene.cpp

34
src/inferno/scene/scene.cpp

@ -40,18 +40,14 @@ void Scene::initialize()
ScriptSystem::the().setScene(this); ScriptSystem::the().setScene(this);
TextAreaSystem::the().setScene(this); TextAreaSystem::the().setScene(this);
// Load assets
// ---------------------------------
m_texture = TextureManager::the().load("assets/gfx/test.png");
m_texture2 = TextureManager::the().load("assets/gfx/test-inverted.png");
// Load scene .json // Load scene .json
// ------------------------------------- // -------------------------------------
auto sceneJson = ruc::Json::parse(ruc::File("assets/scene/scene1.json").data()); auto sceneJson = ruc::Json::parse(ruc::File("assets/scene/scene1.json").data());
VERIFY(sceneJson.exists("camera"), "scene doesnt contain a camera");
// Camera
VERIFY(sceneJson.exists("camera"), "scene doesnt contain a camera");
auto& cameraJson = sceneJson.at("camera"); auto& cameraJson = sceneJson.at("camera");
uint32_t camera = loadEntity(cameraJson); uint32_t camera = loadEntity(cameraJson);
@ -73,21 +69,19 @@ void Scene::initialize()
} }
} }
// Construct entities // Quads
// ---------------------------------
uint32_t quad = createEntity("Quad");
addComponent<SpriteComponent>(quad, glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture);
uint32_t quad2 = createEntity("Quad 2"); if (sceneJson.exists("quad") && sceneJson.at("quad").type() == ruc::Json::Type::Array) {
auto& quad2Transform = getComponent<TransformComponent>(quad2); auto& quads = sceneJson.at("quad").asArray().elements();
quad2Transform.translate.x = 1.1f; for (const auto& quad : quads) {
addComponent<SpriteComponent>(quad2, glm::vec4 { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture); uint32_t quadEntity = loadEntity(quad);
addComponent<SpriteComponent>(quadEntity);
auto& spriteComponent = getComponent<SpriteComponent>(quadEntity);
quad.getTo(spriteComponent);
}
}
uint32_t quad3 = createEntity("Quad 3"); // Text
auto& quad3Transform = getComponent<TransformComponent>(quad3);
quad3Transform.translate.x = 2.2f;
addComponent<SpriteComponent>(quad3, glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
uint32_t text = createEntity("Text"); uint32_t text = createEntity("Text");
addComponent<TextAreaComponent>(text, "HelloWorld!", "assets/fnt/dejavu-sans", 0, 150, 3); addComponent<TextAreaComponent>(text, "HelloWorld!", "assets/fnt/dejavu-sans", 0, 150, 3);

Loading…
Cancel
Save