R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
scripting::bindings::ComponentBindingHelper Class Reference

Helper to simplify component registration. More...

#include <ComponentBindingHelper.hpp>

Collaboration diagram for scripting::bindings::ComponentBindingHelper:
Collaboration graph

Public Member Functions

template<typename T >
void add (const std::string &name, std::function< void(sol::state &)> bindFunc)
 
template<typename T >
void registerComponent (const std::string &name)
 Register a component that's already been bound to Lua.
 
void applyComponentBindings (sol::state &lua)
 Apply all component bindings to the Lua state.
 
void applyEntityMethods (sol::usertype< ecs::wrapper::Entity > &entityType)
 Apply get/has methods on Entity for all components.
 
void applyRemoveFunction (sol::state &lua, ecs::wrapper::ECSWorld *world)
 Create the global removeComponent function for all components.
 
const std::vector< ComponentBinding > & getBindings () const
 Get the list of registered components.
 
void clear ()
 Clear all registered components (for testing/reinitialization)
 

Private Attributes

std::vector< ComponentBinding_bindings
 
std::unordered_map< std::string, std::function< sol::object(ecs::wrapper::Entity &, sol::this_state)> > _getters
 
std::unordered_map< std::string, std::function< bool(ecs::wrapper::Entity &)> > _hasCheckers
 
std::unordered_map< std::string, std::function< void(ecs::wrapper::Entity &)> > _removers
 

Detailed Description

Helper to simplify component registration.

Instead of modifying 3 files, you register a component once: helper.add<Transform>("Transform", bindingFunc);

The helper automatically generates:

  • entity:getTransform()
  • entity:hasTransform()
  • removeComponent(addr, "Transform")

Definition at line 40 of file ComponentBindingHelper.hpp.

Member Function Documentation

◆ add()

template<typename T >
void scripting::bindings::ComponentBindingHelper::add ( const std::string &  name,
std::function< void(sol::state &)>  bindFunc 
)

◆ applyComponentBindings()

void scripting::bindings::ComponentBindingHelper::applyComponentBindings ( sol::state &  lua)

Apply all component bindings to the Lua state.

Parameters
luaLua state
Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 12 of file ComponentBindingHelper.cpp.

References _bindings.

◆ applyEntityMethods()

void scripting::bindings::ComponentBindingHelper::applyEntityMethods ( sol::usertype< ecs::wrapper::Entity > &  entityType)

Apply get/has methods on Entity for all components.

Automatically generates:

  • entity:getTransform(), entity:getVelocity(), etc.
  • entity:hasTransform(), entity:hasVelocity(), etc.
Parameters
entityTypeThe Entity usertype
Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 18 of file ComponentBindingHelper.cpp.

References _getters, and _hasCheckers.

Referenced by scripting::bindings::bindEntity().

◆ applyRemoveFunction()

void scripting::bindings::ComponentBindingHelper::applyRemoveFunction ( sol::state &  lua,
ecs::wrapper::ECSWorld world 
)

Create the global removeComponent function for all components.

Parameters
luaLua state
worldPointer to the ECS world
Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 30 of file ComponentBindingHelper.cpp.

References _removers.

Referenced by scripting::bindings::bindEntity().

◆ clear()

void scripting::bindings::ComponentBindingHelper::clear ( )

Clear all registered components (for testing/reinitialization)

Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 47 of file ComponentBindingHelper.cpp.

Referenced by scripting::bindings::bindComponents().

◆ getBindings()

const std::vector< ComponentBinding > & scripting::bindings::ComponentBindingHelper::getBindings ( ) const

Get the list of registered components.

Returns
const std::vector<ComponentBinding>& List of bindings
Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 43 of file ComponentBindingHelper.cpp.

◆ registerComponent()

template<typename T >
void scripting::bindings::ComponentBindingHelper::registerComponent ( const std::string &  name)

Register a component that's already been bound to Lua.

Simplified version of add() that doesn't require a binding function. Use this when you've already created the Lua usertype manually.

Template Parameters
TComponent type
Parameters
nameComponent name in Lua
Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 146 of file ComponentBindingHelper.hpp.

References _getters, _hasCheckers, _removers, ecs::wrapper::Entity::get(), ecs::wrapper::Entity::has(), and ecs::wrapper::Entity::remove().

Referenced by scripting::bindings::bindComponents().

Here is the call graph for this function:

Member Data Documentation

◆ _bindings

std::vector<ComponentBinding> scripting::bindings::ComponentBindingHelper::_bindings
private

◆ _getters

std::unordered_map<std::string, std::function<sol::object(ecs::wrapper::Entity &, sol::this_state)> > scripting::bindings::ComponentBindingHelper::_getters
private

◆ _hasCheckers

std::unordered_map<std::string, std::function<bool(ecs::wrapper::Entity &)> > scripting::bindings::ComponentBindingHelper::_hasCheckers
private

◆ _removers

std::unordered_map<std::string, std::function<void(ecs::wrapper::Entity &)> > scripting::bindings::ComponentBindingHelper::_removers
private

The documentation for this class was generated from the following files: