@@ -10,20 +10,15 @@ void rhythm_game_utilities::_bind_methods()
10
10
{
11
11
// Common
12
12
13
- ClassDB::bind_static_method (" rhythm_game_utilities" ,
14
- D_METHOD (" lerp" , " a" , " b" , " t" ),
15
- &rhythm_game_utilities::lerp);
16
-
17
13
ClassDB::bind_static_method (" rhythm_game_utilities" ,
18
14
D_METHOD (" inverse_lerp" , " a" , " b" , " v" ),
19
15
&rhythm_game_utilities::inverse_lerp);
20
16
21
- // Parsers
17
+ ClassDB::bind_static_method (" rhythm_game_utilities" ,
18
+ D_METHOD (" lerp" , " a" , " b" , " t" ),
19
+ &rhythm_game_utilities::lerp);
22
20
23
- ClassDB::bind_static_method (
24
- " rhythm_game_utilities" ,
25
- D_METHOD (" parse_sections_from_chart" , " contents" ),
26
- &rhythm_game_utilities::parse_sections_from_chart);
21
+ // Parsers
27
22
28
23
ClassDB::bind_static_method (
29
24
" rhythm_game_utilities" ,
@@ -45,13 +40,30 @@ void rhythm_game_utilities::_bind_methods()
45
40
D_METHOD (" parse_notes_from_chart_section" , " section" ),
46
41
&rhythm_game_utilities::parse_notes_from_chart_section);
47
42
43
+ ClassDB::bind_static_method (
44
+ " rhythm_game_utilities" ,
45
+ D_METHOD (" parse_sections_from_chart" , " contents" ),
46
+ &rhythm_game_utilities::parse_sections_from_chart);
47
+
48
48
ClassDB::bind_static_method (
49
49
" rhythm_game_utilities" ,
50
50
D_METHOD (" parse_time_signatures_from_chart_section" , " section" ),
51
51
&rhythm_game_utilities::parse_time_signatures_from_chart_section);
52
52
53
53
// Utilities
54
54
55
+ ClassDB::bind_static_method (
56
+ " rhythm_game_utilities" ,
57
+ D_METHOD (" calculate_accuracy_ratio" , " position" , " current_position" ,
58
+ " delta" ),
59
+ &rhythm_game_utilities::calculate_accuracy_ratio);
60
+
61
+ ClassDB::bind_static_method (" rhythm_game_utilities" ,
62
+ D_METHOD (" calculate_beat_bars" , " bpm_changes" ,
63
+ " resolution" , " ts" ,
64
+ " include_half_notes" ),
65
+ &rhythm_game_utilities::calculate_beat_bars);
66
+
55
67
ClassDB::bind_static_method (
56
68
" rhythm_game_utilities" ,
57
69
D_METHOD (" convert_seconds_to_ticks" , " seconds" , " resolution" ,
@@ -63,6 +75,11 @@ void rhythm_game_utilities::_bind_methods()
63
75
D_METHOD (" convert_tick_to_position" , " tick" , " resolution" ),
64
76
&rhythm_game_utilities::convert_tick_to_position);
65
77
78
+ ClassDB::bind_static_method (
79
+ " rhythm_game_utilities" ,
80
+ D_METHOD (" find_position_near_given_tick" , " notes" , " tick" , " delta" ),
81
+ &rhythm_game_utilities::find_position_near_given_tick);
82
+
66
83
ClassDB::bind_static_method (
67
84
" rhythm_game_utilities" ,
68
85
D_METHOD (" is_on_the_beat" , " bpm" , " current_time" , " delta" ),
@@ -72,74 +89,22 @@ void rhythm_game_utilities::_bind_methods()
72
89
" rhythm_game_utilities" ,
73
90
D_METHOD (" round_up_to_the_nearest_multiplier" , " value" , " multiplier" ),
74
91
&rhythm_game_utilities::round_up_to_the_nearest_multiplier);
75
-
76
- ClassDB::bind_static_method (
77
- " rhythm_game_utilities" ,
78
- D_METHOD (" calculate_accuracy_ratio" , " position" , " current_position" ,
79
- " delta" ),
80
- &rhythm_game_utilities::calculate_accuracy_ratio);
81
-
82
- ClassDB::bind_static_method (" rhythm_game_utilities" ,
83
- D_METHOD (" calculate_beat_bars" , " bpm_changes" ,
84
- " resolution" , " ts" ,
85
- " include_half_notes" ),
86
- &rhythm_game_utilities::calculate_beat_bars);
87
92
}
88
93
89
94
// Common
90
95
91
- float rhythm_game_utilities::lerp (float a, float b, float t)
92
- {
93
- return RhythmGameUtilities::Lerp (a, b, t);
94
- }
95
-
96
96
float rhythm_game_utilities::inverse_lerp (float a, float b, float v)
97
97
{
98
98
return RhythmGameUtilities::InverseLerp (a, b, v);
99
99
}
100
100
101
- // Parsers
102
-
103
- Dictionary rhythm_game_utilities::parse_sections_from_chart (String contents)
101
+ float rhythm_game_utilities::lerp (float a, float b, float t)
104
102
{
105
- Dictionary sections;
106
-
107
- auto sections_internal =
108
- RhythmGameUtilities::ParseSectionsFromChart (contents.utf8 ().get_data ());
109
-
110
- for (auto section_internal = sections_internal.begin ();
111
- section_internal != sections_internal.end (); section_internal++)
112
- {
113
- auto section_key = godot::String (section_internal->first .c_str ());
114
-
115
- Array section_items;
116
-
117
- for (auto i = 0 ; i < section_internal->second .size (); i += 1 )
118
- {
119
- Dictionary section_item;
120
-
121
- auto temp = section_internal->second [i];
122
-
123
- auto key = godot::Variant (temp.first .c_str ());
124
-
125
- Array values;
126
-
127
- for (auto j = 0 ; j < temp.second .size (); j += 1 )
128
- {
129
- values.append (godot::Variant (temp.second [j].c_str ()));
130
- }
131
-
132
- section_item[key] = values;
133
-
134
- section_items.append (section_item);
135
- }
136
-
137
- sections[section_key] = section_items;
138
- }
139
-
140
- return sections;
103
+ return RhythmGameUtilities::Lerp (a, b, t);
141
104
}
142
105
106
+ // Parsers
107
+
143
108
Array rhythm_game_utilities::parse_bpm_from_chart_section (Array section)
144
109
{
145
110
auto bpm_changes_internal = RhythmGameUtilities::ParseBpmFromChartSection (
@@ -214,6 +179,46 @@ Array rhythm_game_utilities::parse_notes_from_chart_section(Array section)
214
179
return notes;
215
180
}
216
181
182
+ Dictionary rhythm_game_utilities::parse_sections_from_chart (String contents)
183
+ {
184
+ Dictionary sections;
185
+
186
+ auto sections_internal =
187
+ RhythmGameUtilities::ParseSectionsFromChart (contents.utf8 ().get_data ());
188
+
189
+ for (auto section_internal = sections_internal.begin ();
190
+ section_internal != sections_internal.end (); section_internal++)
191
+ {
192
+ auto section_key = godot::String (section_internal->first .c_str ());
193
+
194
+ Array section_items;
195
+
196
+ for (auto i = 0 ; i < section_internal->second .size (); i += 1 )
197
+ {
198
+ Dictionary section_item;
199
+
200
+ auto temp = section_internal->second [i];
201
+
202
+ auto key = godot::Variant (temp.first .c_str ());
203
+
204
+ Array values;
205
+
206
+ for (auto j = 0 ; j < temp.second .size (); j += 1 )
207
+ {
208
+ values.append (godot::Variant (temp.second [j].c_str ()));
209
+ }
210
+
211
+ section_item[key] = values;
212
+
213
+ section_items.append (section_item);
214
+ }
215
+
216
+ sections[section_key] = section_items;
217
+ }
218
+
219
+ return sections;
220
+ }
221
+
217
222
Array rhythm_game_utilities::parse_time_signatures_from_chart_section (
218
223
Array section)
219
224
{
@@ -239,6 +244,54 @@ Array rhythm_game_utilities::parse_time_signatures_from_chart_section(
239
244
240
245
// Utilities
241
246
247
+ float rhythm_game_utilities::calculate_accuracy_ratio (int position,
248
+ int current_position,
249
+ int delta)
250
+ {
251
+ return RhythmGameUtilities::CalculateAccuracyRatio (position,
252
+ current_position, delta);
253
+ }
254
+
255
+ Array rhythm_game_utilities::calculate_beat_bars (Array bpm_changes,
256
+ int resolution, int ts,
257
+ bool include_half_notes)
258
+ {
259
+ std::vector<RhythmGameUtilities::Tempo> bpm_changes_internal;
260
+ bpm_changes_internal.reserve (bpm_changes.size ());
261
+
262
+ for (auto i = 0 ; i < bpm_changes.size (); i += 1 )
263
+ {
264
+ RhythmGameUtilities::Tempo bpm_change_internal;
265
+
266
+ if (bpm_changes[i].get_type () == Variant::DICTIONARY)
267
+ {
268
+ Dictionary variant = bpm_changes[i];
269
+
270
+ bpm_change_internal.Position = variant[" position" ];
271
+ bpm_change_internal.BPM = variant[" bpm" ];
272
+ }
273
+
274
+ bpm_changes_internal.push_back (bpm_change_internal);
275
+ }
276
+
277
+ auto beat_bars_internal = RhythmGameUtilities::CalculateBeatBars (
278
+ bpm_changes_internal, resolution, ts, include_half_notes);
279
+
280
+ Array beat_bars_dictionary_array;
281
+
282
+ for (auto &beat_bar_internal : beat_bars_internal)
283
+ {
284
+ Dictionary beat_bar_dictionary;
285
+
286
+ beat_bar_dictionary[" position" ] = beat_bar_internal.Position ;
287
+ beat_bar_dictionary[" bpm" ] = beat_bar_internal.BPM ;
288
+
289
+ beat_bars_dictionary_array.append (beat_bar_dictionary);
290
+ }
291
+
292
+ return beat_bars_dictionary_array;
293
+ }
294
+
242
295
int rhythm_game_utilities::convert_seconds_to_ticks (
243
296
float seconds, int resolution, Array bpm_changes,
244
297
Array time_signature_changes)
@@ -291,63 +344,53 @@ float rhythm_game_utilities::convert_tick_to_position(int tick, int resolution)
291
344
return RhythmGameUtilities::ConvertTickToPosition (tick, resolution);
292
345
}
293
346
294
- bool rhythm_game_utilities::is_on_the_beat (int bpm, float current_time,
295
- float delta)
296
- {
297
- return RhythmGameUtilities::IsOnTheBeat (bpm, current_time, delta);
298
- }
299
-
300
- int rhythm_game_utilities::round_up_to_the_nearest_multiplier (int value,
301
- int multiplier)
302
- {
303
- return RhythmGameUtilities::RoundUpToTheNearestMultiplier (value,
304
- multiplier);
305
- }
306
-
307
- float rhythm_game_utilities::calculate_accuracy_ratio (int position,
308
- int current_position,
309
- int delta)
347
+ Dictionary rhythm_game_utilities::find_position_near_given_tick (Array notes,
348
+ int tick,
349
+ int delta)
310
350
{
311
- return RhythmGameUtilities::CalculateAccuracyRatio (position,
312
- current_position, delta);
313
- }
314
-
315
- Array rhythm_game_utilities::calculate_beat_bars (Array bpm_changes,
316
- int resolution, int ts,
317
- bool include_half_notes)
318
- {
319
- std::vector<RhythmGameUtilities::Tempo> bpm_changes_internal;
320
- bpm_changes_internal.reserve (bpm_changes.size ());
351
+ std::vector<RhythmGameUtilities::Note> notes_internal;
352
+ notes_internal.reserve (notes.size ());
321
353
322
- for (auto i = 0 ; i < bpm_changes .size (); i += 1 )
354
+ for (auto i = 0 ; i < notes .size (); i += 1 )
323
355
{
324
- RhythmGameUtilities::Tempo bpm_change_internal ;
356
+ RhythmGameUtilities::Note note_internal ;
325
357
326
- if (bpm_changes [i].get_type () == Variant::DICTIONARY)
358
+ if (notes [i].get_type () == Variant::DICTIONARY)
327
359
{
328
- Dictionary variant = bpm_changes [i];
360
+ Dictionary variant = notes [i];
329
361
330
- bpm_change_internal.Position = variant[" position" ];
331
- bpm_change_internal.BPM = variant[" bpm" ];
362
+ note_internal.Position = variant[" position" ];
363
+ note_internal.HandPosition = variant[" hand_position" ];
364
+ note_internal.Length = variant[" length" ];
332
365
}
333
366
334
- bpm_changes_internal .push_back (bpm_change_internal );
367
+ notes_internal .push_back (note_internal );
335
368
}
336
369
337
- auto beat_bars_internal = RhythmGameUtilities::CalculateBeatBars (
338
- bpm_changes_internal, resolution, ts, include_half_notes );
370
+ auto note_internal = RhythmGameUtilities::FindPositionNearGivenTick (
371
+ notes_internal, tick, delta );
339
372
340
- Array beat_bars_dictionary_array ;
373
+ Dictionary note ;
341
374
342
- for ( auto &beat_bar_internal : beat_bars_internal )
375
+ if (note_internal )
343
376
{
344
- Dictionary beat_bar_dictionary;
377
+ note[" position" ] = note_internal->Position ;
378
+ note[" hand_position" ] = note_internal->HandPosition ;
379
+ note[" length" ] = note_internal->Length ;
380
+ }
345
381
346
- beat_bar_dictionary[ " position " ] = beat_bar_internal. Position ;
347
- beat_bar_dictionary[ " bpm " ] = beat_bar_internal. BPM ;
382
+ return note ;
383
+ }
348
384
349
- beat_bars_dictionary_array.append (beat_bar_dictionary);
350
- }
385
+ bool rhythm_game_utilities::is_on_the_beat (int bpm, float current_time,
386
+ float delta)
387
+ {
388
+ return RhythmGameUtilities::IsOnTheBeat (bpm, current_time, delta);
389
+ }
351
390
352
- return beat_bars_dictionary_array;
391
+ int rhythm_game_utilities::round_up_to_the_nearest_multiplier (int value,
392
+ int multiplier)
393
+ {
394
+ return RhythmGameUtilities::RoundUpToTheNearestMultiplier (value,
395
+ multiplier);
353
396
}
0 commit comments