use strict_num_extended::{FinF64, NonNegativeF64, PositiveF64};
use crate::bms::command::{
JudgeLevel, ObjId,
channel::{Channel, NoteChannelId},
time::{ObjTime, Track},
};
use crate::bms::command::{graphics::Argb, minor_command::SwBgaEvent};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WavObj {
pub offset: ObjTime,
pub channel_id: NoteChannelId,
pub wav_id: ObjId,
}
impl PartialOrd for WavObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for WavObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.offset
.cmp(&other.offset)
.then(self.wav_id.cmp(&other.wav_id))
}
}
impl WavObj {
pub(crate) fn dangling() -> Self {
Self {
offset: ObjTime::start_of(1.into()),
channel_id: NoteChannelId::bgm(),
wav_id: ObjId::null(),
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BpmChangeObj {
pub time: ObjTime,
pub bpm: PositiveF64,
}
impl PartialEq for BpmChangeObj {
fn eq(&self, other: &Self) -> bool {
self.time == other.time
}
}
impl Eq for BpmChangeObj {}
impl PartialOrd for BpmChangeObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for BpmChangeObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.time.cmp(&other.time)
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SectionLenChangeObj {
pub track: Track,
pub length: FinF64,
}
impl PartialEq for SectionLenChangeObj {
fn eq(&self, other: &Self) -> bool {
self.track == other.track
}
}
impl Eq for SectionLenChangeObj {}
impl PartialOrd for SectionLenChangeObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SectionLenChangeObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.track.cmp(&other.track)
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StopObj {
pub time: ObjTime,
pub duration: NonNegativeF64,
}
impl PartialEq for StopObj {
fn eq(&self, other: &Self) -> bool {
self.time == other.time
}
}
impl Eq for StopObj {}
impl PartialOrd for StopObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for StopObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.time.cmp(&other.time)
}
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BgaObj {
pub time: ObjTime,
pub id: ObjId,
pub layer: BgaLayer,
}
impl PartialEq for BgaObj {
fn eq(&self, other: &Self) -> bool {
self.time == other.time
}
}
impl Eq for BgaObj {}
impl PartialOrd for BgaObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for BgaObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.time.cmp(&other.time)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum BgaLayer {
Base,
Poor,
Overlay,
Overlay2,
}
impl BgaLayer {
#[must_use]
pub const fn from_channel(channel: Channel) -> Option<Self> {
match channel {
Channel::BgaBase | Channel::BgaBaseArgb | Channel::BgaBaseOpacity => Some(Self::Base),
Channel::BgaLayer | Channel::BgaLayerArgb | Channel::BgaLayerOpacity => {
Some(Self::Overlay)
}
Channel::BgaLayer2 | Channel::BgaLayer2Argb | Channel::BgaLayer2Opacity => {
Some(Self::Overlay2)
}
Channel::BgaPoor | Channel::BgaPoorArgb | Channel::BgaPoorOpacity => Some(Self::Poor),
_ => None,
}
}
#[must_use]
pub const fn to_channel(self) -> Channel {
match self {
Self::Base => Channel::BgaBase,
Self::Overlay => Channel::BgaLayer,
Self::Overlay2 => Channel::BgaLayer2,
Self::Poor => Channel::BgaPoor,
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ScrollingFactorObj {
pub time: ObjTime,
pub factor: FinF64,
}
impl PartialEq for ScrollingFactorObj {
fn eq(&self, other: &Self) -> bool {
self.time == other.time
}
}
impl Eq for ScrollingFactorObj {}
impl PartialOrd for ScrollingFactorObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for ScrollingFactorObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.time.cmp(&other.time)
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SpeedObj {
pub time: ObjTime,
pub factor: PositiveF64,
}
impl PartialEq for SpeedObj {
fn eq(&self, other: &Self) -> bool {
self.time == other.time
}
}
impl Eq for SpeedObj {}
impl PartialOrd for SpeedObj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SpeedObj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.time.cmp(&other.time)
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BgaOpacityObj {
pub time: ObjTime,
pub layer: BgaLayer,
pub opacity: u8,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BgaArgbObj {
pub time: ObjTime,
pub layer: BgaLayer,
pub argb: Argb,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BgmVolumeObj {
pub time: ObjTime,
pub volume: u8,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct KeyVolumeObj {
pub time: ObjTime,
pub volume: u8,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SeekObj {
pub time: ObjTime,
pub position: FinF64,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextObj {
pub time: ObjTime,
pub text: String,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct JudgeObj {
pub time: ObjTime,
pub judge_level: JudgeLevel,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BgaKeyboundObj {
pub time: ObjTime,
pub event: SwBgaEvent,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OptionObj {
pub time: ObjTime,
pub option: String,
}