Skip to content

Commit ad7387a

Browse files
committed
Added new song class to Godot plugin.
1 parent d20d2a1 commit ad7387a

File tree

3 files changed

+220
-0
lines changed

3 files changed

+220
-0
lines changed

GodotPlugin/include/register_types.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "register_types.h"
22

33
#include "rhythm_game_utilities.h"
4+
#include "song.h"
45

56
#include <gdextension_interface.h>
67
#include <godot_cpp/core/class_db.hpp>
@@ -17,6 +18,7 @@ void initialize_rhythm_game_utilities(ModuleInitializationLevel p_level)
1718
}
1819

1920
ClassDB::register_class<rhythm_game_utilities>(true);
21+
ClassDB::register_class<Song>();
2022
}
2123

2224
void terminate_rhythm_game_utilities(ModuleInitializationLevel p_level)

GodotPlugin/include/song.cpp

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#include "song.h"
2+
3+
#include "rhythm_game_utilities.h"
4+
5+
#include <RhythmGameUtilities/Enums/Difficulty.h>
6+
#include <RhythmGameUtilities/Enums/NamedSection.h>
7+
8+
void Song::_bind_methods()
9+
{
10+
// sections
11+
12+
ClassDB::bind_method(D_METHOD("set_sections", "sections"),
13+
&Song::set_sections);
14+
ClassDB::bind_method(D_METHOD("get_sections"), &Song::get_sections);
15+
16+
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "sections"), "set_sections",
17+
"get_sections");
18+
19+
// meta_data
20+
21+
ClassDB::bind_method(D_METHOD("set_meta_data", "meta_data"),
22+
&Song::set_meta_data);
23+
ClassDB::bind_method(D_METHOD("get_meta_data"), &Song::get_meta_data);
24+
25+
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "meta_data"),
26+
"set_meta_data", "get_meta_data");
27+
28+
// resolution
29+
30+
ClassDB::bind_method(D_METHOD("set_resolution", "resolution"),
31+
&Song::set_resolution);
32+
ClassDB::bind_method(D_METHOD("get_resolution"), &Song::get_resolution);
33+
34+
ADD_PROPERTY(PropertyInfo(Variant::INT, "resolution"), "set_resolution",
35+
"get_resolution");
36+
37+
// tempo_changes
38+
39+
ClassDB::bind_method(D_METHOD("set_tempo_changes", "tempo_changes"),
40+
&Song::set_tempo_changes);
41+
ClassDB::bind_method(D_METHOD("get_tempo_changes"),
42+
&Song::get_tempo_changes);
43+
44+
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "tempo_changes"),
45+
"set_tempo_changes", "get_tempo_changes");
46+
47+
// time_signature_changes
48+
49+
ClassDB::bind_method(
50+
D_METHOD("set_time_signature_changes", "time_signature_changes"),
51+
&Song::set_time_signature_changes);
52+
ClassDB::bind_method(D_METHOD("get_time_signature_changes"),
53+
&Song::get_time_signature_changes);
54+
55+
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "time_signature_changes"),
56+
"set_time_signature_changes", "get_time_signature_changes");
57+
58+
// difficulties
59+
60+
ClassDB::bind_method(D_METHOD("set_difficulties", "difficulties"),
61+
&Song::set_difficulties);
62+
ClassDB::bind_method(D_METHOD("get_difficulties"), &Song::get_difficulties);
63+
64+
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "difficulties"),
65+
"set_difficulties", "get_difficulties");
66+
67+
// beat_bars
68+
69+
ClassDB::bind_method(D_METHOD("set_beat_bars", "beat_bars"),
70+
&Song::set_beat_bars);
71+
ClassDB::bind_method(D_METHOD("get_beat_bars"), &Song::get_beat_bars);
72+
73+
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "beat_bars"), "set_beat_bars",
74+
"get_beat_bars");
75+
76+
ClassDB::bind_method(D_METHOD("load_song", "contents"), &Song::load_song);
77+
}
78+
79+
// sections
80+
81+
void Song::set_sections(Dictionary value) { sections = value; }
82+
83+
Dictionary Song::get_sections() { return sections; }
84+
85+
// meta_data
86+
87+
void Song::set_meta_data(Dictionary value) { meta_data = value; }
88+
89+
Dictionary Song::get_meta_data() { return meta_data; }
90+
91+
// resolution
92+
93+
void Song::set_resolution(int value) { resolution = value; }
94+
95+
int Song::get_resolution() { return resolution; }
96+
97+
// tempo_changes
98+
99+
void Song::set_tempo_changes(Array value) { tempo_changes = value; }
100+
101+
Array Song::get_tempo_changes() { return tempo_changes; }
102+
103+
// time_signature_changes
104+
105+
void Song::set_time_signature_changes(Array value)
106+
{
107+
time_signature_changes = value;
108+
}
109+
110+
Array Song::get_time_signature_changes() { return time_signature_changes; }
111+
112+
// difficulties
113+
114+
void Song::set_difficulties(Dictionary value) { difficulties = value; }
115+
116+
Dictionary Song::get_difficulties() { return difficulties; }
117+
118+
// beat_bars
119+
120+
void Song::set_beat_bars(Array value) { beat_bars = value; }
121+
122+
Array Song::get_beat_bars() { return beat_bars; }
123+
124+
void Song::load_song(const String contents)
125+
{
126+
sections = rhythm_game_utilities::parse_sections_from_chart(contents);
127+
128+
meta_data = rhythm_game_utilities::parse_meta_data_from_chart_section(
129+
sections[godot::String(RhythmGameUtilities::ToString(
130+
RhythmGameUtilities::NamedSection::Song)
131+
.c_str())]);
132+
133+
resolution = int(meta_data["Resolution"]);
134+
135+
tempo_changes =
136+
rhythm_game_utilities::parse_tempo_changes_from_chart_section(
137+
sections[godot::String(
138+
RhythmGameUtilities::ToString(
139+
RhythmGameUtilities::NamedSection::SyncTrack)
140+
.c_str())]);
141+
142+
time_signature_changes =
143+
rhythm_game_utilities::parse_time_signature_changes_from_chart_section(
144+
sections[godot::String(
145+
RhythmGameUtilities::ToString(
146+
RhythmGameUtilities::NamedSection::SyncTrack)
147+
.c_str())]);
148+
149+
for (int difficultyInt = RhythmGameUtilities::Difficulty::Easy;
150+
difficultyInt <= RhythmGameUtilities::Difficulty::Expert;
151+
difficultyInt += 1)
152+
{
153+
auto difficulty =
154+
static_cast<RhythmGameUtilities::Difficulty>(difficultyInt);
155+
156+
auto key = godot::String(
157+
RhythmGameUtilities::ToString(difficulty).append("Single").c_str());
158+
159+
if (sections.has(key))
160+
{
161+
difficulties[godot::String(
162+
RhythmGameUtilities::ToString(difficulty).c_str())] =
163+
rhythm_game_utilities::parse_notes_from_chart_section(
164+
sections[key]);
165+
}
166+
}
167+
168+
beat_bars = rhythm_game_utilities::calculate_beat_bars(tempo_changes,
169+
resolution, 4, true);
170+
}

