Skip to content

Commit 2f2fe33

Browse files
committed
Added new method.
1 parent aa3e449 commit 2f2fe33

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

GodotPlugin/include/rhythm_game_utilities.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "utilities.hpp"
44

55
#include <RhythmGameUtilities/Common.hpp>
6+
#include <RhythmGameUtilities/Parsers.hpp>
67
#include <RhythmGameUtilities/Utilities.hpp>
78

89
void rhythm_game_utilities::_bind_methods()
@@ -17,6 +18,13 @@ void rhythm_game_utilities::_bind_methods()
1718
D_METHOD("inverse_lerp", "a", "b", "v"),
1819
&rhythm_game_utilities::inverse_lerp);
1920

21+
// Parsers
22+
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);
27+
2028
// Utilities
2129

2230
ClassDB::bind_static_method(
@@ -65,6 +73,44 @@ float rhythm_game_utilities::inverse_lerp(float a, float b, float v)
6573
return RhythmGameUtilities::InverseLerp(a, b, v);
6674
}
6775

76+
// Parsers
77+
78+
Dictionary rhythm_game_utilities::parse_sections_from_chart(String contents)
79+
{
80+
Dictionary sections;
81+
82+
auto sectionsInternal =
83+
RhythmGameUtilities::ParseSectionsFromChart(contents.utf8().get_data());
84+
85+
for (auto sectionInternal = sectionsInternal.begin();
86+
sectionInternal != sectionsInternal.end(); sectionInternal++)
87+
{
88+
auto sectionKey = godot::String(sectionInternal->first.c_str());
89+
90+
Dictionary section;
91+
92+
for (auto i = 0; i < sectionInternal->second.size(); i += 1)
93+
{
94+
auto temp = sectionInternal->second[i];
95+
96+
auto key = godot::Variant(temp.first.c_str());
97+
98+
Array values;
99+
100+
for (auto j = 0; j < temp.second.size(); j += 1)
101+
{
102+
values.append(godot::Variant(temp.second[j].c_str()));
103+
}
104+
105+
section[key] = values;
106+
}
107+
108+
sections[sectionKey] = section;
109+
}
110+
111+
return sections;
112+
}
113+
68114
// Utilities
69115

70116
int rhythm_game_utilities::convert_seconds_to_ticks(float seconds,

GodotPlugin/include/rhythm_game_utilities.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class rhythm_game_utilities : public Object
2222

2323
static float inverse_lerp(float a, float b, float v);
2424

25+
// Parsers
26+
27+
static Dictionary parse_sections_from_chart(String contents);
28+
2529
// Utilities
2630

2731
static int convert_seconds_to_ticks(float seconds, int resolution,

0 commit comments

Comments
 (0)