1use serde::{Deserialize, Serialize};
2use serde_json::Result;
3
4#[derive(Deserialize, Serialize, Debug, Default)]
6pub struct Bmson {
7 pub version: String,
8 pub info: BmsonInfo,
9 pub lines: Option<Vec<BarLine>>,
10 pub bpm_events: Option<Vec<BpmEvent>>,
11 pub stop_events: Option<Vec<StopEvent>>,
12 pub sound_channels: Option<Vec<SoundChannel>>,
13 pub bga: Bga,
14 pub scroll_events: Option<Vec<ScrollEvent>>,
16 pub mine_channels: Option<Vec<MineChannel>>,
18 pub key_channels: Option<Vec<KeyChannel>>,
20}
21
22#[derive(Deserialize, Serialize, Debug, Default)]
24pub struct BmsonInfo {
25 pub title: String,
26 pub subtitle: String,
27 pub artist: String,
28 pub subartists: Option<Vec<String>>,
29 pub genre: String,
30 #[serde(default = "default_mode_hint")]
31 pub mode_hint: String,
32 pub chart_name: String,
33 pub level: u32,
34 pub init_bpm: f64,
35 #[serde(default = "default_judge_rank")]
36 pub judge_rank: f64,
37 #[serde(default = "default_total")]
38 pub total: f64,
39 pub back_image: Option<String>,
40 pub eyecatch_image: Option<String>,
41 pub banner_image: Option<String>,
42 pub preview_music: Option<String>,
43 #[serde(default = "default_resolution")]
44 pub resolution: u32,
45 pub ln_type: Option<String>,
47}
48fn default_mode_hint() -> String {
49 "beat-7k".to_string()
50}
51fn default_judge_rank() -> f64 {
52 100.
53}
54fn default_total() -> f64 {
55 100.
56}
57fn default_resolution() -> u32 {
58 240
59}
60
61#[derive(Deserialize, Serialize, Debug, Default)]
63pub struct BarLine {
64 pub y: u32,
65}
66
67#[derive(Deserialize, Serialize, Debug, Default)]
71pub struct SoundChannel {
72 pub name: String,
73 pub notes: Vec<Note>,
74}
75
76#[derive(Deserialize, Serialize, Debug, Default)]
78pub struct Note {
79 pub x: Option<u32>,
83 pub y: u32,
84 pub l: u32,
85 pub c: bool,
86 pub t: Option<String>,
88 pub up: Option<bool>,
90}
91
92#[derive(Deserialize, Serialize, Debug, Default)]
94pub struct BpmEvent {
95 pub y: u32,
96 pub bpm: f64,
97}
98
99#[derive(Deserialize, Serialize, Debug, Default)]
101pub struct StopEvent {
102 pub y: u32,
103 pub duration: u32,
104}
105
106#[derive(Deserialize, Serialize, Debug, Default)]
108pub struct Bga {
109 pub bga_header: Vec<BgaHeader>,
110 pub bga_events: Vec<BgaEvent>,
111 pub layer_events: Vec<BgaEvent>,
112 pub poor_events: Vec<BgaEvent>,
113}
114
115#[derive(Deserialize, Serialize, Debug, Default)]
117pub struct BgaHeader {
118 pub id: u32,
119 pub name: String,
120}
121
122#[derive(Deserialize, Serialize, Debug, Default)]
124pub struct BgaEvent {
125 pub y: u32,
126 pub id: u32,
127}
128
129#[derive(Deserialize, Serialize, Debug, Default)]
131pub struct ScrollEvent {
132 pub y: f64,
133}
134
135#[derive(Deserialize, Serialize, Debug, Default)]
137pub struct MineChannel {
138 pub name: String,
139 pub notes: Vec<MineNote>,
140}
141
142#[derive(Deserialize, Serialize, Debug, Default)]
144pub struct MineNote {
145 pub x: Option<u32>,
146 pub y: u32,
147 pub damage: f64,
148}
149
150#[derive(Deserialize, Serialize, Debug, Default)]
152pub struct KeyChannel {
153 pub name: String,
154 pub notes: Vec<KeyNote>,
155}
156
157#[derive(Deserialize, Serialize, Debug, Default)]
159pub struct KeyNote {
160 pub x: Option<u32>,
161 pub y: u32,
162}
163
164impl Bmson {
165 pub fn new(source: &str) -> Result<Bmson> {
166 serde_json::from_str(source)
167 }
168}