def get_parent_class(cls, classname):
     ret = godot_string_alloc()
     lib.godot_string_new(ret)
     gd_classname = godot_string_from_pyobj(classname)
     args = ffi.new("godot_string**", gd_classname)
     lib.godot_method_bind_ptrcall(cls._meth_get_parent_class,
                                   cls._instance, ffi.cast("void**",
                                                           args), ret)
     raw_str = lib.godot_string_unicode_str(ret)
     return ffi.string(raw_str)
 def get_class_consts(cls, classname):
     consts = []
     ret = godot_pool_string_array_alloc()
     lib.godot_pool_string_array_new(ret)
     gd_classname = godot_string_from_pyobj(classname)
     gd_true = godot_bool_alloc(True)
     args = ffi.new("void*[2]", [gd_classname, gd_true])
     # 2nd arg should be false, which what we get by not initializing it
     lib.godot_method_bind_ptrcall(cls._meth_get_integer_constant_list,
                                   cls._instance, args, ret)
     for i in range(lib.godot_pool_string_array_size(ret)):
         godot_str = lib.godot_pool_string_array_get(ret, i)
         raw_str = lib.godot_string_unicode_str(ffi.addressof(godot_str))
         consts.append(ffi.string(raw_str))
     return consts
    def get_class_list(cls):
        ret = godot_pool_string_array_alloc()
        lib.godot_method_bind_ptrcall(cls._meth_get_class_list, cls._instance,
                                      ffi.NULL, ret)

        # Convert Godot return into Python civilized stuff
        unordered = []
        for i in range(lib.godot_pool_string_array_size(ret)):
            godot_str = lib.godot_pool_string_array_get(ret, i)
            raw_str = lib.godot_string_unicode_str(ffi.addressof(godot_str))
            unordered.append(ffi.string(raw_str))

        # Order class to have a parent defined before their children
        classes = []
        while len(unordered) != len(classes):
            for classname in unordered:
                parentname = cls.get_parent_class(classname)
                if not parentname or parentname in classes:
                    if classname not in classes:
                        classes.append(classname)

        return classes
Exemplo n.º 4
0
def godot_string_to_pyobj(p_gdstring):
    raw_str = lib.godot_string_unicode_str(p_gdstring)
    return ffi.string(raw_str)