Lua
Functions | Description |
trigger an event with the c++ dispatcher |
Functions | Description |
create an entity. | |
destroy an entity | |
get the numbers of entities | |
checks whether the requested component is associated with the given entity | |
get the component linked to the given entity | |
remove the component linked to the given entity | |
add the component to the given entity |
This function trigger an event using the EnTT dispatcher.
-- Global signature
shiva.dispatcher:trigger_[event_name]_event(evt_arg);
-- Example of generated one
shiva.dispatcher:trigger_quit_game_event(evt_arg);
Parameters
Name | Description |
evt_arg | type -> constructor of the current_event |
Example
function on_key_pressed(evt)
if (evt.keycode == Keyboard.Escape) then
-- quit_game.hpp take a integer as argument for his construction
shiva.dispatcher:trigger_quit_game_event(1)
end
end
This function create an entity through the EnTT registry and return an unique identifier.
shiva.entity_registry:create();
Return value
Possible name | Description |
entity_id | integer
|
Example
function foo()
local entity_id = shiva.entity_registry:create()
end
This function destroy an entity through the EnTT registry.
shiva.entity_registry:destroy(entity_id);
Parameters
Name | Description |
entity_id | integer
|
Example
function foo()
local id = shiva.entity_registry:create()
shiva.entity_registry:destroy(id)
end
This function retrieve the number of entities through the EnTT registry
shiva.entity_registry:nb_entities()
Return value
Possible name | Description |
nb_entities | integer
|
Example
function foo()
local id = shiva.entity_registry:create()
assert(shiva.entity_registry:nb_entities() == 1)
shiva.entity_registry:destroy(id)
assert(shiva.entity_registry:nb_entities() == 0)
end
This function checks whether the requested component is associated with the given entity through the EnTT registry
All those functions are automatically generated based on the common components.
-- Global signature
shiva.entity_registry:has_[component_name]_component(entity_id);
-- Example of generated one
shiva.entity_registry:has_layer_1_component(entity_id);
Parameters
Name | Description |
entity_id | integer
|
Return value
Possible name | Description |
result | boolean
|
Example
function foo()
local entity_id = shiva.entity_registry:create()
local component = shiva.entity_registry:add_layer_1_component(entity_id)
local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
shiva.entity_registry:remove_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end
This function takes an entity as a parameter and retrieves the component associated with it through the EnTT registry.
All those functions are automatically generated based on the common components.
-- Global signature
shiva.entity_registry:get_[component_name]_component(entity_id);
-- Example of generated one
shiva.entity_registry:get_layer_1_component(entity_id);
Parameters
Name | Description |
entity_id | integer
|
Return value
Possible Name | Description |
same_component | Component &
|
Example
function foo()
local entity_id = shiva.entity_registry:create()
local component = shiva.entity_registry:add_layer_1_component(entity_id)
local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
shiva.entity_registry:remove_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end
This function takes an entity as a parameter and remove the component associated with it through the EnTT registry.
All those functions are automatically generated based on the common components.
-- Global signature
shiva.entity_registry:remove_[component_name]_component(entity_id);
-- Example of generated one
shiva.entity_registry:remove_layer_1_component(entity_id);
Parameters
Name | Description |
entity_id | integer
|
Example
function foo()
local entity_id = shiva.entity_registry:create()
local component = shiva.entity_registry:add_layer_1_component(entity_id)
local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
shiva.entity_registry:remove_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end
This function takes an entity as a parameter and add the component through the EnTT registry, and return a reference to the component.
All those functions are automatically generated based on the common components.
-- Global signature
shiva.entity_registry:add_[component_name]_component(entity_id);
-- Example of generated one
shiva.entity_registry:add_layer_1_component(entity_id);
Parameters
Name | Description |
entity_id | integer
|
Return value
Possible name | Description |
component | Component &
|
Example
function foo()
local entity_id = shiva.entity_registry:create()
local component = shiva.entity_registry:add_layer_1_component(entity_id)
local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
shiva.entity_registry:remove_layer_1_component(entity_id)
assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end
Last modified 4yr ago