R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ComponentBindingHelper.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** rtype
4** File description:
5** ComponentBindingHelper implementation
6*/
7
9
11
13 for (const auto &binding : _bindings) {
14 binding.bindFunc(lua);
15 }
16 }
17
18 void ComponentBindingHelper::applyEntityMethods(sol::usertype<ecs::wrapper::Entity> &entityType) {
19 for (const auto &[name, getter] : _getters) {
20 std::string getMethodName = "get" + name;
21 entityType[getMethodName] = getter;
22 }
23
24 for (const auto &[name, checker] : _hasCheckers) {
25 std::string hasMethodName = "has" + name;
26 entityType[hasMethodName] = checker;
27 }
28 }
29
31 lua.set_function("removeComponent",
32 [this, world](ecs::Address addr, const std::string &componentName) {
33 auto it = _removers.find(componentName);
34 if (it != _removers.end()) {
35 auto entity = world->getEntity(addr);
36 if (entity.isValid()) {
37 it->second(entity);
38 }
39 }
40 });
41 }
42
43 const std::vector<ComponentBinding> &ComponentBindingHelper::getBindings() const {
44 return _bindings;
45 }
46
47 void ComponentBindingHelper::clear() {
48 _bindings.clear();
49 _getters.clear();
50 _hasCheckers.clear();
51 _removers.clear();
52 }
53
54} // namespace scripting::bindings
High-level ECS manager providing clean server-side API.
Definition ECSWorld.hpp:122
void applyComponentBindings(sol::state &lua)
Apply all component bindings to the Lua state.
std::unordered_map< std::string, std::function< void(ecs::wrapper::Entity &)> > _removers
std::unordered_map< std::string, std::function< sol::object(ecs::wrapper::Entity &, sol::this_state)> > _getters
void applyRemoveFunction(sol::state &lua, ecs::wrapper::ECSWorld *world)
Create the global removeComponent function for all components.
std::unordered_map< std::string, std::function< bool(ecs::wrapper::Entity &)> > _hasCheckers
void applyEntityMethods(sol::usertype< ecs::wrapper::Entity > &entityType)
Apply get/has methods on Entity for all components.
std::uint32_t Address
Type used to represent an entity address/ID.