mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
feat: passing args to component in entity definition
This commit is contained in:
parent
f2aa77db8b
commit
f6be6689aa
5 changed files with 33 additions and 7 deletions
|
|
@ -173,9 +173,9 @@ entityid_t Entities::spawn(
|
|||
auto& scripting = registry.emplace<ScriptComponents>(entity);
|
||||
registry.emplace<rigging::Skeleton>(entity, skeleton->instance());
|
||||
|
||||
for (auto& componentName : def.components) {
|
||||
for (auto& instance : def.components) {
|
||||
auto component = std::make_unique<UserComponent>(
|
||||
componentName, EntityFuncsSet {}, nullptr
|
||||
instance.component, EntityFuncsSet {}, nullptr, instance.params
|
||||
);
|
||||
scripting.components.emplace_back(std::move(component));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,11 +80,18 @@ struct UserComponent {
|
|||
std::string name;
|
||||
EntityFuncsSet funcsset;
|
||||
scriptenv env;
|
||||
dv::value params;
|
||||
|
||||
UserComponent(
|
||||
const std::string& name, EntityFuncsSet funcsset, scriptenv env
|
||||
const std::string& name,
|
||||
EntityFuncsSet funcsset,
|
||||
scriptenv env,
|
||||
dv::value params
|
||||
)
|
||||
: name(name), funcsset(funcsset), env(env) {
|
||||
: name(name),
|
||||
funcsset(funcsset),
|
||||
env(std::move(env)),
|
||||
params(std::move(params)) {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <glm/glm.hpp>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "data/dv.hpp"
|
||||
#include "maths/aabb.hpp"
|
||||
#include "physics/Hitbox.hpp"
|
||||
|
||||
|
|
@ -12,12 +13,17 @@ namespace rigging {
|
|||
class SkeletonConfig;
|
||||
}
|
||||
|
||||
struct ComponentInstance {
|
||||
std::string component;
|
||||
dv::value params;
|
||||
};
|
||||
|
||||
struct EntityDef {
|
||||
/// @brief Entity string id (with prefix included)
|
||||
std::string const name;
|
||||
|
||||
/// @brief Component IDs
|
||||
std::vector<std::string> components;
|
||||
/// @brief Component instances
|
||||
std::vector<ComponentInstance> components;
|
||||
|
||||
/// @brief Physic body type
|
||||
BodyType bodyType = BodyType::DYNAMIC;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue