10#include "../../third_party/nlohmann/json.hpp"
20 inline std::string
GetString(
const json&
j,
const std::string&
key,
const std::string& defaultValue =
"")
22 if (
j.contains(
key) &&
j[
key].is_string()) {
23 return j[
key].get<std::string>();
29 inline int GetInt(
const json&
j,
const std::string&
key,
int defaultValue = 0)
31 if (
j.contains(
key) &&
j[
key].is_number_integer()) {
32 return j[
key].get<
int>();
38 inline float GetFloat(
const json&
j,
const std::string&
key,
float defaultValue = 0.0f)
40 if (
j.contains(
key) &&
j[
key].is_number()) {
41 return static_cast<float>(
j[
key].get<
double>());
49 if (
j.contains(
key) &&
j[
key].is_number()) {
50 return j[
key].get<
double>();
56 inline bool GetBool(
const json&
j,
const std::string&
key,
bool defaultValue =
false)
58 if (
j.contains(
key) &&
j[
key].is_boolean()) {
59 return j[
key].get<
bool>();
67 if (
j.contains(
key) &&
j[
key].is_array()) {
76 if (
j.contains(
key) &&
j[
key].is_object()) {
79 return json::object();
85 return j.contains(
key);
105 unsigned long value = 0;
108 value = std::stoul(
hex,
nullptr, 16);
114 if (
hex.length() == 6) {
118 return static_cast<int>(value);
127 return std::string(
buffer);
ComponentTypeID GetComponentTypeID_Static()
size_t GetArraySize(const json &j)
json GetObject(const json &j, const std::string &key)
double GetDouble(const json &j, const std::string &key, double defaultValue=0.0)
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
int GetInt(const json &j, const std::string &key, int defaultValue=0)
bool HasKey(const json &j, const std::string &key)
bool GetBool(const json &j, const std::string &key, bool defaultValue=false)
json GetArray(const json &j, const std::string &key)
std::string ColorToString(int color)
float GetFloat(const json &j, const std::string &key, float defaultValue=0.0f)
int ParseColor(const std::string &colorStr)