rust_constructor/
background.rs1use crate::{DisplayInfo, RustConstructorResource};
5use std::{any::Any, fmt::Debug};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct PageData {
16 pub forced_update: bool,
20
21 pub change_page_updated: bool,
25
26 pub enter_page_updated: bool,
30
31 pub tags: Vec<[String; 2]>,
35}
36
37impl RustConstructorResource for PageData {
38 fn as_any(&self) -> &dyn Any {
39 self
40 }
41
42 fn as_any_mut(&mut self) -> &mut dyn Any {
43 self
44 }
45
46 fn display_display_info(&self) -> Option<DisplayInfo> {
47 None
48 }
49
50 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
51
52 fn display_tags(&self) -> Vec<[String; 2]> {
53 self.tags.clone()
54 }
55
56 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
57 if replace {
58 self.tags = tags.to_owned();
59 } else {
60 for tag in tags {
61 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
62 self.tags.remove(index);
63 };
64 }
65 self.tags.extend(tags.iter().cloned());
66 };
67 }
68}
69
70impl Default for PageData {
71 fn default() -> Self {
72 PageData {
73 forced_update: true,
74 change_page_updated: false,
75 enter_page_updated: false,
76 tags: Vec::new(),
77 }
78 }
79}
80
81impl PageData {
82 #[inline]
83 pub fn forced_update(mut self, forced_update: bool) -> Self {
84 self.forced_update = forced_update;
85 self
86 }
87
88 #[inline]
89 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
90 if replace {
91 self.tags = tags.to_owned();
92 } else {
93 for tag in tags {
94 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
95 self.tags.remove(index);
96 };
97 }
98 self.tags.extend(tags.iter().cloned());
99 };
100 self
101 }
102}
103
104#[derive(Debug, Clone, PartialEq, PartialOrd)]
108pub struct Variable<T> {
109 pub value: Option<T>,
113
114 pub tags: Vec<[String; 2]>,
118}
119
120impl<T: Debug + 'static> RustConstructorResource for Variable<T> {
121 fn as_any(&self) -> &dyn Any {
122 self
123 }
124
125 fn as_any_mut(&mut self) -> &mut dyn Any {
126 self
127 }
128
129 fn display_display_info(&self) -> Option<DisplayInfo> {
130 None
131 }
132
133 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
134
135 fn display_tags(&self) -> Vec<[String; 2]> {
136 self.tags.clone()
137 }
138
139 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
140 if replace {
141 self.tags = tags.to_owned();
142 } else {
143 for tag in tags {
144 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
145 self.tags.remove(index);
146 };
147 }
148 self.tags.extend(tags.iter().cloned());
149 };
150 }
151}
152
153impl<T> Default for Variable<T> {
154 fn default() -> Self {
155 Variable {
156 value: None,
157 tags: Vec::new(),
158 }
159 }
160}
161
162impl<T> Variable<T> {
163 #[inline]
164 pub fn value(mut self, value: Option<T>) -> Self {
165 self.value = value;
166 self
167 }
168
169 #[inline]
170 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
171 if replace {
172 self.tags = tags.to_owned();
173 } else {
174 for tag in tags {
175 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
176 self.tags.remove(index);
177 };
178 }
179 self.tags.extend(tags.iter().cloned());
180 };
181 self
182 }
183}
184
185#[derive(Debug, Clone, PartialEq, PartialOrd)]
194pub struct SplitTime {
195 pub time: [f32; 2],
199
200 pub tags: Vec<[String; 2]>,
204}
205
206impl RustConstructorResource for SplitTime {
207 fn as_any(&self) -> &dyn Any {
208 self
209 }
210
211 fn as_any_mut(&mut self) -> &mut dyn Any {
212 self
213 }
214
215 fn display_display_info(&self) -> Option<DisplayInfo> {
216 None
217 }
218
219 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
220
221 fn display_tags(&self) -> Vec<[String; 2]> {
222 self.tags.clone()
223 }
224
225 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
226 if replace {
227 self.tags = tags.to_owned();
228 } else {
229 for tag in tags {
230 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
231 self.tags.remove(index);
232 };
233 }
234 self.tags.extend(tags.iter().cloned());
235 };
236 }
237}
238
239impl Default for SplitTime {
240 fn default() -> Self {
241 Self {
242 time: [0_f32, 0_f32],
243 tags: Vec::new(),
244 }
245 }
246}
247
248impl SplitTime {
249 #[inline]
250 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
251 if replace {
252 self.tags = tags.to_owned();
253 } else {
254 for tag in tags {
255 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
256 self.tags.remove(index);
257 };
258 }
259 self.tags.extend(tags.iter().cloned());
260 };
261 self
262 }
263}