add entity events: on_aim_on, on_aim_off
This commit is contained in:
parent
54902d7f49
commit
a36ffaacd9
@ -357,6 +357,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
||||
if (vox) {
|
||||
maxDistance = glm::distance(camera->position, end);
|
||||
}
|
||||
auto prevEntity = selection.entity;
|
||||
selection.entity = ENTITY_NONE;
|
||||
selection.actualPosition = iend;
|
||||
if (auto result = level->entities->rayCast(
|
||||
@ -367,6 +368,18 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
||||
selection.actualPosition = selection.position;
|
||||
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) {
|
||||
selection.vox = {BLOCK_VOID, {}};
|
||||
return nullptr;
|
||||
|
||||
@ -346,6 +346,8 @@ void scripting::on_entity_spawn(
|
||||
funcsset.on_sensor_enter = lua::hasfield(L, "on_sensor_enter");
|
||||
funcsset.on_sensor_exit = lua::hasfield(L, "on_sensor_exit");
|
||||
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);
|
||||
|
||||
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() {
|
||||
auto L = lua::get_main_thread();
|
||||
lua::get_from(L, STDCOMP, "update", true);
|
||||
|
||||
@ -93,6 +93,8 @@ namespace scripting {
|
||||
void on_entities_render();
|
||||
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_aim_on(const Entity& entity, Player* player);
|
||||
void on_aim_off(const Entity& entity, Player* player);
|
||||
|
||||
/// @brief Called on UI view show
|
||||
void on_ui_open(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user