diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 7c7bc59..294658a 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -302,7 +302,7 @@ impl ItemShops { ItemShops { weapon_shop: weapon_shop, - tool_shop: ToolShop::new(), + tool_shop: ToolShop::default(), armor_shop: ArmorShop::default(), } } diff --git a/src/ship/shops/tool.rs b/src/ship/shops/tool.rs index 7eecd3d..66313b5 100644 --- a/src/ship/shops/tool.rs +++ b/src/ship/shops/tool.rs @@ -53,7 +53,7 @@ impl ShopItem for ToolShopItem { fn price(&self) -> usize { match self { ToolShopItem::Tool(tool) => { - TOOL_STATS.get(&tool) + TOOL_STATS.get(tool) .map(|tool_stats| { tool_stats.price }) @@ -146,7 +146,7 @@ fn load_tool_table() -> ToolTable { let mut table: HashMap> = toml::from_str(s.as_str()).unwrap(); - ToolTable(table.remove("tools".into()).unwrap()) + ToolTable(table.remove("tools").unwrap()) } fn load_tech_table() -> TechTable { @@ -156,7 +156,7 @@ fn load_tech_table() -> TechTable { f.read_to_string(&mut s).unwrap(); let mut table: HashMap> = toml::from_str(s.as_str()).unwrap(); - let techniques = table.remove("techniques".into()).unwrap(); + let techniques = table.remove("techniques").unwrap(); let techniques = techniques.into_iter() .map(|tech_tier| { TechTier { @@ -194,15 +194,18 @@ pub struct ToolShop { rng: R, } -impl ToolShop { - pub fn new() -> ToolShop { + +impl Default for ToolShop { + fn default() -> ToolShop { ToolShop { tools: load_tool_table(), techs: load_tech_table(), rng: R::from_entropy(), } } +} +impl ToolShop { fn generate_tech_types(&mut self, character_level: usize) -> Vec { let tier = self.techs.0.iter() .filter(|t| t.level <= character_level) @@ -233,7 +236,7 @@ impl ToolShop { let tech_choice = WeightedIndex::new(tier.iter().map(|(_, e)| e.probability)).unwrap(); while techs.len() < number_of_techs { let tech_detail = tier.get(tech_choice.sample(&mut self.rng)).unwrap(); - if techs.iter().find(|t| *t == tech_detail.0).is_none() { + if !techs.iter().any(|t| t == tech_detail.0) { techs.push(*tech_detail.0); } } @@ -269,7 +272,7 @@ impl ToolShop { pub fn generate_tool_list(&mut self, character_level: usize) -> Vec { let mut tools = Vec::new().into_iter() - .chain(self.tools.0.clone().into_iter().map(|t| ToolShopItem::Tool(t))) + .chain(self.tools.0.clone().into_iter().map(ToolShopItem::Tool)) .chain(self.generate_techs(character_level).into_iter()) .collect::>(); tools.sort(); @@ -284,12 +287,12 @@ mod test { #[test] fn test_loading_tool_shop() { - ToolShop::::new(); + ToolShop::::default(); } #[test] fn test_generating_some_tools() { - let mut ts = ToolShop::::new(); + let mut ts = ToolShop::::default(); for i in 0..200 { ts.generate_tool_list(i); }