|
| 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 | +} |
0 commit comments