|
R-Type
Distributed multiplayer game engine in C++
|
Helper to simplify component registration. More...
#include <ComponentBindingHelper.hpp>

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 |
Helper to simplify component registration.
Instead of modifying 3 files, you register a component once: helper.add<Transform>("Transform", bindingFunc);
The helper automatically generates:
Definition at line 40 of file ComponentBindingHelper.hpp.
| void scripting::bindings::ComponentBindingHelper::add | ( | const std::string & | name, |
| std::function< void(sol::state &)> | bindFunc | ||
| ) |
Definition at line 116 of file ComponentBindingHelper.hpp.
References _bindings, _getters, _hasCheckers, _removers, ecs::wrapper::Entity::get(), ecs::wrapper::Entity::has(), and ecs::wrapper::Entity::remove().

| void scripting::bindings::ComponentBindingHelper::applyComponentBindings | ( | sol::state & | lua | ) |
Apply all component bindings to the Lua state.
| lua | Lua state |
Definition at line 12 of file ComponentBindingHelper.cpp.
References _bindings.
| void scripting::bindings::ComponentBindingHelper::applyEntityMethods | ( | sol::usertype< ecs::wrapper::Entity > & | entityType | ) |
Apply get/has methods on Entity for all components.
Automatically generates:
| entityType | The Entity usertype |
Definition at line 18 of file ComponentBindingHelper.cpp.
References _getters, and _hasCheckers.
Referenced by scripting::bindings::bindEntity().
| void scripting::bindings::ComponentBindingHelper::applyRemoveFunction | ( | sol::state & | lua, |
| ecs::wrapper::ECSWorld * | world | ||
| ) |
Create the global removeComponent function for all components.
| lua | Lua state |
| world | Pointer to the ECS world |
Definition at line 30 of file ComponentBindingHelper.cpp.
References _removers.
Referenced by scripting::bindings::bindEntity().
| void scripting::bindings::ComponentBindingHelper::clear | ( | ) |
Clear all registered components (for testing/reinitialization)
Definition at line 47 of file ComponentBindingHelper.cpp.
Referenced by scripting::bindings::bindComponents().
| const std::vector< ComponentBinding > & scripting::bindings::ComponentBindingHelper::getBindings | ( | ) | const |
Get the list of registered components.
Definition at line 43 of file ComponentBindingHelper.cpp.
| 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.
| T | Component type |
| name | Component name in Lua |
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().

|
private |
Definition at line 107 of file ComponentBindingHelper.hpp.
Referenced by add(), and applyComponentBindings().
|
private |
Definition at line 109 of file ComponentBindingHelper.hpp.
Referenced by add(), applyEntityMethods(), and registerComponent().
|
private |
Definition at line 110 of file ComponentBindingHelper.hpp.
Referenced by add(), applyEntityMethods(), and registerComponent().
|
private |
Definition at line 111 of file ComponentBindingHelper.hpp.
Referenced by add(), applyRemoveFunction(), and registerComponent().