1 module godot.signal;
2 
3 import godot.abi;
4 import godot.builtins;
5 import godot.object;
6 
7 struct GodotSignal {
8     package(godot) union signal {
9         godot_signal _godot_signal;
10         GodotSignal_Bind _bind;
11     }
12 
13     package(godot) signal _signal;
14     alias _signal this;
15 
16     package(godot) this(godot_signal opaque) {
17         _godot_signal = opaque;
18     }
19 
20     this(ref scope const GodotSignal other) {
21         _signal = other._signal;
22     }
23 
24     this(in GodotObject object, in StringName signal) {
25         this = _bind.new2(object, signal);
26     }
27 
28     this(in GodotObject object, in string signal) {
29         StringName snSignal = signal;
30         this = _bind.new2(object, snSignal);
31     }
32 
33     void _defaultCtor() {
34         _bind.new0();
35     }
36 
37     ~this() {
38         _bind._destructor();
39     }
40 
41     void emit(Args...)(Args args) {
42         _bind.emit(args);
43     }
44 
45     bool isNull() const {
46         return _bind.isNull();
47     }
48 
49     GodotObject getObject() const {
50         return _bind.getObject();
51     }
52 
53     ObjectID getObjectId() const {
54         return ObjectID(_bind.getObjectId());
55     }
56 
57     StringName getName() const {
58         return _bind.getName();
59     }
60 
61     int connect(in GodotCallable callable, in int flags = 0) {
62         return cast(int) _bind.connect(callable, flags);
63     }
64 
65     void disconnect(in GodotCallable callable) {
66         _bind.disconnect(callable);
67     }
68 
69     bool isConnected(in GodotCallable callable) const {
70         return _bind.isConnected(callable);
71     }
72 
73     Array getConnections() const {
74         return _bind.getConnections();
75     }
76 
77     void emit(Args...)(Args args) const {
78         _bind.emit(args);
79     }
80 }
81 
82 /// Type-safe Signal wrapper around Godot's Signal
83 version(none) struct GodotSignalT(string Name, Args...) {
84 
85     GodotSignal _impl;
86 
87     enum string name = Name;
88 
89     this(GodotSignal sig) {
90         _impl = sig;
91     }
92 
93     ref typeof(this) opAssign(GodotSignal value)
94     {
95         _impl = value;
96         return this;
97     }
98 
99     void emit(Args args) {
100         _impl.emit(args);
101     }
102 }