Skip to content

Commit 84e030c

Browse files
committed
Start implementing beatmap module, plus refinements
- Make all types implement `Clone` and some `Copy - Wrap long doc comments - Rename non-self-explanatory fields
1 parent 75d6d67 commit 84e030c

File tree

6 files changed

+572
-70
lines changed

6 files changed

+572
-70
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ Documentation can be found on [docs.rs](https://docs.rs/beat_saber_map).
2121
- [ ] Create structures for map files
2222
- [x] [`Info`](https://docs.rs/beat_saber_map/latest/beat_saber_map/info/struct.Info.html)
2323
- [x] [`Audio`](https://docs.rs/beat_saber_map/latest/beat_saber_map/audio/struct.Audio.html)
24-
- [ ] `Beatmap`
24+
- [ ] [`Beatmap`](https://docs.rs/beat_saber_map/latest/beat_saber_map/beatmap/struct.Beatmap.html)
2525
- [ ] `Lightshow`
2626
- [ ] Create utility methods for map file structures and [`BeatSaberMap`](https://docs.rs/beat_saber_map/latest/beat_saber_map/struct.BeatSaberMap.html)
2727
- [x] [`BeatSaberMap::from_dir()`](https://docs.rs/beat_saber_map/latest/beat_saber_map/struct.BeatSaberMap.html#method.from_dir)
2828
- [x] [`Info::from_file()`](https://docs.rs/beat_saber_map/latest/beat_saber_map/info/struct.Info.html#method.from_file)
2929
- [x] [`Audio::from_file()`](https://docs.rs/beat_saber_map/latest/beat_saber_map/audio/struct.Audio.html#method.from_file)
30+
- [x] [`Beatmap::from_file()`](https://docs.rs/beat_saber_map/latest/beat_saber_map/beatmap/struct.Beatmap.html#method.from_file)
3031
- [ ] More...

sample/Normal.dat

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"version": "4.0.0",
3+
"colorNotes": [
4+
{
5+
"b": 10,
6+
"r": 0,
7+
"i": 0
8+
}
9+
],
10+
"colorNotesData": [
11+
{
12+
"x": 1,
13+
"y": 0,
14+
"c": 0,
15+
"d": 1,
16+
"a": 0
17+
},
18+
{
19+
"x": 2,
20+
"y": 2,
21+
"c": 0,
22+
"d": 0,
23+
"a": 0
24+
}
25+
],
26+
"bombNotes": [
27+
{
28+
"b": 10,
29+
"r": 0,
30+
"i": 0
31+
}
32+
],
33+
"bombNotesData": [
34+
{
35+
"x": 1,
36+
"y": 0
37+
}
38+
],
39+
"obstacles": [
40+
{
41+
"b": 10,
42+
"r": 0,
43+
"i": 0
44+
}
45+
],
46+
"obstaclesData": [
47+
{
48+
"d": 5,
49+
"x": 1,
50+
"y": 0,
51+
"w": 1,
52+
"h": 5
53+
}
54+
],
55+
"arcs": [
56+
{
57+
"hb": 10,
58+
"tb": 15,
59+
"hr": 0,
60+
"tr": 0,
61+
"hi": 0,
62+
"ti": 1,
63+
"ai": 0
64+
}
65+
],
66+
"arcsData": [
67+
{
68+
"m": 1,
69+
"tm": 1,
70+
"a": 0
71+
}
72+
],
73+
"chains": [
74+
{
75+
"hb": 10,
76+
"tb": 15,
77+
"hr": 0,
78+
"tr": 0,
79+
"i": 0,
80+
"ci": 0
81+
}
82+
],
83+
"chainsData": [
84+
{
85+
"tx": 2,
86+
"ty": 2,
87+
"c": 3,
88+
"s": 0.5
89+
}
90+
],
91+
"spawnRotations": [
92+
{
93+
"b": 10,
94+
"i": 0
95+
},
96+
{
97+
"b": 15,
98+
"i": 1
99+
}
100+
],
101+
"spawnRotationsData": [
102+
{
103+
"t": 0,
104+
"r": 15
105+
},
106+
{
107+
"t": 1,
108+
"r": 15
109+
}
110+
]
111+
}

src/audio.rs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,31 @@ use crate::Error;
88

99
/// Information regarding how audio file should be processed.
1010
///
11-
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html) for language-agnostic documentation.
12-
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
11+
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html)
12+
/// for language-agnostic documentation.
13+
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
1314
#[serde(rename_all = "camelCase")]
1415
#[serde(default)]
1516
pub struct Audio {
1617
/// Should be "4.0.0", that's the currently supported schema version.
1718
pub version: String,
1819
/// Used for verifying internal relationships and leaderboard integrity.
1920
///
20-
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format.html#checksums) for language-agnostic documentation.
21+
/// Refer to the
22+
/// [BSMG Wiki](https://bsmg.wiki/mapping/map-format.html#checksums) for
23+
/// language-agnostic documentation.
2124
pub song_checksum: String,
2225
/// Measures duration of audio file in samples.
2326
///
24-
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#sample-count) for language-agnostic documentation.
27+
/// Refer to the
28+
/// [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#sample-count)
29+
/// for language-agnostic documentation.
2530
pub song_sample_count: u32,
2631
/// Caches quality level of audio file.
2732
///
28-
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#song-frequency) for language-agnostic documentation.
33+
/// Refer to the
34+
/// [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#song-frequency)
35+
/// for language-agnostic documentation.
2936
pub song_frequency: u32,
3037
/// See [`BpmData`].
3138
pub bpm_data: Vec<BpmData>,
@@ -47,40 +54,52 @@ impl Default for Audio {
4754
}
4855

4956
impl Audio {
50-
/// Instatiates an [`Audio`] from an audio file, typically named `BPMInfo.dat`.
57+
/// Instatiates an [`Audio`] from an audio file, typically named
58+
/// `BPMInfo.dat`.
5159
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> {
5260
Ok(serde_json::from_str(&fs::read_to_string(path)?)?)
5361
}
5462
}
5563

5664
/// Alters BPM of specified region.
5765
///
58-
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#bpm-regions) for language-agnostic documentation.
59-
#[derive(Debug, PartialEq, Eq, Default, Deserialize, Serialize)]
66+
/// Refer to the
67+
/// [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#bpm-regions) for
68+
/// language-agnostic documentation.
69+
#[derive(Debug, Clone, PartialEq, Eq, Default, Deserialize, Serialize)]
6070
#[serde(default)]
6171
pub struct BpmData {
6272
/// Start sample index.
63-
pub si: usize,
73+
#[serde(rename = "si")]
74+
pub start_index: usize,
6475
/// End sample index.
65-
pub ei: usize,
76+
#[serde(rename = "ei")]
77+
pub end_index: usize,
6678
/// Start beat.
67-
pub sb: usize,
79+
#[serde(rename = "sb")]
80+
pub start_beat: usize,
6881
/// End beat.
69-
pub eb: usize,
82+
#[serde(rename = "eb")]
83+
pub end_beat: usize,
7084
}
7185

7286
/// Applies normalization to loudness of audio file within specified region.
7387
///
74-
/// Refer to the [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#lufs-data) for language-agnostic documentation.
75-
#[derive(Debug, PartialEq, Eq, Default, Deserialize, Serialize)]
88+
/// Refer to the
89+
/// [BSMG Wiki](https://bsmg.wiki/mapping/map-format/audio.html#lufs-data) for
90+
/// language-agnostic documentation.
91+
#[derive(Debug, Clone, PartialEq, Eq, Default, Deserialize, Serialize)]
7692
#[serde(default)]
7793
pub struct LufsData {
7894
/// Start sample index.
79-
pub si: usize,
95+
#[serde(rename = "si")]
96+
pub start_index: usize,
8097
/// End sample index.
81-
pub ei: usize,
98+
#[serde(rename = "ei")]
99+
pub end_index: usize,
82100
/// Loudness.
83-
pub l: usize,
101+
#[serde(rename = "l")]
102+
pub loudness: usize,
84103
}
85104

86105
#[cfg(test)]
@@ -100,15 +119,15 @@ mod tests {
100119
song_sample_count: 1149214,
101120
song_frequency: 44100,
102121
bpm_data: vec![BpmData {
103-
si: 0,
104-
ei: 1149214,
105-
sb: 0,
106-
eb: 26,
122+
start_index: 0,
123+
end_index: 1149214,
124+
start_beat: 0,
125+
end_beat: 26,
107126
}],
108127
lufs_data: vec![LufsData {
109-
si: 0,
110-
ei: 1149214,
111-
l: 0,
128+
start_index: 0,
129+
end_index: 1149214,
130+
loudness: 0,
112131
}],
113132
}
114133
}

0 commit comments

Comments
 (0)