ignore line on invalid curve points instead of error throw

This commit is contained in:
MaxOhn
2023-01-28 03:24:02 +01:00
parent 17ab4c454e
commit ea51971471
2 changed files with 28 additions and 17 deletions
+3
View File
@@ -3,6 +3,9 @@
- __Additions:__ - __Additions:__
- Added the method `ScoreState::total_hits` - Added the method `ScoreState::total_hits`
- __Fixes:__
- Lines with invalid curve points are now ignored instead of making parsing fail
# v0.9.2 (2022-11-08) # v0.9.2 (2022-11-08)
- __Adjustments:__ - __Adjustments:__
+25 -17
View File
@@ -416,7 +416,7 @@ macro_rules! parse_hitobjects_body {
// Buffer to re-use for all sliders // Buffer to re-use for all sliders
let mut vertices = Vec::new(); let mut vertices = Vec::new();
while next_line!($reader)? != 0 { 'next_line: while next_line!($reader)? != 0 {
if let Some(bytes) = $reader.get_section() { if let Some(bytes) = $reader.get_section() {
*$section = Section::from_bytes(bytes); *$section = Section::from_bytes(bytes);
empty = false; empty = false;
@@ -441,7 +441,7 @@ macro_rules! parse_hitobjects_body {
let pos = if let (Some(x), Some(y)) = (x, y) { let pos = if let (Some(x), Some(y)) = (x, y) {
Pos2 { x, y } Pos2 { x, y }
} else { } else {
continue; continue 'next_line;
}; };
let time_opt = split let time_opt = split
@@ -452,7 +452,7 @@ macro_rules! parse_hitobjects_body {
let time = match time_opt { let time = match time_opt {
Some(time) => time, Some(time) => time,
None => continue, None => continue 'next_line,
}; };
if !$self.hit_objects.is_empty() && time < prev_time { if !$self.hit_objects.is_empty() && time < prev_time {
@@ -461,12 +461,12 @@ macro_rules! parse_hitobjects_body {
let kind: u8 = match split.next().next_field("hitobject kind")?.parse() { let kind: u8 = match split.next().next_field("hitobject kind")?.parse() {
Ok(kind) => kind, Ok(kind) => kind,
Err(_) => continue, Err(_) => continue 'next_line,
}; };
let mut sound: u8 = match split.next().next_field("sound")?.parse() { let mut sound: u8 = match split.next().next_field("sound")?.parse() {
Ok(sound) => sound, Ok(sound) => sound,
Err(_) => continue, Err(_) => continue 'next_line,
}; };
#[derive(Debug)] #[derive(Debug)]
@@ -515,7 +515,7 @@ macro_rules! parse_hitobjects_body {
match has_custom_sound_file(split.next()) { match has_custom_sound_file(split.next()) {
Status::Ok(false) => {} Status::Ok(false) => {}
Status::Ok(true) => sound = 0, Status::Ok(true) => sound = 0,
Status::Skip => continue, Status::Skip => continue 'next_line,
Status::Err(err) => return Err(err), Status::Err(err) => return Err(err),
} }
@@ -534,7 +534,7 @@ macro_rules! parse_hitobjects_body {
// * osu-stable treated the first span of the slider // * osu-stable treated the first span of the slider
// * as a repeat, but no repeats are happening // * as a repeat, but no repeats are happening
Ok(repeats @ 0..=9000) => repeats.saturating_sub(1), Ok(repeats @ 0..=9000) => repeats.saturating_sub(1),
Ok(_) | Err(_) => continue, Ok(_) | Err(_) => continue 'next_line,
}; };
let mut start_idx = 0; let mut start_idx = 0;
@@ -565,28 +565,36 @@ macro_rules! parse_hitobjects_body {
// * The start of the next segment is the index after the type descriptor. // * The start of the next segment is the index after the type descriptor.
let end_point = point_split.get(end_idx + 1).copied(); let end_point = point_split.get(end_idx + 1).copied();
convert_points( let convert_res = convert_points(
&point_split[start_idx..end_idx], &point_split[start_idx..end_idx],
end_point, end_point,
first, first,
pos, pos,
&mut control_points, &mut control_points,
&mut vertices, &mut vertices,
)?; );
if convert_res.is_err() {
continue 'next_line;
}
start_idx = end_idx; start_idx = end_idx;
first = false; first = false;
} }
if end_idx > start_idx { if end_idx > start_idx {
convert_points( let convert_res = convert_points(
&point_split[start_idx..end_idx], &point_split[start_idx..end_idx],
None, None,
first, first,
pos, pos,
&mut control_points, &mut control_points,
&mut vertices, &mut vertices,
)?; );
if convert_res.is_err() {
continue 'next_line;
}
} }
if control_points.is_empty() { if control_points.is_empty() {
@@ -597,7 +605,7 @@ macro_rules! parse_hitobjects_body {
.map(|s| f64::parse_in_custom_range(s, MAX_COORDINATE_VALUE as f64)) .map(|s| f64::parse_in_custom_range(s, MAX_COORDINATE_VALUE as f64))
{ {
Some(Some(len)) => (len > 0.0).then_some(len), Some(Some(len)) => (len > 0.0).then_some(len),
Some(None) => continue, Some(None) => continue 'next_line,
None => None, None => None,
}; };
@@ -616,7 +624,7 @@ macro_rules! parse_hitobjects_body {
match has_custom_sound_file(split.nth(1)) { match has_custom_sound_file(split.nth(1)) {
Status::Ok(false) => {} Status::Ok(false) => {}
Status::Ok(true) => sound = 0, Status::Ok(true) => sound = 0,
Status::Skip => continue, Status::Skip => continue 'next_line,
Status::Err(err) => return Err(err), Status::Err(err) => return Err(err),
} }
@@ -632,13 +640,13 @@ macro_rules! parse_hitobjects_body {
let end_time = match split.next().next_field("spinner endtime")?.parse::<f64>() { let end_time = match split.next().next_field("spinner endtime")?.parse::<f64>() {
Ok(end_time) => end_time.max(time), Ok(end_time) => end_time.max(time),
Err(_) => continue, Err(_) => continue 'next_line,
}; };
match has_custom_sound_file(split.next()) { match has_custom_sound_file(split.next()) {
Status::Ok(false) => {} Status::Ok(false) => {}
Status::Ok(true) => sound = 0, Status::Ok(true) => sound = 0,
Status::Skip => continue, Status::Skip => continue 'next_line,
Status::Err(err) => return Err(err), Status::Err(err) => return Err(err),
} }
@@ -650,13 +658,13 @@ macro_rules! parse_hitobjects_body {
Some((head, tail)) => { Some((head, tail)) => {
let parsed = match f64::parse_in_range(head) { let parsed = match f64::parse_in_range(head) {
Some(time_) => time_.max(time), Some(time_) => time_.max(time),
None => continue, None => continue 'next_line,
}; };
match has_custom_sound_file(Some(tail)) { match has_custom_sound_file(Some(tail)) {
Status::Ok(false) => {} Status::Ok(false) => {}
Status::Ok(true) => sound = 0, Status::Ok(true) => sound = 0,
Status::Skip => continue, Status::Skip => continue 'next_line,
Status::Err(err) => return Err(err), Status::Err(err) => return Err(err),
} }