1 /** 2 Holds a reference to an $(D GodotObject)'s instance ID. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.encodedobjectasid; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.reference; 25 /** 26 Holds a reference to an $(D GodotObject)'s instance ID. 27 28 Utility class which holds a reference to the internal identifier of an $(D GodotObject) instance, as given by $(D GodotObject.getInstanceId). This ID can then be used to retrieve the object instance with $(D @GDScript.instanceFromId). 29 This class is used internally by the editor inspector and script debugger, but can also be used in plugins to pass and display objects as their IDs. 30 */ 31 @GodotBaseClass struct EncodedObjectAsID 32 { 33 package(godot) enum string _GODOT_internal_name = "EncodedObjectAsID"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("get_object_id") GodotMethod!(long) getObjectId; 44 @GodotName("set_object_id") GodotMethod!(void, long) setObjectId; 45 } 46 /// 47 pragma(inline, true) bool opEquals(in EncodedObjectAsID other) const 48 { return _godot_object.ptr is other._godot_object.ptr; } 49 /// 50 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 51 { _godot_object.ptr = n; return null; } 52 /// 53 pragma(inline, true) bool opEquals(typeof(null) n) const 54 { return _godot_object.ptr is n; } 55 /// 56 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 57 mixin baseCasts; 58 /// Construct a new instance of EncodedObjectAsID. 59 /// Note: use `memnew!EncodedObjectAsID` instead. 60 static EncodedObjectAsID _new() 61 { 62 static godot_class_constructor constructor; 63 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EncodedObjectAsID"); 64 if(constructor is null) return typeof(this).init; 65 return cast(EncodedObjectAsID)(constructor()); 66 } 67 @disable new(size_t s); 68 /** 69 70 */ 71 long getObjectId() const 72 { 73 checkClassBinding!(typeof(this))(); 74 return ptrcall!(long)(GDNativeClassBinding.getObjectId, _godot_object); 75 } 76 /** 77 78 */ 79 void setObjectId(in long id) 80 { 81 checkClassBinding!(typeof(this))(); 82 ptrcall!(void)(GDNativeClassBinding.setObjectId, _godot_object, id); 83 } 84 /** 85 The $(D GodotObject) identifier stored in this $(D EncodedObjectAsID) instance. The object instance can be retrieved with $(D @GDScript.instanceFromId). 86 */ 87 @property long objectId() 88 { 89 return getObjectId(); 90 } 91 /// ditto 92 @property void objectId(long v) 93 { 94 setObjectId(v); 95 } 96 }