feat: convert music detail to dxrating
This commit is contained in:
95
sdgb-api/src/title/model/dxrating/mod.rs
Normal file
95
sdgb-api/src/title/model/dxrating/mod.rs
Normal file
@@ -0,0 +1,95 @@
|
||||
use serde::Serialize;
|
||||
|
||||
/// Full payload for image generate api
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DxRatingNet {
|
||||
pub calculated_entries: DxCalculatedEntries,
|
||||
|
||||
pub version: DataVersion,
|
||||
/// use `_generic`
|
||||
pub region: &'static str,
|
||||
}
|
||||
|
||||
/// Export/Import format
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DxCalculatedEntries {
|
||||
pub b35: Vec<DxMusicRecord>,
|
||||
pub b15: Vec<DxMusicRecord>,
|
||||
}
|
||||
|
||||
/// full music record
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DxMusicRecord {
|
||||
pub sheet_id: DxSheetId,
|
||||
pub achievement_rate: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DxSheetId {
|
||||
pub music_title: String,
|
||||
pub dx_version: bool,
|
||||
pub level: DxLevelName,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, strum::IntoStaticStr, strum::FromRepr)]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[repr(u32)]
|
||||
pub enum DxLevelName {
|
||||
Basic,
|
||||
Advanced,
|
||||
Expert,
|
||||
Master,
|
||||
ReMaster,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum DataVersion {
|
||||
Buddies,
|
||||
BuddiesPlus,
|
||||
Prism,
|
||||
PrismPlus,
|
||||
}
|
||||
|
||||
impl Serialize for DataVersion {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(match self {
|
||||
DataVersion::Buddies => "BUDDiES",
|
||||
DataVersion::BuddiesPlus => "BUDDiES PLUS",
|
||||
DataVersion::Prism => "PRiSM",
|
||||
DataVersion::PrismPlus => "PRiSM PLUS",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for DxSheetId {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for DxSheetId {
|
||||
fn to_string(&self) -> String {
|
||||
let mut output = self.music_title.clone();
|
||||
|
||||
if self.dx_version {
|
||||
output += "__dxrt__dx__dxrt__"
|
||||
} else {
|
||||
output += "__dxrt__std__dxrt__"
|
||||
}
|
||||
|
||||
output += self.level.into();
|
||||
|
||||
output
|
||||
}
|
||||
}
|
||||
|
||||
mod conversion;
|
||||
Reference in New Issue
Block a user