]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add ObjectRef:get_children() (#10480)
authorZughy <63455151+Zughy@users.noreply.github.com>
Tue, 13 Oct 2020 19:27:52 +0000 (21:27 +0200)
committerGitHub <noreply@github.com>
Tue, 13 Oct 2020 19:27:52 +0000 (20:27 +0100)
Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com>
doc/lua_api.txt
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h

index c8b294149c4e150afa747b4324ba3dc07855c688..1631d564c881d587653b0ebe112ae38f485c823e 100644 (file)
@@ -6206,6 +6206,8 @@ object you are working with still exists.
        should appear in first person.
 * `get_attach()`: returns parent, bone, position, rotation, forced_visible, 
     or nil if it isn't attached.
+* `get_children()`: returns a list of ObjectRefs that are attached to the
+    object.
 * `set_detach()`
 * `set_bone_position(bone, position, rotation)`
     * `bone`: string
index 57ed7e2cdbef5f82a049a5c8ab417c5dfbfc4776..96c8c687c07c08f009eb8f3ad6c4c61077f35374 100644 (file)
@@ -738,6 +738,27 @@ int ObjectRef::l_get_attach(lua_State *L)
        return 5;
 }
 
+// get_children(self)
+int ObjectRef::l_get_children(lua_State *L)
+{
+       GET_ENV_PTR;
+
+       ObjectRef *ref = checkobject(L, 1);
+       ServerActiveObject *sao = getobject(ref);
+       if (sao == nullptr)
+               return 0;
+
+       const std::unordered_set<int> child_ids = sao->getAttachmentChildIds();
+       int i = 0;
+       lua_createtable(L, child_ids.size(), 0);
+       for (const int id : child_ids) {
+               ServerActiveObject *child = env->getActiveObject(id);
+               getScriptApiBase(L)->objectrefGetOrCreate(L, child);
+               lua_rawseti(L, -2, ++i);
+       }
+       return 1;
+}
+
 // set_detach(self)
 int ObjectRef::l_set_detach(lua_State *L)
 {
@@ -2337,6 +2358,7 @@ luaL_Reg ObjectRef::methods[] = {
        luamethod(ObjectRef, get_bone_position),
        luamethod(ObjectRef, set_attach),
        luamethod(ObjectRef, get_attach),
+       luamethod(ObjectRef, get_children),
        luamethod(ObjectRef, set_detach),
        luamethod(ObjectRef, set_properties),
        luamethod(ObjectRef, get_properties),
index ca03dfa2e95a1d24a7144cab05ee8fdbf69f0912..097a74cae1873b3e2d90ad93330f68cd066e25ff 100644 (file)
@@ -143,6 +143,9 @@ class ObjectRef : public ModApiBase {
        // get_attach(self)
        static int l_get_attach(lua_State *L);
 
+       // get_children(self)
+       static int l_get_children(lua_State *L);
+
        // set_detach(self)
        static int l_set_detach(lua_State *L);