use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NoteSound {
pub smap_note_id: Option<u16>,
pub time: u32,
}
impl Default for NoteSound {
fn default() -> Self {
Self {
smap_note_id: None,
time: 0,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PlayNote {
pub sound: NoteSound,
pub note_type: u8,
pub group: u8,
pub lane: u8,
}
impl Default for PlayNote {
fn default() -> Self {
Self {
sound: NoteSound::default(),
note_type: 0,
group: 0,
lane: 0,
}
}
}
impl PlayNote {
pub fn new() -> Self {
Self::default()
}
pub fn with_sound(mut self, smap_note_id: u16) -> Self {
self.sound = NoteSound {
smap_note_id: Some(smap_note_id),
time: 0,
};
self
}
pub fn with_time(mut self, time: u32) -> Self {
self.sound = NoteSound {
smap_note_id: None,
time,
};
self
}
pub fn with_type(mut self, note_type: u8) -> Self {
self.note_type = note_type;
self
}
pub fn with_group(mut self, note_group: u8) -> Self {
self.group = note_group;
self
}
pub fn with_lane(mut self, note_lane: u8) -> Self {
self.lane = note_lane;
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Chart {
pub name: String,
pub chart_type: String,
pub author: String,
pub difficulty_type: u8,
pub difficulty_level: u8,
pub content: Vec<PlayNote>,
pub variation: bool,
}
impl Default for Chart {
fn default() -> Self {
Self {
name: "Chart".to_string(),
author: "Unknown".to_string(),
chart_type: "Plain".to_string(),
difficulty_type: 0,
difficulty_level: 1,
content: vec![],
variation: false,
}
}
}
impl Chart {
pub fn new(name: &str, author: &str) -> Self {
let mut chart = Self::default();
chart.name = name.to_string();
chart.author = author.to_string();
chart
}
pub fn with_chart_type(mut self, chart_type: &str) -> Self {
self.chart_type = chart_type.to_string();
self
}
pub fn with_difficulty_type(mut self, diff_type: u8) -> Self {
self.difficulty_type = diff_type;
self
}
pub fn with_level(mut self, diff_level: u8) -> Self {
self.difficulty_level = diff_level;
self
}
pub fn variation(mut self) -> Self {
self.variation = true;
self
}
pub fn insert_note(&mut self, lane: u8, smap_note_id: u16) {
let note = PlayNote::new().with_lane(lane).with_sound(smap_note_id);
self.content.push(note);
}
pub fn insert_silent_note(&mut self, lane: u8, time: u32) {
let note = PlayNote::new().with_lane(lane).with_time(time);
self.content.push(note);
}
}