From ad22763a1ffef533a964de384723c5fc75ec0a0b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 16 Sep 2026 23:40:41 +0300 Subject: [PATCH] add new skeleton:get_color, skeleton:set_color overloads --- res/modules/internal/stdcomp.lua | 4 ++-- .../scripting/lua/libs/lib__skeleton.cpp | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/res/modules/internal/stdcomp.lua b/res/modules/internal/stdcomp.lua index 4a0ace852..dfea2e7c9 100644 --- a/res/modules/internal/stdcomp.lua +++ b/res/modules/internal/stdcomp.lua @@ -58,8 +58,8 @@ local Skeleton = {__index={ index=function(self, s) return __skeleton.index(self.eid, s) end, is_visible=function(self, i) return __skeleton.is_visible(self.eid, i) end, set_visible=function(self, i, b) return __skeleton.set_visible(self.eid, i, b) end, - get_color=function(self) return __skeleton.get_color(self.eid) end, - set_color=function(self, color) return __skeleton.set_color(self.eid, color) end, + get_color=function(self, ...) return __skeleton.get_color(self.eid, ...) end, + set_color=function(self, color, ...) return __skeleton.set_color(self.eid, color, ...) end, set_interpolated=function(self, b) return __skeleton.set_interpolated(self.eid, b) end, }} diff --git a/src/logic/scripting/lua/libs/lib__skeleton.cpp b/src/logic/scripting/lua/libs/lib__skeleton.cpp index fc673db77..136f4ce62 100644 --- a/src/logic/scripting/lua/libs/lib__skeleton.cpp +++ b/src/logic/scripting/lua/libs/lib__skeleton.cpp @@ -147,8 +147,19 @@ static int l_set_visible(lua::State* L) { return 0; } +static glm::vec4 to_color(lua::State* L, int idx) { + if (lua::objlen(L, idx) > 3) { + return lua::tovec4(L, idx); + } + return glm::vec4(lua::tovec3(L, idx), 1.0f); +} + static int l_get_color(lua::State* L) { if (auto skeleton = get_skeleton(L)) { + if (lua::isnumber(L, 2)) { + auto index = index_range_check(*skeleton, lua::tointeger(L, 2)); + return lua::pushvec(L, skeleton->boneTints[index]); + } return lua::pushvec(L, skeleton->tint); } return 0; @@ -156,9 +167,12 @@ static int l_get_color(lua::State* L) { static int l_set_color(lua::State* L) { if (auto skeleton = get_skeleton(L)) { - skeleton->tint = lua::objlen(L, 2) > 3 - ? lua::tovec4(L, 2) - : glm::vec4(lua::tovec3(L, 2), 1.0f); + if (lua::isnumber(L, 2)) { + auto index = index_range_check(*skeleton, lua::tointeger(L, 2)); + skeleton->boneTints[index] = to_color(L, 3); + } else { + skeleton->tint = to_color(L, 2); + } } return 0; }