diff --git a/doc/ru/scripting/ecs.md b/doc/ru/scripting/ecs.md index a0fba048..8511ee33 100644 --- a/doc/ru/scripting/ecs.md +++ b/doc/ru/scripting/ecs.md @@ -16,6 +16,9 @@ Lua. -- Удаляет сущность (сущность может продолжать существовать до завершения кадра, но не будет отображена в этом кадре) entity:despawn() +-- Возращает имя скелета сущности +entity:get_skeleton() -> str + -- Заменяет скелет сущности entity:set_skeleton(name: str) @@ -127,4 +130,3 @@ rig:set_matrix(index: int, matrix: mat4) -- Назначает текстуру по ключу (динамически назначаемые текстуры - '$имя') rig:set_texture(key: str, value: str) ``` - diff --git a/res/modules/internal/stdcomp.lua b/res/modules/internal/stdcomp.lua index df36bfbe..08ae0759 100644 --- a/res/modules/internal/stdcomp.lua +++ b/res/modules/internal/stdcomp.lua @@ -53,6 +53,7 @@ end local Entity = {__index={ despawn=function(self) return entities.despawn(self.eid) end, + get_skeleton=function(self) return entities.get_skeleton(self.eid) end, set_skeleton=function(self, s) return entities.set_skeleton(self.eid, s) end, get_component=function(self, name) return self.components[name] end, has_component=function(self, name) return self.components[name] ~= nil end, diff --git a/src/logic/scripting/lua/libentity.cpp b/src/logic/scripting/lua/libentity.cpp index 0f1db956..9cff1e6b 100644 --- a/src/logic/scripting/lua/libentity.cpp +++ b/src/logic/scripting/lua/libentity.cpp @@ -1,6 +1,8 @@ #include "libentity.hpp" #include "../../../objects/Player.hpp" +#include "../../../objects/Entities.hpp" +#include "../../../objects/rigging.hpp" #include "../../../physics/Hitbox.hpp" #include "../../../window/Camera.hpp" #include "../../../content/Content.hpp" @@ -32,6 +34,13 @@ static int l_despawn(lua::State* L) { return 0; } +static int l_get_skeleton(lua::State* L) { + if (auto entity = get_entity(L, 1)) { + return lua::pushstring(L, entity->getSkeleton().config->getName()); + } + return 0; +} + static int l_set_skeleton(lua::State* L) { if (auto entity = get_entity(L, 1)) { std::string skeletonName = lua::require_string(L, 2); @@ -48,6 +57,7 @@ const luaL_Reg entitylib [] = { {"exists", lua::wrap}, {"spawn", lua::wrap}, {"despawn", lua::wrap}, + {"get_skeleton", lua::wrap}, {"set_skeleton", lua::wrap}, {NULL, NULL} };