diff options
| author | troido <troido@protonmail.com> | 2020-01-27 23:01:26 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-01-27 23:01:26 +0100 |
| commit | fde8695bbca220e5af85344a7da23bea0f6513b6 (patch) | |
| tree | 3d971adb4111eed756bcd2d4e30a8919f4df093d /src/room.rs | |
| parent | 599d7dc27df5e5ba37ef622d520399d7ca331425 (diff) | |
cleanup!
Diffstat (limited to 'src/room.rs')
| -rw-r--r-- | src/room.rs | 79 |
1 files changed, 14 insertions, 65 deletions
diff --git a/src/room.rs b/src/room.rs index 4c1b291..b9614e3 100644 --- a/src/room.rs +++ b/src/room.rs @@ -1,7 +1,5 @@ use std::collections::HashMap; -// use std::collections::HashSet; -// use std::ops::Deref; use specs::{ VecStorage, @@ -17,7 +15,8 @@ use specs::{ Write }; -struct EntityId(usize); + +// Components #[derive(Component, Debug, Hash, PartialEq, Eq, Clone, Copy)] #[storage(VecStorage)] @@ -37,6 +36,17 @@ struct Visible { struct Size (i32, i32); +// Resources + +#[derive(Default)] +struct TopView { + width: i32, + height: i32, + cells: HashMap<Position, Vec<String>> +} + +// Systems + struct Draw; impl <'a> System<'a> for Draw { @@ -53,13 +63,8 @@ impl <'a> System<'a> for Draw { } } -#[derive(Default)] -struct TopView { - width: i32, - height: i32, - cells: HashMap<Position, Vec<String>> -} +// Higher level stuff pub struct Room<'a, 'b> { world: World, @@ -92,13 +97,11 @@ impl <'a, 'b>Room<'a, 'b> { let tv = &*self.world.fetch::<TopView>(); let width = tv.width; let height = tv.height; -// let TopView{width: width, height: height, cells: cells} = ; let size = width * height; let mut values :Vec<usize> = Vec::with_capacity(size as usize); let mut mapping: Vec<Vec<String>> = Vec::with_capacity(size as usize); for y in 0..height { for x in 0..width { -// values.push(mapping.len()); let sprites = match tv.cells.get(&Position{x: x, y: y}) { Some(sprites) => {sprites.to_vec()} None => {vec![]} @@ -143,57 +146,3 @@ fn gen_world(world: &mut World){ } } -// pub fn make_room<'a, 'b>(size: (i32, i32)) -> (World, Dispatcher<'a, 'b>){ -// let (width, height) = size; -// let mut world = World::new(); -// world.register::<Position>(); -// world.register::<Visible>(); -// world.insert(Size(width, height)); -// world.insert(TopView{width: width, height: height, cells: HashMap::new()}); -// -// -// -// let mut dispatcher = DispatcherBuilder::new() -// .with(Draw, "draw", &[]) -// .build(); -// -// -// gen_world(&mut world); -// -// (world, dispatcher) -// } - -// pub fn view_room(world :&World) -> (Vec<usize>, Vec<Vec<String>>) { -// let TopView{width: width, height: height, cells: cells} = *world.fetch::<TopView>(); -// let size = width * height; -// let mut values :Vec<usize> = Vec::with_capacity(size as usize); -// let mut mapping = Vec::with_capacity(size as usize); -// for y in 0..height { -// for x in 0..width { -// values.push(mapping.len()); -// mapping.push(match cells.get(Position{x: x, y: y}) { -// Some(sprites) => {sprites} -// None => {vec![]} -// }); -// } -// } -// return (values, mapping) -// -// } - -// struct Room { -// entities: Entities, -// width: u32, -// height: u32, -// ground: HashMap<(u32, u32), GroundTile> -// } -// -// struct Entities { -// components: HashMap<EntityId, Box<Component>>, -// systems: HashMap<EntityId, Box<System>> -// } -// -// -// struct GroundTile { -// entities: HashSet<EntityId> -// } |
