bms_utils/
bmson.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Result;
3
4/// Bmson本体
5#[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    /// beatoraja拡張
15    pub scroll_events: Option<Vec<ScrollEvent>>,
16    /// beatoraja拡張
17    pub mine_channels: Option<Vec<MineChannel>>,
18    /// beatoraja拡張
19    pub key_channels: Option<Vec<KeyChannel>>,
20}
21
22/// ヘッダー
23#[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    /// beatoraja拡張
46    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/// 小節線イベント
62#[derive(Deserialize, Serialize, Debug, Default)]
63pub struct BarLine {
64    pub y: u32,
65}
66
67/// サウンドチャンネル
68///
69/// DTMソフトのトラックと似ている
70#[derive(Deserialize, Serialize, Debug, Default)]
71pub struct SoundChannel {
72    pub name: String,
73    pub notes: Vec<Note>,
74}
75
76/// サウンドノート
77#[derive(Deserialize, Serialize, Debug, Default)]
78pub struct Note {
79    /// 演奏レーン
80    ///
81    /// 0 or NullでGBM
82    pub x: Option<u32>,
83    pub y: u32,
84    pub l: u32,
85    pub c: bool,
86    /// beatoraja拡張
87    pub t: Option<String>,
88    /// beatoraja拡張
89    pub up: Option<bool>,
90}
91
92/// BPM変化イベント
93#[derive(Deserialize, Serialize, Debug, Default)]
94pub struct BpmEvent {
95    pub y: u32,
96    pub bpm: f64,
97}
98
99/// 譜面停止イベント
100#[derive(Deserialize, Serialize, Debug, Default)]
101pub struct StopEvent {
102    pub y: u32,
103    pub duration: u32,
104}
105
106/// BGAデータ
107#[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/// 画像ファイル
116#[derive(Deserialize, Serialize, Debug, Default)]
117pub struct BgaHeader {
118    pub id: u32,
119    pub name: String,
120}
121
122/// BGA設定イベント
123#[derive(Deserialize, Serialize, Debug, Default)]
124pub struct BgaEvent {
125    pub y: u32,
126    pub id: u32,
127}
128
129/// スクロール速度設定イベント(beatoraja拡張)
130#[derive(Deserialize, Serialize, Debug, Default)]
131pub struct ScrollEvent {
132    pub y: f64,
133}
134
135/// 地雷チャンネル(beatoraja拡張)
136#[derive(Deserialize, Serialize, Debug, Default)]
137pub struct MineChannel {
138    pub name: String,
139    pub notes: Vec<MineNote>,
140}
141
142/// 地雷ノート(beatoraja拡張)
143#[derive(Deserialize, Serialize, Debug, Default)]
144pub struct MineNote {
145    pub x: Option<u32>,
146    pub y: u32,
147    pub damage: f64,
148}
149
150/// 不可視チャンネル(beatoraja拡張)
151#[derive(Deserialize, Serialize, Debug, Default)]
152pub struct KeyChannel {
153    pub name: String,
154    pub notes: Vec<KeyNote>,
155}
156
157/// 不可視ノート(beatoraja拡張)
158#[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}