Implement Deref for newtypes
This commit is contained in:
parent
0ea4a20326
commit
19eebdc345
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -51,6 +51,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"byteorder",
|
||||
"clap",
|
||||
"derive_more",
|
||||
"konami-lz77",
|
||||
"log",
|
||||
"num-derive",
|
||||
|
@ -140,6 +141,17 @@ dependencies = [
|
|||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "0.99.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.7.1"
|
||||
|
|
|
@ -8,6 +8,7 @@ edition = "2018"
|
|||
anyhow = "1.0.31"
|
||||
byteorder = "1.3.4"
|
||||
clap = "3.0.0-beta.1"
|
||||
derive_more = "0.99.9"
|
||||
konami-lz77 = { git = "https://github.com/sbruder/konami-lz77" }
|
||||
log = "0.4.8"
|
||||
num-derive = "0.3"
|
||||
|
|
|
@ -144,8 +144,8 @@ impl ShockStepGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_time_from_beats(beats: f32, tempo_changes: &[ssq::TempoChange]) -> Option<beatmap::Time> {
|
||||
for tempo_change in tempo_changes {
|
||||
fn get_time_from_beats(beats: f32, tempo_changes: &ssq::TempoChanges) -> Option<beatmap::Time> {
|
||||
for tempo_change in tempo_changes.to_vec() {
|
||||
// For TempoChanges that are infinitely short but exactly cover that beat, use the start
|
||||
// time of that TempoChange
|
||||
if (beats - tempo_change.start_beats).abs() < 0.001
|
||||
|
@ -198,7 +198,7 @@ impl ssq::Step {
|
|||
|
||||
match self {
|
||||
ssq::Step::Step { beats, row } => {
|
||||
let time = get_time_from_beats(*beats, &tempo_changes.0);
|
||||
let time = get_time_from_beats(*beats, tempo_changes);
|
||||
|
||||
match time {
|
||||
Some(time) => {
|
||||
|
@ -236,8 +236,8 @@ impl ssq::Step {
|
|||
}
|
||||
}
|
||||
ssq::Step::Freeze { start, end, row } => {
|
||||
let time = get_time_from_beats(*start, &tempo_changes.0);
|
||||
let end_time = get_time_from_beats(*end, &tempo_changes.0);
|
||||
let time = get_time_from_beats(*start, tempo_changes);
|
||||
let end_time = get_time_from_beats(*end, tempo_changes);
|
||||
|
||||
match (time, end_time) {
|
||||
(Some(time), Some(end_time)) => {
|
||||
|
@ -290,7 +290,7 @@ impl ssq::Step {
|
|||
hit_objects.push(beatmap::HitObject::HitCircle {
|
||||
x: beatmap::column_to_x(column as u8, num_columns),
|
||||
y: 192,
|
||||
time: get_time_from_beats(*beats, &tempo_changes.0)?,
|
||||
time: get_time_from_beats(*beats, tempo_changes)?,
|
||||
hit_sound: beatmap::HitSound {
|
||||
normal: true,
|
||||
whistle: false,
|
||||
|
@ -378,18 +378,17 @@ impl ssq::SSQ {
|
|||
pub fn to_beatmaps(&self, config: &Config) -> Result<Vec<beatmap::Beatmap>> {
|
||||
debug!("Configuration: {:?}", config);
|
||||
|
||||
let mut timing_points = Vec::new();
|
||||
let mut timing_points = beatmap::TimingPoints(Vec::new());
|
||||
|
||||
for entry in &self.tempo_changes.0 {
|
||||
for entry in self.tempo_changes.to_vec() {
|
||||
if config.stops || entry.beat_length != f32::INFINITY {
|
||||
trace!("Converting {:?} to to timing point", entry);
|
||||
let timing_point: beatmap::TimingPoint = entry.clone().into();
|
||||
timing_points.push(timing_point);
|
||||
timing_points.push(entry.into());
|
||||
}
|
||||
}
|
||||
debug!(
|
||||
"Converted {} tempo changes to timing points",
|
||||
self.tempo_changes.0.len()
|
||||
self.tempo_changes.len()
|
||||
);
|
||||
|
||||
let mut converted_charts = Vec::new();
|
||||
|
@ -407,19 +406,19 @@ impl ssq::SSQ {
|
|||
&self.tempo_changes,
|
||||
&mut shock_step_generator,
|
||||
) {
|
||||
hit_objects.0.append(&mut step_hit_objects);
|
||||
hit_objects.append(&mut step_hit_objects);
|
||||
}
|
||||
}
|
||||
|
||||
let converted_chart = ConvertedChart {
|
||||
difficulty: chart.difficulty.clone(),
|
||||
hit_objects,
|
||||
timing_points: beatmap::TimingPoints(timing_points.clone()),
|
||||
timing_points: timing_points.clone(),
|
||||
};
|
||||
|
||||
debug!(
|
||||
"Converted to beatmap with {} hit objects",
|
||||
converted_chart.hit_objects.0.len(),
|
||||
converted_chart.hit_objects.len(),
|
||||
);
|
||||
|
||||
converted_charts.push(converted_chart);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::ops::Deref;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use derive_more::Deref;
|
||||
use quick_xml::de::{from_str, DeError};
|
||||
use serde::de;
|
||||
use serde::Deserialize;
|
||||
|
@ -24,7 +24,7 @@ pub enum Error {
|
|||
/// Type that implements [`serde::de::Deserialize`] for space separated lists in xml tag bodies.
|
||||
///
|
||||
/// [`serde::de::Deserialize`]: ../../../serde/de/trait.Deserialize.html
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Deref)]
|
||||
pub struct XMLList<T>(Vec<T>);
|
||||
|
||||
impl<'de, T> serde::de::Deserialize<'de> for XMLList<T>
|
||||
|
@ -45,14 +45,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for XMLList<T> {
|
||||
type Target = Vec<T>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// This currently only includes fields present in every entry.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Entry {
|
||||
|
|
|
@ -7,6 +7,7 @@ use std::io::Cursor;
|
|||
use std::num;
|
||||
|
||||
use byteorder::{ReadBytesExt, LE};
|
||||
use derive_more::Deref;
|
||||
use log::{debug, info, trace, warn};
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -159,7 +160,7 @@ pub struct TempoChange {
|
|||
pub beat_length: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, Deref, PartialEq)]
|
||||
pub struct TempoChanges(pub Vec<TempoChange>);
|
||||
|
||||
impl TempoChanges {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use std::fmt;
|
||||
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use num_derive::ToPrimitive;
|
||||
use num_traits::ToPrimitive;
|
||||
use std::fmt;
|
||||
|
||||
use crate::utils;
|
||||
|
||||
|
@ -165,7 +167,7 @@ impl fmt::Display for Difficulty {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Deref)]
|
||||
pub struct Events(pub Vec<Event>);
|
||||
|
||||
impl fmt::Display for Events {
|
||||
|
@ -176,7 +178,7 @@ impl fmt::Display for Events {
|
|||
[Events]\n\
|
||||
{}\n\
|
||||
",
|
||||
utils::join_display_values(self.0.clone(), "\n")
|
||||
utils::join_display_values(self.to_vec(), "\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +228,7 @@ impl fmt::Display for Event {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Deref, DerefMut)]
|
||||
pub struct TimingPoints(pub Vec<TimingPoint>);
|
||||
|
||||
impl fmt::Display for TimingPoints {
|
||||
|
@ -237,7 +239,7 @@ impl fmt::Display for TimingPoints {
|
|||
[TimingPoints]\n\
|
||||
{}\n\
|
||||
",
|
||||
utils::join_display_values(self.0.clone(), "\n")
|
||||
utils::join_display_values(self.to_vec(), "\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -296,7 +298,7 @@ impl fmt::Display for TimingPoint {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Deref)]
|
||||
pub struct Colours(pub Vec<Colour>);
|
||||
|
||||
impl fmt::Display for Colours {
|
||||
|
@ -307,7 +309,7 @@ impl fmt::Display for Colours {
|
|||
[Colours]\n\
|
||||
{}\n\
|
||||
",
|
||||
utils::join_display_values(self.0.clone(), "\n")
|
||||
utils::join_display_values(self.to_vec(), "\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +544,7 @@ impl fmt::Display for HitObject {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Deref, DerefMut)]
|
||||
pub struct HitObjects(pub Vec<HitObject>);
|
||||
|
||||
impl fmt::Display for HitObjects {
|
||||
|
@ -553,7 +555,7 @@ impl fmt::Display for HitObjects {
|
|||
[HitObjects]\n\
|
||||
{}\n\
|
||||
",
|
||||
utils::join_display_values(self.0.clone(), "\n")
|
||||
utils::join_display_values(self.to_vec(), "\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue