1
1
#include " rhythm_game_utilities.h"
2
2
3
- #include < godot_cpp/variant/dictionary .hpp>
3
+ #include " utilities .hpp"
4
4
5
5
#include < RhythmGameUtilities/Common.hpp>
6
6
#include < RhythmGameUtilities/Utilities.hpp>
@@ -45,6 +45,12 @@ void rhythm_game_utilities::_bind_methods()
45
45
D_METHOD (" calculate_accuracy_ratio" , " position" , " currentPosition" ,
46
46
" delta" ),
47
47
&rhythm_game_utilities::calculate_accuracy_ratio);
48
+
49
+ ClassDB::bind_static_method (" rhythm_game_utilities" ,
50
+ D_METHOD (" calculate_beat_bars" , " bpmChanges" ,
51
+ " resolution" , " ts" ,
52
+ " includeHalfNotes" ),
53
+ &rhythm_game_utilities::calculate_beat_bars);
48
54
}
49
55
50
56
// Common
@@ -65,18 +71,8 @@ int rhythm_game_utilities::convert_seconds_to_ticks(float seconds,
65
71
int resolution,
66
72
Dictionary bpmChanges)
67
73
{
68
- std::map<int , int > bpmChangesMap;
69
-
70
- auto keys = bpmChanges.keys ();
71
-
72
- for (auto i = 0 ; i < keys.size (); i += 1 )
73
- {
74
- auto key = keys[i];
75
- bpmChangesMap[key] = bpmChanges[key];
76
- }
77
-
78
- return RhythmGameUtilities::ConvertSecondsToTicks (seconds, resolution,
79
- bpmChangesMap);
74
+ return RhythmGameUtilities::ConvertSecondsToTicks (
75
+ seconds, resolution, convert_dictionary_to_map<int , int >(bpmChanges));
80
76
}
81
77
82
78
float rhythm_game_utilities::convert_tick_to_position (int tick, int resolution)
@@ -104,3 +100,26 @@ float rhythm_game_utilities::calculate_accuracy_ratio(int position,
104
100
return RhythmGameUtilities::CalculateAccuracyRatio (position,
105
101
currentPosition, delta);
106
102
}
103
+
104
+ Array rhythm_game_utilities::calculate_beat_bars (Dictionary bpmChanges,
105
+ int resolution, int ts,
106
+ bool includeHalfNotes)
107
+ {
108
+ auto beatBars = RhythmGameUtilities::CalculateBeatBars (
109
+ convert_dictionary_to_map<int , int >(bpmChanges), resolution, ts,
110
+ includeHalfNotes);
111
+
112
+ Array beatBarsDictionaryArray;
113
+
114
+ for (auto &beatBar : beatBars)
115
+ {
116
+ Dictionary beatBarDictionary;
117
+
118
+ beatBarDictionary[" bpm" ] = beatBar.BPM ;
119
+ beatBarDictionary[" position" ] = beatBar.Position ;
120
+
121
+ beatBarsDictionaryArray.append (beatBarDictionary);
122
+ }
123
+
124
+ return beatBarsDictionaryArray;
125
+ }
0 commit comments