Browse Source

Component: Add ability to load TextAreaComponent from JSON

master
Riyyi 2 years ago
parent
commit
e1d88a1872
  1. 1
      assets/scene/scene1.json
  2. 34
      src/inferno/component/textareacomponent.cpp
  3. 3
      src/inferno/component/textareacomponent.h

1
assets/scene/scene1.json

@ -39,6 +39,7 @@
],
"text": [
{
"name": "Text",
"content": "HelloWorld!",
"font": "assets/fnt/dejavu-sans",
"font-size": 0,

34
src/inferno/component/textareacomponent.cpp

@ -0,0 +1,34 @@
/*
* Copyright (C) 2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#include "ruc/json/json.h"
#include "inferno/component/textareacomponent.h"
namespace Inferno {
void fromJson(const ruc::Json& json, TextAreaComponent& value)
{
VERIFY(json.type() == ruc::Json::Type::Object);
if (json.exists("content") && json.at("content").type() == ruc::Json::Type::String) {
json.at("content").getTo(value.content);
}
if (json.exists("font") && json.at("font").type() == ruc::Json::Type::String) {
json.at("font").getTo(value.font);
}
if (json.exists("font-size") && json.at("font-size").type() == ruc::Json::Type::Number) {
json.at("font-size").getTo(value.fontSize);
}
if (json.exists("width") && json.at("width").type() == ruc::Json::Type::Number) {
json.at("width").getTo(value.width);
}
if (json.exists("lines") && json.at("lines").type() == ruc::Json::Type::Number) {
json.at("lines").getTo(value.width);
}
}
} // namespace Inferno

3
src/inferno/component/textareacomponent.h

@ -11,6 +11,7 @@
#include <utility> // std::move
#include "glm/ext/vector_float4.hpp" // glm::vec4
#include "ruc/json/json.h"
namespace Inferno {
@ -38,4 +39,6 @@ struct TextAreaComponent {
// float dropShadow { 0.0f };
};
void fromJson(const ruc::Json& json, TextAreaComponent& value);
} // namespace Inferno

Loading…
Cancel
Save