mania key mods added & some refactoring

This commit is contained in:
MaxOhn
2021-01-16 10:25:09 +01:00
parent c95de10b9b
commit fedcbb3fa2
4 changed files with 67 additions and 78 deletions
@@ -2,6 +2,12 @@ use crate::{Beatmap, DifficultyPoint, TimingPoint};
use std::slice::Iter;
macro_rules! next_tuple {
($iter:expr, ($first:ident, $second:ident)) => {
$iter.next().map(|e| (e.$first, e.$second))
};
}
pub(crate) struct ControlPointIter<'p> {
timing_points: Iter<'p, TimingPoint>,
difficulty_points: Iter<'p, DifficultyPoint>,
@@ -11,15 +17,14 @@ pub(crate) struct ControlPointIter<'p> {
}
impl<'p> ControlPointIter<'p> {
#[inline]
pub(crate) fn new(map: &'p Beatmap) -> Self {
let mut timing_points = map.timing_points.iter();
let mut difficulty_points = map.difficulty_points.iter();
Self {
next_timing: timing_points.next().map(|t| t.time),
next_difficulty: difficulty_points
.next()
.map(|d| (d.time, d.speed_multiplier)),
next_difficulty: next_tuple!(difficulty_points, (time, speed_multiplier)),
timing_points,
difficulty_points,
@@ -42,11 +47,9 @@ impl<'p> Iterator for ControlPointIter<'p> {
Some(ControlPoint::Timing { time })
}
(Some(_), Some((time, speed_multiplier))) => {
self.next_difficulty = self
.difficulty_points
.next()
.map(|d| (d.time, d.speed_multiplier));
(_, Some((time, speed_multiplier))) => {
self.next_difficulty =
next_tuple!(self.difficulty_points, (time, speed_multiplier));
Some(ControlPoint::Difficulty {
time,
@@ -58,17 +61,6 @@ impl<'p> Iterator for ControlPointIter<'p> {
Some(ControlPoint::Timing { time })
}
(_, Some((time, speed_multiplier))) => {
self.next_difficulty = self
.difficulty_points
.next()
.map(|d| (d.time, d.speed_multiplier));
Some(ControlPoint::Difficulty {
time,
speed_multiplier,
})
}
(None, None) => None,
}
}
+7 -7
View File
@@ -1,8 +1,8 @@
const HITSOUND_WHISTLE: u8 = 1 << 1;
const HITSOUND_FINISH: u8 = 1 << 2;
const HITSOUND_CLAP: u8 = 1 << 3;
pub trait HitSound {
const HITSOUND_WHISTLE: u8 = 1 << 1;
const HITSOUND_FINISH: u8 = 1 << 2;
const HITSOUND_CLAP: u8 = 1 << 3;
fn normal(self) -> bool;
fn whistle(self) -> bool;
fn finish(self) -> bool;
@@ -15,14 +15,14 @@ impl HitSound for u8 {
}
fn whistle(self) -> bool {
self & HITSOUND_WHISTLE > 0
self & Self::HITSOUND_WHISTLE > 0
}
fn finish(self) -> bool {
self & HITSOUND_FINISH > 0
self & Self::HITSOUND_FINISH > 0
}
fn clap(self) -> bool {
self & HITSOUND_CLAP > 0
self & Self::HITSOUND_CLAP > 0
}
}
+2 -2
View File
@@ -42,7 +42,7 @@ macro_rules! validate_float {
}};
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum GameMode {
STD = 0,
TKO = 1,
@@ -379,7 +379,7 @@ impl FromStr for PathType {
}
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
enum Section {
None,
General,
+47 -50
View File
@@ -1,3 +1,12 @@
macro_rules! impl_mods {
($func_name:ident, $const_name:ident) => {
#[inline]
fn $func_name(self) -> bool {
self & Self::$const_name > 0
}
};
}
pub trait Mods: Copy {
const NF: u32 = 1 << 0;
const EZ: u32 = 1 << 1;
@@ -6,10 +15,19 @@ pub trait Mods: Copy {
const HR: u32 = 1 << 4;
const DT: u32 = 1 << 6;
const HT: u32 = 1 << 8;
const NC: u32 = Self::DT | (1 << 9);
const FL: u32 = 1 << 10;
const SO: u32 = 1 << 12;
const K1: u32 = 1 << 26;
const K2: u32 = 1 << 27;
const K3: u32 = 1 << 28;
const K4: u32 = 1 << 15;
const K5: u32 = 1 << 16;
const K6: u32 = 1 << 17;
const K7: u32 = 1 << 18;
const K8: u32 = 1 << 19;
const K9: u32 = 1 << 24;
fn change_speed(self) -> bool;
fn change_map(self) -> bool;
fn speed(self) -> f32;
@@ -21,9 +39,18 @@ pub trait Mods: Copy {
fn hr(self) -> bool;
fn dt(self) -> bool;
fn ht(self) -> bool;
fn nc(self) -> bool;
fn fl(self) -> bool;
fn so(self) -> bool;
fn key1(self) -> bool;
fn key2(self) -> bool;
fn key3(self) -> bool;
fn key4(self) -> bool;
fn key5(self) -> bool;
fn key6(self) -> bool;
fn key7(self) -> bool;
fn key8(self) -> bool;
fn key9(self) -> bool;
}
impl Mods for u32 {
@@ -59,53 +86,23 @@ impl Mods for u32 {
}
}
#[inline]
fn nf(self) -> bool {
self & Self::NF > 0
}
impl_mods!(nf, NF);
impl_mods!(ez, EZ);
impl_mods!(td, TD);
impl_mods!(hd, HD);
impl_mods!(hr, HR);
impl_mods!(dt, DT);
impl_mods!(ht, HT);
impl_mods!(fl, FL);
impl_mods!(so, SO);
#[inline]
fn ez(self) -> bool {
self & Self::EZ > 0
}
#[inline]
fn td(self) -> bool {
self & Self::TD > 0
}
#[inline]
fn hd(self) -> bool {
self & Self::HD > 0
}
#[inline]
fn hr(self) -> bool {
self & Self::HR > 0
}
#[inline]
fn dt(self) -> bool {
self & Self::DT > 0
}
#[inline]
fn ht(self) -> bool {
self & Self::HT > 0
}
#[inline]
fn nc(self) -> bool {
self & Self::NC > 0
}
#[inline]
fn fl(self) -> bool {
self & Self::FL > 0
}
#[inline]
fn so(self) -> bool {
self & Self::SO > 0
}
impl_mods!(key1, K1);
impl_mods!(key2, K2);
impl_mods!(key3, K3);
impl_mods!(key4, K4);
impl_mods!(key5, K5);
impl_mods!(key6, K6);
impl_mods!(key7, K7);
impl_mods!(key8, K8);
impl_mods!(key9, K9);
}