From 47d134612f1df9af1f130c34f28a1bf15565429f Mon Sep 17 00:00:00 2001 From: shonya3 Date: Thu, 27 Jun 2024 19:30:46 +0300 Subject: [PATCH] feat: remove hard rule for sample to have Rain of Chaos card --- divi/src/error.rs | 4 ---- divi/src/sample.rs | 26 +++++++------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/divi/src/error.rs b/divi/src/error.rs index 5470a42a..65e196c5 100644 --- a/divi/src/error.rs +++ b/divi/src/error.rs @@ -15,7 +15,6 @@ pub enum Error { ParseIntError(ParseIntError), CsvError(CsvError), NinjaError(NinjaError), - SampleMustHaveRainOfChaos, } impl Display for Error { @@ -30,9 +29,6 @@ impl Display for Error { Error::ParseIntError(err) => err.fmt(f), Error::CsvError(err) => err.fmt(f), Error::NinjaError(err) => err.fmt(f), - Error::SampleMustHaveRainOfChaos => { - f.write_str("Sample must have rain of chaos cards.") - } } } } diff --git a/divi/src/sample.rs b/divi/src/sample.rs index a23bd03c..7d3cfdea 100644 --- a/divi/src/sample.rs +++ b/divi/src/sample.rs @@ -85,7 +85,7 @@ impl Sample { }; } - sample.write_weight()?; + sample.write_weight(); Ok(sample) } @@ -119,7 +119,7 @@ impl Sample { card.set_amount(amount); } - merged.write_weight()?; + merged.write_weight(); Ok(merged) } @@ -132,22 +132,16 @@ impl Sample { } /// (After parsing) Calculates special weight for each card and mutates it. Runs at the end of parsing. - fn write_weight(&mut self) -> Result<(), Error> { - let rain_of_chaos_amount = self - .cards - .get("Rain of Chaos") - .ok_or(Error::SampleMustHaveRainOfChaos)? - .amount; - if rain_of_chaos_amount == 0 { - return Err(Error::SampleMustHaveRainOfChaos); - } + fn write_weight(&mut self) { + let Some(rain_of_chaos_amount) = self.cards.get("Rain of Chaos").map(|card| card.amount) + else { + return; + }; let weight_multiplier = RAIN_OF_CHAOS_CONDENSED_WEIGHT / rain_of_chaos_amount as f32; self.cards.iter_mut().for_each(|card| { card.weight = Some((weight_multiplier * card.amount as f32).powf(1.0 / CONDENSING_FACTOR)); }); - - Ok(()) } #[must_use] @@ -487,10 +481,4 @@ Encroaching Darkness,5\r\nThe Endless Darkness,1\r\nThe Endurance,19\r\nThe Enfo assert_eq!(rain_of_chaos.amount, 1779); } - - #[test] - fn must_have_rain_of_chaos() { - let result = Sample::create(Input::Csv("name,amount\nThe Doctor,1".to_owned()), None); - assert!(result.is_err()); - } }