GodotPlugin/include/song.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
#include <godot_cpp/classes/object.hpp>
4+
#include <godot_cpp/core/class_db.hpp>
5+
#include <godot_cpp/variant/array.hpp>
6+
#include <godot_cpp/variant/dictionary.hpp>
7+
8+
using namespace godot;
9+
10+
class Song : public Object
11+
{
12+
GDCLASS(Song, Object)
13+
14+
protected:
15+
static void _bind_methods();
16+
17+
public:
18+
Dictionary sections;
19+
Dictionary meta_data;
20+
int resolution;
21+
Array tempo_changes;
22+
Array time_signature_changes;
23+
Dictionary difficulties;
24+
Array beat_bars;
25+
26+
void set_sections(Dictionary value);
27+
Dictionary get_sections();
28+
29+
void set_meta_data(Dictionary value);
30+
Dictionary get_meta_data();
31+
32+
void set_resolution(int value);
33+
int get_resolution();
34+
35+
void set_tempo_changes(Array value);
36+
Array get_tempo_changes();
37+
38+
void set_time_signature_changes(Array value);
39+
Array get_time_signature_changes();
40+
41+
void set_difficulties(Dictionary value);
42+
Dictionary get_difficulties();
43+
44+
void set_beat_bars(Array value);
45+
Array get_beat_bars();
46+
47+
void load_song(const String contents);
48+
};

0 commit comments

Comments
 (0)