add entity events: on_aim_on, on_aim_off

This commit is contained in:
MihailRis
2024-07-16 13:42:58 +03:00
parent 54902d7f49
commit a36ffaacd9
3 changed files with 31 additions and 0 deletions
+13
View File
@@ -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;