From b7f60302ee864ec67676659295f2a61ae7c6e99e Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 26 Jun 2020 21:16:09 +0200 Subject: [PATCH] Implement freeze --- README.md | 2 -- src/ddr/ssq.rs | 55 ++++++++++++++++++++++++-------------------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index e4f2859..5660bc6 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,6 @@ Batch conversion is possible with the included shell script `batch_convert.sh` * Since *osu!mania* does not support shock arrows, it either ignores them or (by default) replaces them with a two-key combination (↑↓ or ←→); you can change this with the (`--shock-action` option) - * Freezes do not work (I do not know how to get the start time yet) and - therefore are disabled in code (`ddr::ssq::FREEZE`) * Known problems listed for unxwb (for wave banks without entry names having 2 entries, which often are preview and full song, the longest one is used by default). diff --git a/src/ddr/ssq.rs b/src/ddr/ssq.rs index 4d11929..97beda3 100644 --- a/src/ddr/ssq.rs +++ b/src/ddr/ssq.rs @@ -13,7 +13,6 @@ use crate::mini_parser::{MiniParser, MiniParserError}; use crate::utils; const MEASURE_LENGTH: i32 = 4096; -const FREEZE: bool = false; #[derive(Error, Debug)] pub enum Error { @@ -231,6 +230,10 @@ impl Chart { let mut parsed_steps = Vec::new(); + // indices of (normal) steps that start a freeze (they are not needed after processing all + // steps as they are already included in the freezes) + let mut freeze_steps = Vec::new(); + for step in 0..count { let beats = measure_to_beats(measures[step]); @@ -256,32 +259,24 @@ impl Chart { continue; } - if FREEZE { - match Self::find_last(parsed_steps.clone(), &row) { - Some(last_step) => { - parsed_steps.push(Step::Freeze { - start: if let Step::Step { beats, .. } = parsed_steps[last_step] - { - beats - } else { - unreachable!() - }, - end: beats, - row, - }); + match Self::find_last(parsed_steps.clone(), &row) { + Some(last_step) => { + parsed_steps.push(Step::Freeze { + start: if let Step::Step { beats, .. } = parsed_steps[last_step] { + beats + } else { + unreachable!() + }, + end: beats, + row, + }); - parsed_steps.remove(last_step); - } - None => { - warn!( - "Could not find previous step for freeze, adding normal step" - ); - parsed_steps.push(Step::Step { beats, row }); - } + freeze_steps.push(last_step); + } + None => { + warn!("Could not find previous step for freeze, adding normal step"); + parsed_steps.push(Step::Step { beats, row }); } - } else { - trace!("Freeze disabled, adding normal step"); - parsed_steps.push(Step::Step { beats, row }); } } else { debug!( @@ -300,6 +295,12 @@ impl Chart { } } + // remove steps that start a freeze + freeze_steps.dedup(); + for i in freeze_steps.iter().rev() { + parsed_steps.remove(*i); + } + debug!("Parsed {} steps", parsed_steps.len()); Ok(Self { @@ -376,10 +377,6 @@ pub struct SSQ { impl SSQ { pub fn parse(data: &[u8]) -> Result { - debug!( - "Configuration: measure length: {}, use freezes: {}", - MEASURE_LENGTH, FREEZE - ); let mut cursor = Cursor::new(data); let mut ssq = Self {