R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
WorldBindings.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** rtype
4** File description:
5** WorldBindings
6*/
7
8#include "WorldBindings.hpp"
9
11
12 // createEntity -> Entity
13 lua.set_function("createEntity", [world]() -> ecs::wrapper::Entity {
14 if (!world) {
15 LOG_ERROR("World not set in LuaEngine");
16 throw std::runtime_error("World not initialized");
17 }
18 try {
19 return world->createEntity();
20 } catch (const std::exception &e) {
21 LOG_ERROR("Failed to create entity: " + std::string(e.what()));
22 throw;
23 }
24 });
25
26 // destroyEntity(Entity) -> void
27 lua.set_function("destroyEntity", [world](ecs::wrapper::Entity entity) {
28 if (!world) {
29 LOG_ERROR("World not set in LuaEngine");
30 return;
31 }
32 if (!entity.isValid()) {
33 LOG_WARNING("Attempted to destroy invalid entity");
34 return;
35 }
36 try {
37 world->destroyEntity(entity);
38 } catch (const std::exception &e) {
39 LOG_ERROR("Failed to destroy entity: " + std::string(e.what()));
40 }
41 });
42
43 // log(string message) -> void
44 lua.set_function("log", [](const std::string &message) { LOG_DEBUG("[LUA] " + message); });
45
46 // entityExists(addr) -> bool
47 lua.set_function("entityExists", [world](ecs::Address addr) -> bool {
48 if (!world) {
49 LOG_ERROR("World not set in LuaEngine");
50 return false;
51 }
52 try {
53 auto entity = world->getEntity(addr);
54 return entity.isValid();
55 } catch (const std::exception &e) {
56 LOG_ERROR("Error checking entity existence: " + std::string(e.what()));
57 return false;
58 }
59 });
60}
#define LOG_DEBUG(...)
Definition Logger.hpp:180
#define LOG_ERROR(...)
Definition Logger.hpp:183
#define LOG_WARNING(...)
Definition Logger.hpp:182
High-level ECS manager providing clean server-side API.
Definition ECSWorld.hpp:122
Entity createEntity()
Create a new entity.
Definition ECSWorld.cpp:67
Entity getEntity(Address address)
Get an entity wrapper from an address.
Definition ECSWorld.cpp:83
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
bool isValid() const
Check if this entity is valid.
Definition ECSWorld.cpp:43
std::uint32_t Address
Type used to represent an entity address/ID.
void bindWorld(sol::state &lua, ecs::wrapper::ECSWorld *world)
Bind ECS world operations to Lua.