Skip to content

Commit

Permalink
chore: Clean up with cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
yngtdd committed Apr 10, 2022
1 parent 1e8db34 commit b8c6e88
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/spawner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
59 changes: 28 additions & 31 deletions src/spawner/template.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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")
}
Expand All @@ -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();

Expand Down Expand Up @@ -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 {});
}
}
}
}

3 changes: 2 additions & 1 deletion src/systems/combat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b8c6e88

Please sign in to comment.