1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use crate::core_types::{GodotString, Variant, VariantType};
use crate::export::{ClassBuilder, ExportInfo, NativeClass, PropertyUsage};
#[must_use = "SignalBuilder left unbuilt -- did you forget to call done()?"]
pub struct SignalBuilder<'a, C> {
class_builder: &'a ClassBuilder<C>,
name: GodotString,
args: Vec<SignalParam>,
}
impl<'a, C: NativeClass> SignalBuilder<'a, C> {
pub(super) fn new(class_builder: &'a ClassBuilder<C>, signal_name: GodotString) -> Self {
Self {
class_builder,
name: signal_name,
args: vec![],
}
}
#[inline]
pub fn with_param(self, parameter_name: &str, parameter_type: VariantType) -> Self {
self.with_param_custom(SignalParam {
name: parameter_name.into(),
default: Variant::nil(),
export_info: ExportInfo::new(parameter_type),
usage: PropertyUsage::DEFAULT,
})
}
#[inline]
pub fn with_param_default(self, parameter_name: &str, default_value: Variant) -> Self {
let variant_type = default_value.get_type();
self.with_param_custom(SignalParam {
name: parameter_name.into(),
default: default_value,
export_info: ExportInfo::new(variant_type),
usage: PropertyUsage::DEFAULT,
})
}
#[inline]
pub fn with_param_untyped(self, parameter_name: &str) -> Self {
self.with_param_custom(SignalParam {
name: parameter_name.into(),
default: Variant::nil(),
export_info: ExportInfo::new(VariantType::Nil),
usage: PropertyUsage::DEFAULT,
})
}
#[inline]
pub fn with_param_custom(mut self, parameter: SignalParam) -> Self {
self.args.push(parameter);
self
}
#[inline]
pub fn done(self) {
self.class_builder.add_signal(Signal {
name: self.name,
args: self.args,
});
}
}
pub(crate) struct Signal {
pub name: GodotString,
pub args: Vec<SignalParam>,
}
pub struct SignalParam {
pub name: GodotString,
pub default: Variant,
pub export_info: ExportInfo,
pub usage: PropertyUsage,
}