R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ComponentBindings.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** rtype
4** File description:
5** ComponentBindings - Simplified version with helper
6*/
7
10
14
15namespace scripting::bindings {
16
18
20 (void)world; // Parameter may be reserved for future use
21
22 // Clear previous registrations to ensure clean state (important for tests)
24
25 // Bind Transform to Lua
26 auto transform_type = lua.new_usertype<ecs::Transform>(
27 "Transform", sol::constructors<ecs::Transform(), ecs::Transform(float, float)>());
28
29 transform_type["x"] = sol::property([](ecs::Transform &t) { return t.getPosition().x; },
30 [](ecs::Transform &t, float x) {
31 auto pos = t.getPosition();
32 t.setPosition(x, pos.y);
33 });
34
35 transform_type["y"] = sol::property([](ecs::Transform &t) { return t.getPosition().y; },
36 [](ecs::Transform &t, float y) {
37 auto pos = t.getPosition();
38 t.setPosition(pos.x, y);
39 });
40
41 transform_type["getRotation"] = &ecs::Transform::getRotation;
42 transform_type["setRotation"] = &ecs::Transform::setRotation;
43
44 // Register with helper for Entity methods generation
46
47 // Bind Velocity to Lua
48 auto velocity_type = lua.new_usertype<ecs::Velocity>(
49 "Velocity", sol::constructors<ecs::Velocity(float, float, float)>());
50
51 velocity_type["dirX"] = sol::property([](ecs::Velocity &v) { return v.getDirection().x; },
52 [](ecs::Velocity &v, float x) {
53 auto dir = v.getDirection();
54 v.setDirection(x, dir.y);
55 });
56
57 velocity_type["dirY"] = sol::property([](ecs::Velocity &v) { return v.getDirection().y; },
58 [](ecs::Velocity &v, float y) {
59 auto dir = v.getDirection();
60 v.setDirection(dir.x, y);
61 });
62
63 velocity_type["speed"] = sol::property(&ecs::Velocity::getSpeed, &ecs::Velocity::setSpeed);
64
65 // Register with helper
67
68 // Bind Health to Lua
69 auto health_type = lua.new_usertype<ecs::Health>(
70 "Health", sol::constructors<ecs::Health(int), ecs::Health(int, int)>());
71
72 health_type["currentHealth"] =
74
75 health_type["maxHealth"] = sol::property(&ecs::Health::getMaxHealth, &ecs::Health::setMaxHealth);
76
77 health_type["invincible"] = sol::property(&ecs::Health::isInvincible, &ecs::Health::setInvincible);
78
79 health_type["invincibilityTimer"] =
81
82 // Register with helper
84
85 return g_componentHelper;
86 }
87
88} // namespace scripting::bindings
Component representing entity health and invincibility.
Definition Health.hpp:20
int getCurrentHealth() const
Get current health points.
Definition Health.hpp:44
bool isInvincible() const
Check if entity is invincible.
Definition Health.hpp:56
void setInvincible(bool invincible)
Set invincibility state.
Definition Health.hpp:80
float getInvincibilityTimer() const
Get remaining invincibility time.
Definition Health.hpp:62
void setInvincibilityTimer(float timer)
Set invincibility timer.
Definition Health.hpp:86
void setCurrentHealth(int health)
Set current health.
Definition Health.hpp:74
int getMaxHealth() const
Get maximum health points.
Definition Health.hpp:50
void setMaxHealth(int health)
Set maximum health.
Definition Health.hpp:68
Component representing position, rotation and scale in 2D space.
Definition Transform.hpp:20
float getRotation() const
Get the rotation angle.
Definition Transform.hpp:67
void setRotation(float rotation)
Set the rotation angle.
Definition Transform.hpp:89
Vector2 getPosition() const
Get the position vector.
Definition Transform.hpp:61
void setPosition(float posX, float posY)
Set the position.
Definition Transform.hpp:80
Component representing movement direction and speed.
Definition Velocity.hpp:20
Vector2 getDirection() const
Get the direction vector.
Definition Velocity.hpp:45
void setSpeed(float speed)
Set the movement speed.
Definition Velocity.hpp:73
float getSpeed() const
Get the movement speed.
Definition Velocity.hpp:51
void setDirection(float dirX, float dirY)
Set the direction vector.
Definition Velocity.hpp:64
High-level ECS manager providing clean server-side API.
Definition ECSWorld.hpp:122
Helper to simplify component registration.
void registerComponent(const std::string &name)
Register a component that's already been bound to Lua.
void clear()
Clear all registered components (for testing/reinitialization)
ComponentBindingHelper & bindComponents(sol::state &lua, ecs::wrapper::ECSWorld *world)
Bind ECS component types to Lua.
static ComponentBindingHelper g_componentHelper