|
1 | | -cimport cython |
2 | | - |
3 | 1 | from .hazmat cimport gdapi, gdptrs, gdextension_interface |
4 | 2 | from .hazmat.gdtypes cimport * |
5 | 3 | from .builtins cimport * |
@@ -95,10 +93,6 @@ cdef inline object _meth_call(BaseGDObject obj, object name, object args): |
95 | 93 | return _object_call(obj._gd_ptr, "call", [name, *args]) |
96 | 94 |
|
97 | 95 |
|
98 | | -# |
99 | | -# Classes API base class loader |
100 | | -# |
101 | | - |
102 | 96 | cdef object _load_class(str name): |
103 | 97 | try: |
104 | 98 | return _loaded_classes[name] |
@@ -273,130 +267,6 @@ cdef object _load_class(str name): |
273 | 267 | return klass |
274 | 268 |
|
275 | 269 |
|
276 | | -# |
277 | | -# ClassDB based class loader |
278 | | -# |
279 | | - |
280 | | - |
281 | | -cdef object _load_class_from_class_db(str name): |
282 | | - try: |
283 | | - return _loaded_classes[name] |
284 | | - except KeyError: |
285 | | - pass |
286 | | - |
287 | | - cdef StringName gdname = StringName(name) |
288 | | - |
289 | | - # Load our good friend ClassDB |
290 | | - cdef StringName gdname_classdb = StringName("ClassDB") |
291 | | - cdef gd_object_t classdb = gdptrs.gdptr_global_get_singleton(&gdname_classdb._gd_data) |
292 | | - |
293 | | - if not _object_call(classdb, "class_exists", [gdname]): |
294 | | - raise RuntimeError(f"Class `{name}` doesn't exist in Godot !") |
295 | | - |
296 | | - gdparent = _object_call(classdb, "get_parent_class", [gdname]) |
297 | | - parent = str(gdparent) |
298 | | - if parent: |
299 | | - parent_cls = _load_class(parent) |
300 | | - bases = (parent_cls, ) |
301 | | - else: |
302 | | - bases = (BaseGDObject, ) |
303 | | - |
304 | | - attrs = {"_gd_name": gdname} |
305 | | - ################################ TODO: meth["name"] is GDString, should use str/StringName instead |
306 | | - |
307 | | - if name == "RefCounted": |
308 | | - @classmethod |
309 | | - def _new(cls): |
310 | | - raise RuntimeError(f"RefCounted Godot object must be created with `{ cls.__name__ }()`") |
311 | | - |
312 | | - attrs["new"] = _new |
313 | | - |
314 | | - def _del(self): |
315 | | - cdef BaseGDObject obj = <BaseGDObject>self |
316 | | - if _object_call(obj._gd_ptr, "unreference", []): |
317 | | - gdptrs.gdptr_object_destroy(obj._gd_ptr) |
318 | | - obj._gd_ptr = NULL |
319 | | - |
320 | | - attrs["__del__"] = _del |
321 | | - |
322 | | - def _free(self): |
323 | | - raise RuntimeError("RefCounted Godot object cannot be freed") |
324 | | - |
325 | | - attrs["free"] = _free |
326 | | - |
327 | | - def _init(self): |
328 | | - cdef gd_string_name_t name = gdapi.gd_string_name_from_unchecked_pystr(type(self).__name__) |
329 | | - (<BaseGDObject>self)._gd_ptr = gdptrs.gdptr_classdb_construct_object(&name) |
330 | | - |
331 | | - attrs["__init__"] = _init |
332 | | - |
333 | | - def _generate_method(spec, py_meth_name): |
334 | | - gd_meth_name = spec["name"] |
335 | | - if spec["flags"] & 32: # METHOD_FLAG_STATIC == 32 |
336 | | - @staticmethod |
337 | | - def _meth(*args): |
338 | | - return _object_call(classdb, "class_call_static", [gdname, gd_meth_name, *args]) |
339 | | - else: |
340 | | - def _meth(self, *args): |
341 | | - return _meth_call(self, gd_meth_name, args) |
342 | | - _meth.__name__ = py_meth_name |
343 | | - return _meth |
344 | | - |
345 | | - meths = _object_call(classdb, "class_get_method_list", [gdname]) |
346 | | - for meth in meths: |
347 | | - meth_name = str(meth["name"]) |
348 | | - attrs[meth_name] = _generate_method(meth, meth_name) |
349 | | - |
350 | | - # `Object` defines a `free`, but it doesn't work properly... |
351 | | - attrs.pop("free", None) |
352 | | - |
353 | | - def _generate_property(spec): |
354 | | - prop_name = spec["name"] |
355 | | - prop_name_py = str(prop_name) |
356 | | - @property |
357 | | - def _property(self): |
358 | | - return _property_getter(self, prop_name) |
359 | | - @_property.setter |
360 | | - def _property(self, value): |
361 | | - _property_setter(self, prop_name, value) |
362 | | - _property.fget.__name__ = prop_name_py |
363 | | - _property.fset.__name__ = prop_name_py |
364 | | - return _property |
365 | | - |
366 | | - properties = _object_call(classdb, "class_get_property_list", [gdname]) |
367 | | - for prop in properties: |
368 | | - attrs[str(prop["name"])] = _generate_property(prop) |
369 | | - |
370 | | - signals = _object_call(classdb, "class_get_signal_list", [gdname]) |
371 | | - for signal in signals: |
372 | | - signal_name = signal["name"] |
373 | | - signal_name_py = str(signal_name) |
374 | | - @property |
375 | | - def _signal(self): |
376 | | - return Signal(self, signal_name) |
377 | | - attrs[signal_name_py] = _signal |
378 | | - |
379 | | - constants = _object_call(classdb, "class_get_integer_constant_list", [gdname, True]) |
380 | | - for constant_name in constants: |
381 | | - constant_value = _object_call(classdb, "class_get_integer_constant", [gdname, constant_name]) |
382 | | - attrs[str(constant_name)] = constant_value |
383 | | - |
384 | | - from enum import Enum |
385 | | - enums = _object_call(classdb, "class_get_enum_list", [gdname, True]) |
386 | | - for enum_name in enums: |
387 | | - enum_items_cooked = {} |
388 | | - enum_items = _object_call(classdb, "class_get_enum_constants", [gdname, enum_name]) |
389 | | - for enum_item_name in enum_items: |
390 | | - enum_item_value = _object_call(classdb, "class_get_integer_constant", [gdname, enum_item_name]) |
391 | | - enum_items_cooked[str(enum_item_name)] = enum_item_value |
392 | | - attrs[str(enum_name)] = Enum(str(enum_name), enum_items_cooked) |
393 | | - |
394 | | - cdef object klass = type(name, bases, attrs) |
395 | | - |
396 | | - _loaded_classes[name] = klass |
397 | | - return klass |
398 | | - |
399 | | - |
400 | 270 | cdef object _object_call(gd_object_t obj, str meth, list args): |
401 | 271 | cdef object pyret |
402 | 272 | cdef gd_variant_t ret |
|
0 commit comments