Skip to main content

rgc_chart/models/quaver/
chart.rs

1use serde::{Deserialize, Serialize};
2use crate::models::quaver::{
3    editor::*,
4    sound::*,
5    timing_points::*,
6    hitobjects::*,
7};
8
9#[derive(Debug, Deserialize, Serialize)]
10pub struct QuaFile {
11    #[serde(rename = "AudioFile")]
12    pub audio_file: String,
13    
14    #[serde(rename = "SongPreviewTime")]
15    pub song_preview_time: i32,
16    
17    #[serde(rename = "BackgroundFile")]
18    pub background_file: String,
19
20    #[serde(rename = "MapId", default = "default_id")]
21    pub map_id: i32,
22
23    #[serde(rename = "MapSetId", default = "default_id")]
24    pub mapset_id: i32,
25    
26    #[serde(rename = "Mode")]
27    pub mode: String,
28    
29    #[serde(rename = "Title")]
30    pub title: String,
31    
32    #[serde(rename = "Artist")]
33    pub artist: String,
34    
35    #[serde(rename = "Source")]
36    pub source: String,
37    
38    #[serde(rename = "Tags")]
39    pub tags: String,
40    
41    #[serde(rename = "Creator")]
42    pub creator: String,
43    
44    #[serde(rename = "DifficultyName")]
45    pub difficulty_name: String,
46    
47    #[serde(rename = "BPMDoesNotAffectScrollVelocity", default = "default_bpm_does_not_affect_scroll_velocity")]
48    pub bpm_does_not_affect_scroll_velocity: bool,
49    
50    #[serde(rename = "InitialScrollVelocity", default = "default_initial_scroll_velocity")]
51    pub initial_scroll_velocity: f32,
52
53    #[serde(rename = "HasScratchKey", default = "default_has_scratch_key")]
54    pub has_scratch_key: bool,
55    
56    #[serde(rename = "EditorLayers")]
57    pub editor_layers: Vec<EditorLayer>,
58    
59    #[serde(rename = "CustomAudioSamples")]
60    pub custom_audio_samples: Vec<AudioSample>,
61
62    #[serde(rename = "SoundEffects")]
63    pub sound_effects: Vec<SoundEffect>,
64
65    #[serde(rename = "TimingPoints")]
66    pub timing_points: Vec<TimingPoint>,
67
68    #[serde(rename = "SliderVelocities")]
69    pub slider_velocities: Vec<SliderVelocity>,
70
71    #[serde(rename = "HitObjects")]
72    pub hitobjects: Vec<HitObject>,
73}
74
75impl QuaFile {
76    pub fn to_str(&self) -> Result<String, serde_yaml_ng::Error> {
77        serde_yaml_ng::to_string(self)
78    }
79
80    pub fn from_str(yaml: &str) -> Result<Self, serde_yaml_ng::Error> {
81        serde_yaml_ng::from_str(yaml)
82    }
83}
84
85fn default_id() -> i32 { -1i32 }
86fn default_bpm_does_not_affect_scroll_velocity() -> bool { true }
87fn default_initial_scroll_velocity() -> f32 { 1f32 }
88fn default_has_scratch_key() -> bool { false }
89
90impl Default for QuaFile {
91    fn default() -> Self {
92        Self {
93            audio_file: String::new(),
94            song_preview_time: 0,
95            background_file: String::new(),
96            map_id: default_id(),
97            mapset_id: default_id(),
98            mode: String::new(),
99            title: String::new(),
100            artist: String::new(),
101            source: String::new(),
102            tags: String::new(),
103            creator: String::new(),
104            difficulty_name: String::new(),
105            bpm_does_not_affect_scroll_velocity: default_bpm_does_not_affect_scroll_velocity(),
106            initial_scroll_velocity: default_initial_scroll_velocity(),
107            has_scratch_key: default_has_scratch_key(),
108            editor_layers: Vec::new(),
109            custom_audio_samples: Vec::new(),
110            sound_effects: Vec::new(),
111            timing_points: Vec::new(),
112            slider_velocities: Vec::new(),
113            hitobjects: Vec::new(),
114        }
115    }
116}