Lua

Events

Entity Registry

Events API Documentation

shiva.dispatcher:trigger_[event_name]_event

This function trigger an event using the EnTT dispatcher.

All those functions are automatically generated based on shiva::event.

-- Global signature
shiva.dispatcher:trigger_[event_name]_event(evt_arg);

-- Example of generated one
shiva.dispatcher:trigger_quit_game_event(evt_arg);

Parameters

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

Entity Registry API Documentation

shiva.entity_registry:create

This function create an entity through the EnTT registry and return an unique identifier.

shiva.entity_registry:create();

Return value

Example

function foo()
    local entity_id = shiva.entity_registry:create()
end

shiva.entity_registry:destroy

This function destroy an entity through the EnTT registry.

shiva.entity_registry:destroy(entity_id);

Parameters

Example

function foo()
    local id = shiva.entity_registry:create()
    shiva.entity_registry:destroy(id)
end

shiva.entity_registry:nb_entities

This function retrieve the number of entities through the EnTT registry

shiva.entity_registry:nb_entities()

Return value

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

shiva.entity_registry:has_[component_name]_component

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

Return value

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

shiva.entity_registry:get_[component_name]_component

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

Return value

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

shiva.entity_registry:remove_[component_name]_component

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

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

shiva.entity_registry:add_[component_name]_component

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

Return value

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 updated