add entities.name(...) and entity:get_name(...)

This commit is contained in:
MihailRis 2024-07-17 20:15:45 +03:00
parent ec4043bc12
commit 5a3f28f2b5
6 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,9 @@ entities.spawn(name: str, pos: vec3, [optional] args: table)
-- Checks the existence of an entity by a unique identifier.
entities.exists(uid: int) -> bool
-- Returns entity name (string ID).
entities.name(uid: int) -> str
-- Returns a table of all loaded entities
entities.get_all() -> table

View File

@ -15,6 +15,9 @@ The entity object is available in components as a global variable **entity**.
-- Deletes an entity (the entity may continue to exist until the frame ends, but will not be displayed in that frame)
entity:despawn()
-- Returns entity name (string ID)
entity:get_name()
-- Returns the name of the entity skeleton
entity:get_skeleton() -> str
-- Replaces the entity skeleton

View File

@ -15,6 +15,9 @@ entities.spawn(name: str, pos: vec3, [optional] args: table)
-- Проверяет наличие сущности по уникальному идентификатору.
entities.exists(uid: int) -> bool
-- Возвращает имя сущности (строковый ID).
entities.name(uid: int) -> str
-- Возвращает таблицу всех загруженных сущностей
entities.get_all() -> table

View File

@ -16,6 +16,9 @@ Lua.
-- Удаляет сущность (сущность может продолжать существовать до завершения кадра, но не будет отображена в этом кадре)
entity:despawn()
-- Возвращает имя сущности (строковый ID)
entity:get_name()
-- Возращает имя скелета сущности
entity:get_skeleton() -> str
-- Заменяет скелет сущности

View File

@ -62,6 +62,7 @@ local Entity = {__index={
get_component=function(self, name) return self.components[name] end,
has_component=function(self, name) return self.components[name] ~= nil end,
get_uid=function(self) return self.eid end,
get_name=function(self) return entities.name(self.eid) end,
}}
local entities = {}

View File

@ -2,6 +2,7 @@
#include "../../../objects/Player.hpp"
#include "../../../objects/Entities.hpp"
#include "../../../objects/EntityDef.hpp"
#include "../../../objects/rigging.hpp"
#include "../../../physics/Hitbox.hpp"
#include "../../../window/Camera.hpp"
@ -15,6 +16,13 @@ static int l_exists(lua::State* L) {
return lua::pushboolean(L, get_entity(L, 1).has_value());
}
static int l_name(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
return lua::pushstring(L, entity->getDef().name);
}
return 0;
}
static int l_spawn(lua::State* L) {
auto level = controller->getLevel();
auto defname = lua::tostring(L, 1);
@ -150,6 +158,7 @@ static int l_raycast(lua::State* L) {
const luaL_Reg entitylib [] = {
{"exists", lua::wrap<l_exists>},
{"name", lua::wrap<l_name>},
{"spawn", lua::wrap<l_spawn>},
{"despawn", lua::wrap<l_despawn>},
{"get_skeleton", lua::wrap<l_get_skeleton>},