From b8c6e8848224c22b51ce9f69fcb8857483348c2d Mon Sep 17 00:00:00 2001 From: yngtdd Date: Sun, 10 Apr 2022 13:15:27 -0400 Subject: [PATCH] chore: Clean up with cargo fmt --- src/main.rs | 7 ++++- src/spawner/mod.rs | 2 +- src/spawner/template.rs | 59 +++++++++++++++++++---------------------- src/systems/combat.rs | 3 ++- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/main.rs b/src/main.rs index f3a9731..109ea24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,7 +177,12 @@ impl State { map_builder.map.tiles[exit_idx] = TileType::Exit; } - spawn_level(&mut self.ecs, &mut rng, map_level as usize, &map_builder.monster_spawns); + spawn_level( + &mut self.ecs, + &mut rng, + map_level as usize, + &map_builder.monster_spawns, + ); self.resources.insert(map_builder.map); self.resources.insert(Camera::new(map_builder.player_start)); diff --git a/src/spawner/mod.rs b/src/spawner/mod.rs index 6c3fb09..a325f83 100644 --- a/src/spawner/mod.rs +++ b/src/spawner/mod.rs @@ -37,7 +37,7 @@ pub fn spawn_level( ecs: &mut World, rng: &mut RandomNumberGenerator, level: usize, - spawn_points: &[Point] + spawn_points: &[Point], ) { let template = Templates::load(); template.spawn_entities(ecs, rng, level, spawn_points); diff --git a/src/spawner/template.rs b/src/spawner/template.rs index 0b02e0d..b118c01 100644 --- a/src/spawner/template.rs +++ b/src/spawner/template.rs @@ -1,9 +1,9 @@ use crate::prelude::*; -use std::fs::File; -use std::collections::HashSet; -use serde::Deserialize; -use ron::de::from_reader; use legion::systems::CommandBuffer; +use ron::de::from_reader; +use serde::Deserialize; +use std::collections::HashSet; +use std::fs::File; #[derive(Clone, Deserialize, Debug)] pub struct Template { @@ -30,8 +30,7 @@ pub struct Templates { impl Templates { pub fn load() -> Self { - let file = File::open("resources/template.ron") - .expect("Failed opening template.ron"); + let file = File::open("resources/template.ron").expect("Failed opening template.ron"); from_reader(file).expect("Unable to load templates") } @@ -41,7 +40,7 @@ impl Templates { ecs: &mut World, rng: &mut RandomNumberGenerator, level: usize, - spawn_points: &[Point] + spawn_points: &[Point], ) { let mut available_entities = Vec::new(); @@ -69,51 +68,49 @@ impl Templates { &self, pt: &Point, template: &Template, - commands: &mut legion::systems::CommandBuffer + commands: &mut legion::systems::CommandBuffer, ) { let entity = commands.push(( pt.clone(), - Render{ + Render { color: ColorPair::new(WHITE, BLACK), - glyph: to_cp437(template.glyph) + glyph: to_cp437(template.glyph), }, - Name(template.name.clone()) + Name(template.name.clone()), )); match template.entity_type { - EntityType::Item => commands.add_component(entity, Item{}), + EntityType::Item => commands.add_component(entity, Item {}), EntityType::Enemy => { - commands.add_component(entity, Enemy{}); + commands.add_component(entity, Enemy {}); commands.add_component(entity, FieldOfView::new(6)); - commands.add_component(entity, ChasingPlayer{}); - commands.add_component(entity, Health{ - current: template.hp.unwrap(), - max: template.hp.unwrap() - }); + commands.add_component(entity, ChasingPlayer {}); + commands.add_component( + entity, + Health { + current: template.hp.unwrap(), + max: template.hp.unwrap(), + }, + ); } } if let Some(effects) = &template.provides { - effects.iter().for_each(|(provides, n)| { - match provides.as_str() { - "Healing" => { - commands.add_component(entity, ProvidesHealing{amount: *n}) - }, - "MagicMap" => { - commands.add_component(entity, ProvidesDungeonMap{}) - } - _ => println!("Warning, we don't know how to provide {}", provides) - } - }); + effects + .iter() + .for_each(|(provides, n)| match provides.as_str() { + "Healing" => commands.add_component(entity, ProvidesHealing { amount: *n }), + "MagicMap" => commands.add_component(entity, ProvidesDungeonMap {}), + _ => println!("Warning, we don't know how to provide {}", provides), + }); } if let Some(damage) = &template.base_damage { commands.add_component(entity, Damage(*damage)); if template.entity_type == EntityType::Item { - commands.add_component(entity, Weapon{}); + commands.add_component(entity, Weapon {}); } } } } - diff --git a/src/systems/combat.rs b/src/systems/combat.rs index 7b5931b..c45557b 100644 --- a/src/systems/combat.rs +++ b/src/systems/combat.rs @@ -31,7 +31,8 @@ pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 0 }; - let weapon_damage: i32 = <(&Carried, &Damage)>::query().iter(ecs) + let weapon_damage: i32 = <(&Carried, &Damage)>::query() + .iter(ecs) .filter(|(carried, _)| carried.0 == *attacker) .map(|(_, dmg)| dmg.0) .sum();