Skip to content

Commit 4f7f43b

Browse files
committed
feat(EnumHint): store optional mapping value information
1 parent 7650cad commit 4f7f43b

File tree

1 file changed

+20
-14
lines changed
  • gdnative-core/src/export/property

1 file changed

+20
-14
lines changed

gdnative-core/src/export/property/hint.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,36 @@ where
116116
/// ```
117117
#[derive(Clone, Eq, PartialEq, Debug, Default)]
118118
pub struct EnumHint {
119-
values: Vec<String>,
119+
values: Vec<(String, Option<i64>)>,
120120
}
121121

122122
impl EnumHint {
123123
#[inline]
124124
pub fn new(values: Vec<String>) -> Self {
125+
let values = values.into_iter().map(|v| (v, None)).collect();
126+
EnumHint { values }
127+
}
128+
129+
#[inline]
130+
pub fn with_numbers(values: Vec<(String, i64)>) -> Self {
131+
let values = values
132+
.into_iter()
133+
.map(|(key, val)| (key, Some(val)))
134+
.collect();
125135
EnumHint { values }
126136
}
127137

128138
/// Formats the hint as a Godot hint string.
129139
fn to_godot_hint_string(&self) -> GodotString {
130-
let mut s = String::new();
131-
132-
let mut iter = self.values.iter();
133-
134-
if let Some(first) = iter.next() {
135-
write!(s, "{}", first).unwrap();
136-
}
137-
138-
for rest in iter {
139-
write!(s, ",{}", rest).unwrap();
140-
}
141-
142-
s.into()
140+
self.values
141+
.iter()
142+
.map(|(key, val)| match val {
143+
Some(val) => format!("{}:{}", key, val),
144+
None => key.clone(),
145+
})
146+
.collect::<Vec<_>>()
147+
.join(",")
148+
.into()
143149
}
144150
}
145151

0 commit comments

Comments
 (0)