R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
EntityBindings.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** rtype
4** File description:
5** EntityBindings - Simplified version with helper
6*/
7
8#include "EntityBindings.hpp"
9
11 ComponentBindingHelper &helper) {
12 // Create the Entity usertype
13 sol::usertype<ecs::wrapper::Entity> entity_type =
14 lua.new_usertype<ecs::wrapper::Entity>("Entity", sol::no_constructor);
15
16 // Basic Entity methods
17 entity_type["getAddress"] = &ecs::wrapper::Entity::getAddress;
18 entity_type["isValid"] = &ecs::wrapper::Entity::isValid;
19
20 // Add destroy() method
21 entity_type["destroy"] = [world](ecs::wrapper::Entity &entity) {
22 if (entity.isValid()) {
23 world->destroyEntity(entity.getAddress());
24 }
25 };
26
27 helper.applyEntityMethods(entity_type);
28
29 // Automatically generate the removeComponent function
30 helper.applyRemoveFunction(lua, world);
31
32 LOG_INFO("Entity bindings initialized with error handling");
33}
#define LOG_INFO(...)
Definition Logger.hpp:181
High-level ECS manager providing clean server-side API.
Definition ECSWorld.hpp:122
void destroyEntity(const Entity &entity)
Destroy an entity and remove it from the world.
Definition ECSWorld.cpp:87
High-level entity wrapper providing fluent interface.
Definition ECSWorld.hpp:33
Address getAddress() const
Get the entity's address.
Definition ECSWorld.cpp:39
bool isValid() const
Check if this entity is valid.
Definition ECSWorld.cpp:43
Helper to simplify component registration.
void applyRemoveFunction(sol::state &lua, ecs::wrapper::ECSWorld *world)
Create the global removeComponent function for all components.
void applyEntityMethods(sol::usertype< ecs::wrapper::Entity > &entityType)
Apply get/has methods on Entity for all components.
void bindEntity(sol::state &lua, ecs::wrapper::ECSWorld *world, ComponentBindingHelper &helper)
Bind Entity wrapper class and operations to Lua.