add user properties methods support items
This commit is contained in:
parent
e3da256c5d
commit
d59a901ae0
@ -1,5 +1,6 @@
|
||||
#define VC_ENABLE_REFLECTION
|
||||
#include "ContentUnitLoader.hpp"
|
||||
#include "ContentLoadingCommons.hpp"
|
||||
|
||||
#include "../ContentBuilder.hpp"
|
||||
#include "coders/json.hpp"
|
||||
@ -87,20 +88,7 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||
Block& def, const std::string& name, const io::path& file
|
||||
) {
|
||||
auto root = io::read_json(file);
|
||||
if (def.properties == nullptr) {
|
||||
def.properties = dv::object();
|
||||
def.properties["name"] = name;
|
||||
}
|
||||
for (auto& [key, value] : root.asObject()) {
|
||||
auto pos = key.rfind('@');
|
||||
if (pos == std::string::npos) {
|
||||
def.properties[key] = value;
|
||||
continue;
|
||||
}
|
||||
auto field = key.substr(0, pos);
|
||||
auto suffix = key.substr(pos + 1);
|
||||
process_method(def.properties, suffix, field, value);
|
||||
}
|
||||
process_properties(def, name, root);
|
||||
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
|
||||
23
src/content/loading/ContentLoadingCommons.hpp
Normal file
23
src/content/loading/ContentLoadingCommons.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "data/dv.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
template <typename T>
|
||||
inline void process_properties(T& def, const std::string& name, const dv::value& root) {
|
||||
if (def.properties == nullptr) {
|
||||
def.properties = dv::object();
|
||||
def.properties["name"] = name;
|
||||
}
|
||||
for (auto& [key, value] : root.asObject()) {
|
||||
auto pos = key.rfind('@');
|
||||
if (pos == std::string::npos) {
|
||||
def.properties[key] = value;
|
||||
continue;
|
||||
}
|
||||
auto field = key.substr(0, pos);
|
||||
auto suffix = key.substr(pos + 1);
|
||||
process_method(def.properties, suffix, field, value);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
#define VC_ENABLE_REFLECTION
|
||||
#include "ContentUnitLoader.hpp"
|
||||
#include "ContentLoadingCommons.hpp"
|
||||
|
||||
#include "../ContentBuilder.hpp"
|
||||
#include "coders/json.hpp"
|
||||
@ -12,11 +13,12 @@
|
||||
|
||||
static debug::Logger logger("item-content-loader");
|
||||
|
||||
|
||||
template<> void ContentUnitLoader<ItemDef>::loadUnit(
|
||||
ItemDef& def, const std::string& name, const io::path& file
|
||||
) {
|
||||
auto root = io::read_json(file);
|
||||
def.properties = root;
|
||||
process_properties(def, name, root);
|
||||
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user