add entity events: on_aim_on, on_aim_off
This commit is contained in:
@@ -357,6 +357,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
|||||||
if (vox) {
|
if (vox) {
|
||||||
maxDistance = glm::distance(camera->position, end);
|
maxDistance = glm::distance(camera->position, end);
|
||||||
}
|
}
|
||||||
|
auto prevEntity = selection.entity;
|
||||||
selection.entity = ENTITY_NONE;
|
selection.entity = ENTITY_NONE;
|
||||||
selection.actualPosition = iend;
|
selection.actualPosition = iend;
|
||||||
if (auto result = level->entities->rayCast(
|
if (auto result = level->entities->rayCast(
|
||||||
@@ -367,6 +368,18 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
|||||||
selection.actualPosition = selection.position;
|
selection.actualPosition = selection.position;
|
||||||
selection.normal = result->normal;
|
selection.normal = result->normal;
|
||||||
}
|
}
|
||||||
|
if (selection.entity != prevEntity) {
|
||||||
|
if (prevEntity != ENTITY_NONE) {
|
||||||
|
if (auto pentity = level->entities->get(prevEntity)) {
|
||||||
|
scripting::on_aim_off(*pentity, player.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selection.entity != ENTITY_NONE) {
|
||||||
|
if (auto pentity = level->entities->get(selection.entity)) {
|
||||||
|
scripting::on_aim_on(*pentity, player.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (vox == nullptr || selection.entity) {
|
if (vox == nullptr || selection.entity) {
|
||||||
selection.vox = {BLOCK_VOID, {}};
|
selection.vox = {BLOCK_VOID, {}};
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -346,6 +346,8 @@ void scripting::on_entity_spawn(
|
|||||||
funcsset.on_sensor_enter = lua::hasfield(L, "on_sensor_enter");
|
funcsset.on_sensor_enter = lua::hasfield(L, "on_sensor_enter");
|
||||||
funcsset.on_sensor_exit = lua::hasfield(L, "on_sensor_exit");
|
funcsset.on_sensor_exit = lua::hasfield(L, "on_sensor_exit");
|
||||||
funcsset.on_save = lua::hasfield(L, "on_save");
|
funcsset.on_save = lua::hasfield(L, "on_save");
|
||||||
|
funcsset.on_aim_on = lua::hasfield(L, "on_aim_on");
|
||||||
|
funcsset.on_aim_off = lua::hasfield(L, "on_aim_off");
|
||||||
lua::pop(L, 2);
|
lua::pop(L, 2);
|
||||||
|
|
||||||
component->env = compenv;
|
component->env = compenv;
|
||||||
@@ -423,6 +425,20 @@ void scripting::on_sensor_exit(const Entity& entity, size_t index, entityid_t oi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scripting::on_aim_on(const Entity& entity, Player* player) {
|
||||||
|
process_entity_callback(entity, "on_aim_on",
|
||||||
|
&entity_funcs_set::on_aim_on, [player](auto L) {
|
||||||
|
return lua::pushinteger(L, player->getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void scripting::on_aim_off(const Entity& entity, Player* player) {
|
||||||
|
process_entity_callback(entity, "on_aim_off",
|
||||||
|
&entity_funcs_set::on_aim_off, [player](auto L) {
|
||||||
|
return lua::pushinteger(L, player->getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void scripting::on_entities_update() {
|
void scripting::on_entities_update() {
|
||||||
auto L = lua::get_main_thread();
|
auto L = lua::get_main_thread();
|
||||||
lua::get_from(L, STDCOMP, "update", true);
|
lua::get_from(L, STDCOMP, "update", true);
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ namespace scripting {
|
|||||||
void on_entities_render();
|
void on_entities_render();
|
||||||
void on_sensor_enter(const Entity& entity, size_t index, entityid_t oid);
|
void on_sensor_enter(const Entity& entity, size_t index, entityid_t oid);
|
||||||
void on_sensor_exit(const Entity& entity, size_t index, entityid_t oid);
|
void on_sensor_exit(const Entity& entity, size_t index, entityid_t oid);
|
||||||
|
void on_aim_on(const Entity& entity, Player* player);
|
||||||
|
void on_aim_off(const Entity& entity, Player* player);
|
||||||
|
|
||||||
/// @brief Called on UI view show
|
/// @brief Called on UI view show
|
||||||
void on_ui_open(
|
void on_ui_open(
|
||||||
|
|||||||
Reference in New Issue
Block a user