add entity.properties

This commit is contained in:
MihailRis 2026-10-19 21:46:30 +03:00
parent 3edb96e291
commit 283e3c041e
5 changed files with 84 additions and 11 deletions

View file

@ -123,6 +123,13 @@ std::unique_ptr<Content> ContentBuilder::build() {
def->properties["script-file"] = def->scriptFile;
}
for (EntityDef* def : entityDefsIndices) {
if (def->properties == nullptr) {
def->properties = dv::object();
}
def->properties["name"] = def->name;
}
for (auto& [name, def] : content->generators.getDefs()) {
def->prepare(content.get());
}

View file

@ -1,5 +1,6 @@
#define VC_ENABLE_REFLECTION
#include "ContentUnitLoader.hpp"
#include "ContentLoadingCommons.hpp"
#include "../ContentBuilder.hpp"
#include "coders/json.hpp"
@ -16,6 +17,7 @@ template<> void ContentUnitLoader<EntityDef>::loadUnit(
EntityDef& def, const std::string& name, const io::path& file
) {
auto root = io::read_json(file);
process_properties(def, name, root);
if (root.has("parent")) {
const auto& parentName = root["parent"].asString();

View file

@ -24,6 +24,7 @@
#include "world/Level.hpp"
#include "world/World.hpp"
#include "interfaces/Process.hpp"
#include "objects/EntityDef.hpp"
#include <iostream>
#include <stdexcept>
@ -298,6 +299,11 @@ void scripting::on_content_load(Content* content) {
lua::setfield(L, "properties");
lua::pop(L);
}
if (lua::getglobal(L, "entities")) {
push_properties_tables(L, indices.entities);
lua::setfield(L, "properties");
lua::pop(L);
}
lua::getregistry(L, "app");
lua::setglobal(L, "__vc_app");

View file

@ -19,6 +19,8 @@ struct EntityDef {
/// @brief Entity string id (with prefix included)
std::string const name;
dv::value properties = nullptr;
/// @brief Component instances
std::vector<ComponentInstance> components;