capitalex gist felülvizsgálása . Revízióhoz ugrás
1 file changed, 338 insertions
generated-text-input.lua(fájl létrehozva)
@@ -0,0 +1,338 @@ | |||
1 | + | local min, max, huge = math.min, math.max, math.huge | |
2 | + | local machine = {} | |
3 | + | ||
4 | + | machine.counters = { | |
5 | + | ["run current frame"] = 0, | |
6 | + | ["step timer"] = 0, | |
7 | + | ["clear the screen"] = 0, | |
8 | + | ["draw scene"] = 0, | |
9 | + | ["present current frame"] = 0, | |
10 | + | ["sleep for 1ms"] = 0, | |
11 | + | ["next cycle"] = 0, | |
12 | + | ["run main loop"] = 1, | |
13 | + | ["@poll inputs"] = 0, | |
14 | + | ["@quit love"] = 0, | |
15 | + | ["@step timer"] = 0, | |
16 | + | ["@clear screen"] = 0, | |
17 | + | ["@text input"] = 0, | |
18 | + | ["@text received"] = 0, | |
19 | + | ["@quit"] = 0, | |
20 | + | ["@push text"] = 0, | |
21 | + | ["@draw buffer"] = 0, | |
22 | + | ["@present"] = 0, | |
23 | + | ["@is backspace pressed"] = 0, | |
24 | + | ["@backspace was pressed"] = 0, | |
25 | + | ["@delete character"] = 0, | |
26 | + | ["@is new line pressed"] = 0, | |
27 | + | ["@new line was pressed"] = 0, | |
28 | + | ["@insert new line"] = 0, | |
29 | + | ["handling inputs"] = 0, | |
30 | + | ["handle text input"] = 0, | |
31 | + | ["@exit code"] = 0, | |
32 | + | ["handle return or enter"] = 0, | |
33 | + | ["check for text input event"] = 0, | |
34 | + | ["push text to buffer"] = 0, | |
35 | + | ["check for backspace"] = 0, | |
36 | + | ["delete character from buffer"] = 0, | |
37 | + | ["check for new line"] = 0, | |
38 | + | ["insert new line"] = 0, | |
39 | + | ["@sleep"] = 0, | |
40 | + | ["drawing scene"] = 0, | |
41 | + | ["draw buffer"] = 0, | |
42 | + | ["handle backspace"] = 0, | |
43 | + | ["poll inputs"] = 0, | |
44 | + | ["handle inputs"] = 0, | |
45 | + | } | |
46 | + | ||
47 | + | function machine.on_poll_inputs(counters) | |
48 | + | end | |
49 | + | ||
50 | + | function machine.on_quit_love(counters) | |
51 | + | end | |
52 | + | ||
53 | + | function machine.on_step_timer(counters) | |
54 | + | end | |
55 | + | ||
56 | + | function machine.on_clear_screen(counters) | |
57 | + | end | |
58 | + | ||
59 | + | function machine.on_present(counters) | |
60 | + | end | |
61 | + | ||
62 | + | function machine.on_sleep(counters, sleep) | |
63 | + | end | |
64 | + | ||
65 | + | function machine.on_text_input(counters) | |
66 | + | end | |
67 | + | ||
68 | + | function machine.on_push_text_to_buffer(counters) | |
69 | + | end | |
70 | + | ||
71 | + | function machine.on_draw_buffer(counters) | |
72 | + | end | |
73 | + | ||
74 | + | function machine.on_is_backspace_pressed(counters) | |
75 | + | end | |
76 | + | ||
77 | + | function machine.on_delete_character(counters) | |
78 | + | end | |
79 | + | ||
80 | + | function machine.on_is_new_line_pressed(counters) | |
81 | + | end | |
82 | + | ||
83 | + | function machine.on_insert_new_line(counters) | |
84 | + | end | |
85 | + | ||
86 | + | function match(self, counters) | |
87 | + | if counters["@poll inputs"] > 0 then | |
88 | + | self.on_poll_inputs(counters) | |
89 | + | counters["@poll inputs"] = 0 | |
90 | + | return true | |
91 | + | end | |
92 | + | if counters["@quit love"] > 0 then | |
93 | + | counters["@exit code"] = self.on_quit_love(counters) | |
94 | + | counters["@quit love"] = 0 | |
95 | + | return true | |
96 | + | end | |
97 | + | if counters["@step timer"] > 0 then | |
98 | + | self.on_step_timer(counters) | |
99 | + | counters["@step timer"] = 0 | |
100 | + | return true | |
101 | + | end | |
102 | + | if counters["@clear screen"] > 0 then | |
103 | + | self.on_clear_screen(counters) | |
104 | + | counters["@clear screen"] = 0 | |
105 | + | return true | |
106 | + | end | |
107 | + | if counters["@present"] > 0 then | |
108 | + | self.on_present(counters) | |
109 | + | counters["@present"] = 0 | |
110 | + | return true | |
111 | + | end | |
112 | + | if counters["@sleep"] > 0 then | |
113 | + | self.on_sleep(counters, counters["@sleep"]) | |
114 | + | counters["@sleep"] = 0 | |
115 | + | return true | |
116 | + | end | |
117 | + | if counters["@text input"] > 0 then | |
118 | + | counters["@text received"] = self.on_text_input(counters) | |
119 | + | counters["@text input"] = 0 | |
120 | + | return true | |
121 | + | end | |
122 | + | if counters["@push text"] > 0 then | |
123 | + | self.on_push_text_to_buffer(counters) | |
124 | + | counters["@push text"] = 0 | |
125 | + | return true | |
126 | + | end | |
127 | + | if counters["@draw buffer"] > 0 then | |
128 | + | self.on_draw_buffer(counters) | |
129 | + | counters["@draw buffer"] = 0 | |
130 | + | return true | |
131 | + | end | |
132 | + | if counters["@is backspace pressed"] > 0 then | |
133 | + | counters["@backspace was pressed"] = self.on_is_backspace_pressed(counters) | |
134 | + | counters["@is backspace pressed"] = 0 | |
135 | + | return true | |
136 | + | end | |
137 | + | if counters["@delete character"] > 0 then | |
138 | + | self.on_delete_character(counters) | |
139 | + | counters["@delete character"] = 0 | |
140 | + | return true | |
141 | + | end | |
142 | + | if counters["@is new line pressed"] > 0 then | |
143 | + | counters["@new line was pressed"] = self.on_is_new_line_pressed(counters) | |
144 | + | counters["@is new line pressed"] = 0 | |
145 | + | return true | |
146 | + | end | |
147 | + | if counters["@insert new line"] > 0 then | |
148 | + | self.on_insert_new_line(counters) | |
149 | + | counters["@insert new line"] = 0 | |
150 | + | return true | |
151 | + | end | |
152 | + | if counters["handling inputs"] > 0 then | |
153 | + | acc = counters["handling inputs"] | |
154 | + | counters["handling inputs"] = max(counters["handling inputs"] - acc, 0) | |
155 | + | counters["handle text input"] = counters["handle text input"] + acc * 1 | |
156 | + | counters["handle backspace"] = counters["handle backspace"] + acc * 1 | |
157 | + | counters["handle return or enter"] = counters["handle return or enter"] + acc * 1 | |
158 | + | return true | |
159 | + | end | |
160 | + | if counters["handle text input"] > 0 then | |
161 | + | acc = counters["handle text input"] | |
162 | + | counters["handle text input"] = max(counters["handle text input"] - acc, 0) | |
163 | + | counters["check for text input event"] = counters["check for text input event"] + acc * 1 | |
164 | + | counters["push text to buffer"] = counters["push text to buffer"] + acc * 1 | |
165 | + | return true | |
166 | + | end | |
167 | + | if counters["check for text input event"] > 0 then | |
168 | + | acc = counters["check for text input event"] | |
169 | + | counters["check for text input event"] = max(counters["check for text input event"] - acc, 0) | |
170 | + | counters["@text input"] = counters["@text input"] + acc * 1 | |
171 | + | return true | |
172 | + | end | |
173 | + | if counters["push text to buffer"] > 0 and counters["@text received"] > 0 then | |
174 | + | local acc = huge | |
175 | + | acc = min(acc, counters["@text received"]) | |
176 | + | acc = min(acc, counters["push text to buffer"]) | |
177 | + | counters["push text to buffer"] = max(counters["push text to buffer"] - acc, 0) | |
178 | + | counters["@text received"] = max(counters["@text received"] - acc, 0) | |
179 | + | counters["@push text"] = counters["@push text"] + acc * 1 | |
180 | + | counters["handle text input"] = counters["handle text input"] + acc * 1 | |
181 | + | return true | |
182 | + | end | |
183 | + | if counters["push text to buffer"] > 0 then | |
184 | + | acc = counters["push text to buffer"] | |
185 | + | counters["push text to buffer"] = max(counters["push text to buffer"] - acc, 0) | |
186 | + | return true | |
187 | + | end | |
188 | + | if counters["handle backspace"] > 0 then | |
189 | + | acc = counters["handle backspace"] | |
190 | + | counters["handle backspace"] = max(counters["handle backspace"] - acc, 0) | |
191 | + | counters["check for backspace"] = counters["check for backspace"] + acc * 1 | |
192 | + | counters["delete character from buffer"] = counters["delete character from buffer"] + acc * 1 | |
193 | + | return true | |
194 | + | end | |
195 | + | if counters["check for backspace"] > 0 then | |
196 | + | acc = counters["check for backspace"] | |
197 | + | counters["check for backspace"] = max(counters["check for backspace"] - acc, 0) | |
198 | + | counters["@is backspace pressed"] = counters["@is backspace pressed"] + acc * 1 | |
199 | + | return true | |
200 | + | end | |
201 | + | if counters["delete character from buffer"] > 0 and counters["@backspace was pressed"] > 0 then | |
202 | + | local acc = huge | |
203 | + | acc = min(acc, counters["@backspace was pressed"]) | |
204 | + | acc = min(acc, counters["delete character from buffer"]) | |
205 | + | counters["delete character from buffer"] = max(counters["delete character from buffer"] - acc, 0) | |
206 | + | counters["@backspace was pressed"] = max(counters["@backspace was pressed"] - acc, 0) | |
207 | + | counters["@delete character"] = counters["@delete character"] + acc * 1 | |
208 | + | return true | |
209 | + | end | |
210 | + | if counters["delete character from buffer"] > 0 then | |
211 | + | acc = counters["delete character from buffer"] | |
212 | + | counters["delete character from buffer"] = max(counters["delete character from buffer"] - acc, 0) | |
213 | + | return true | |
214 | + | end | |
215 | + | if counters["handle return or enter"] > 0 then | |
216 | + | acc = counters["handle return or enter"] | |
217 | + | counters["handle return or enter"] = max(counters["handle return or enter"] - acc, 0) | |
218 | + | counters["check for new line"] = counters["check for new line"] + acc * 1 | |
219 | + | counters["insert new line"] = counters["insert new line"] + acc * 1 | |
220 | + | return true | |
221 | + | end | |
222 | + | if counters["check for new line"] > 0 then | |
223 | + | acc = counters["check for new line"] | |
224 | + | counters["check for new line"] = max(counters["check for new line"] - acc, 0) | |
225 | + | counters["@is new line pressed"] = counters["@is new line pressed"] + acc * 1 | |
226 | + | return true | |
227 | + | end | |
228 | + | if counters["insert new line"] > 0 and counters["@new line was pressed"] > 0 then | |
229 | + | local acc = huge | |
230 | + | acc = min(acc, counters["@new line was pressed"]) | |
231 | + | acc = min(acc, counters["insert new line"]) | |
232 | + | counters["insert new line"] = max(counters["insert new line"] - acc, 0) | |
233 | + | counters["@new line was pressed"] = max(counters["@new line was pressed"] - acc, 0) | |
234 | + | counters["@insert new line"] = counters["@insert new line"] + acc * 1 | |
235 | + | return true | |
236 | + | end | |
237 | + | if counters["insert new line"] > 0 then | |
238 | + | acc = counters["insert new line"] | |
239 | + | counters["insert new line"] = max(counters["insert new line"] - acc, 0) | |
240 | + | return true | |
241 | + | end | |
242 | + | if counters["drawing scene"] > 0 then | |
243 | + | acc = counters["drawing scene"] | |
244 | + | counters["drawing scene"] = max(counters["drawing scene"] - acc, 0) | |
245 | + | counters["draw buffer"] = counters["draw buffer"] + acc * 1 | |
246 | + | return true | |
247 | + | end | |
248 | + | if counters["draw buffer"] > 0 then | |
249 | + | acc = counters["draw buffer"] | |
250 | + | counters["draw buffer"] = max(counters["draw buffer"] - acc, 0) | |
251 | + | counters["@draw buffer"] = counters["@draw buffer"] + acc * 1 | |
252 | + | return true | |
253 | + | end | |
254 | + | if counters["run main loop"] > 0 then | |
255 | + | acc = counters["run main loop"] | |
256 | + | counters["run main loop"] = max(counters["run main loop"] - acc, 0) | |
257 | + | counters["run current frame"] = counters["run current frame"] + acc * 1 | |
258 | + | counters["poll inputs"] = counters["poll inputs"] + acc * 1 | |
259 | + | counters["handle inputs"] = counters["handle inputs"] + acc * 1 | |
260 | + | return true | |
261 | + | end | |
262 | + | if counters["poll inputs"] > 0 then | |
263 | + | acc = counters["poll inputs"] | |
264 | + | counters["poll inputs"] = max(counters["poll inputs"] - acc, 0) | |
265 | + | counters["@poll inputs"] = counters["@poll inputs"] + acc * 1 | |
266 | + | return true | |
267 | + | end | |
268 | + | if counters["handle inputs"] > 0 then | |
269 | + | acc = counters["handle inputs"] | |
270 | + | counters["handle inputs"] = max(counters["handle inputs"] - acc, 0) | |
271 | + | counters["handling inputs"] = counters["handling inputs"] + acc * 1 | |
272 | + | return true | |
273 | + | end | |
274 | + | if counters["run current frame"] > 0 and counters["@quit"] > 0 then | |
275 | + | local acc = huge | |
276 | + | acc = min(acc, counters["run current frame"]) | |
277 | + | acc = min(acc, counters["@quit"]) | |
278 | + | counters["run current frame"] = max(counters["run current frame"] - acc, 0) | |
279 | + | counters["@quit"] = max(counters["@quit"] - acc, 0) | |
280 | + | counters["@quit love"] = counters["@quit love"] + acc * 1 | |
281 | + | return true | |
282 | + | end | |
283 | + | if counters["run current frame"] > 0 then | |
284 | + | acc = counters["run current frame"] | |
285 | + | counters["run current frame"] = max(counters["run current frame"] - acc, 0) | |
286 | + | counters["step timer"] = counters["step timer"] + acc * 1 | |
287 | + | counters["clear the screen"] = counters["clear the screen"] + acc * 1 | |
288 | + | counters["draw scene"] = counters["draw scene"] + acc * 1 | |
289 | + | counters["present current frame"] = counters["present current frame"] + acc * 1 | |
290 | + | counters["sleep for 1ms"] = counters["sleep for 1ms"] + acc * 1 | |
291 | + | counters["next cycle"] = counters["next cycle"] + acc * 1 | |
292 | + | return true | |
293 | + | end | |
294 | + | if counters["step timer"] > 0 then | |
295 | + | acc = counters["step timer"] | |
296 | + | counters["step timer"] = max(counters["step timer"] - acc, 0) | |
297 | + | counters["@step timer"] = counters["@step timer"] + acc * 1 | |
298 | + | return true | |
299 | + | end | |
300 | + | if counters["clear the screen"] > 0 then | |
301 | + | acc = counters["clear the screen"] | |
302 | + | counters["clear the screen"] = max(counters["clear the screen"] - acc, 0) | |
303 | + | counters["@clear screen"] = counters["@clear screen"] + acc * 1 | |
304 | + | return true | |
305 | + | end | |
306 | + | if counters["draw scene"] > 0 then | |
307 | + | acc = counters["draw scene"] | |
308 | + | counters["draw scene"] = max(counters["draw scene"] - acc, 0) | |
309 | + | counters["drawing scene"] = counters["drawing scene"] + acc * 1 | |
310 | + | return true | |
311 | + | end | |
312 | + | if counters["present current frame"] > 0 then | |
313 | + | acc = counters["present current frame"] | |
314 | + | counters["present current frame"] = max(counters["present current frame"] - acc, 0) | |
315 | + | counters["@present"] = counters["@present"] + acc * 1 | |
316 | + | return true | |
317 | + | end | |
318 | + | if counters["sleep for 1ms"] > 0 then | |
319 | + | acc = counters["sleep for 1ms"] | |
320 | + | counters["sleep for 1ms"] = max(counters["sleep for 1ms"] - acc, 0) | |
321 | + | counters["@sleep"] = counters["@sleep"] + acc * 1 | |
322 | + | return true | |
323 | + | end | |
324 | + | if counters["next cycle"] > 0 then | |
325 | + | acc = counters["next cycle"] | |
326 | + | counters["next cycle"] = max(counters["next cycle"] - acc, 0) | |
327 | + | counters["run main loop"] = counters["run main loop"] + acc * 1 | |
328 | + | return true | |
329 | + | end | |
330 | + | return false | |
331 | + | end | |
332 | + | ||
333 | + | function machine:run() | |
334 | + | local counters = self.counters | |
335 | + | while match(self, counters) do end | |
336 | + | end | |
337 | + | ||
338 | + | return machine |
Újabb
Régebbi