diff options
| author | troido <troido@protonmail.com> | 2020-09-22 16:31:26 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-22 16:31:26 +0200 |
| commit | 5cf8cc94bdf84341589fab4d1b941aa104de9a42 (patch) | |
| tree | 0c1ae68e100e1b09a666d21a54904d0ca019cb3d | |
| parent | f2c9425d33f79a3dbfc0c6ac41c8b88b81a1672e (diff) | |
added capes!
| -rw-r--r-- | content/encyclopediae/default_encyclopedia.json | 32 | ||||
| -rw-r--r-- | src/components/equipment.rs | 4 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 5 | ||||
| -rw-r--r-- | src/systems/view.rs | 26 |
4 files changed, 46 insertions, 21 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json index 1317d85..bd1ae9c 100644 --- a/content/encyclopediae/default_encyclopedia.json +++ b/content/encyclopediae/default_encyclopedia.json @@ -145,9 +145,11 @@ "slot": "hand", "stats": {"strength": 3} }]}, - "armour": {"action": ["equip", { - "slot": "body", - "stats": {"defence": 3} + "armour": { + "sprite": "armour", + "action": ["equip", { + "slot": "body", + "stats": {"defence": 3} }]}, "pickaxe": { "sprite": "sword", @@ -155,6 +157,30 @@ "slot": "hand", "stats": {"mining": 5} }] + }, + "redcape": { + "sprite": "armour", + "action": ["equip", { + "slot": "back", + "stats": {}, + "sprite": "redplayer" + }] + }, + "greencape": { + "sprite": "armour", + "action": ["equip", { + "slot": "back", + "stats": {}, + "sprite": "greenplayer" + }] + }, + "bluecape": { + "sprite": "armour", + "action": ["equip", { + "slot": "back", + "stats": {}, + "sprite": "blueplayer" + }] } } } diff --git a/src/components/equipment.rs b/src/components/equipment.rs index e7c9734..0e93902 100644 --- a/src/components/equipment.rs +++ b/src/components/equipment.rs @@ -13,7 +13,8 @@ use crate::{ #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Slot { Hand, - Body + Body, + Back } impl Slot { @@ -21,6 +22,7 @@ impl Slot { match txt { "hand" => Some(Self::Hand), "body" => Some(Self::Body), + "back" => Some(Self::Back), _ => None } } diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index 8b58d75..4927636 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -35,12 +35,12 @@ impl <'a> System<'a> for Use { WriteStorage<'a, Inventory>, Write<'a, NewEntities>, WriteStorage<'a, AttackInbox>, - Read<'a, Ground>, + Write<'a, Ground>, ReadStorage<'a, Flags>, Read<'a, RoomPermissions> ); - fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, ground, flags, roompermissions): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut ground, flags, roompermissions): Self::SystemData) { for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){ if let Control::Use(rank) = &controller.control { if let Some(entry) = inventory.items.get_mut(*rank) { @@ -70,6 +70,7 @@ impl <'a> System<'a> for Use { } inventory.items[*rank].is_equipped = true; } + ground.changes.insert(position.pos); } None => {} } diff --git a/src/systems/view.rs b/src/systems/view.rs index 604878f..8b97149 100644 --- a/src/systems/view.rs +++ b/src/systems/view.rs @@ -38,15 +38,8 @@ impl <'a> System<'a> for View { let changes: Vec<(Pos, Vec<Sprite>)> = ground.changes .iter() - .map(|pos| - ( - *pos, - ground.by_height(pos, &visible).into_iter() - .filter_map(|e| - entity_sprite(e, &visible, &inventories) - ).collect() - ) - ).collect(); + .map(|pos| (*pos, sprites_on(&ground, *pos, &visible, &inventories))) + .collect(); let has_changed: bool = !changes.is_empty(); output.output.clear(); @@ -54,7 +47,7 @@ impl <'a> System<'a> for View { for (ent, player, pos) in (&entities, &players, &positions).join() { let mut updates = WorldMessage::default(); if new.get(ent).is_some() { - let (values, mapping) = draw_room(&ground, (size.width, size.height), &visible); + let (values, mapping) = draw_room(&ground, (size.width, size.height), &visible, &inventories); let field = FieldMessage{ width: size.width, height: size.height, @@ -104,19 +97,22 @@ fn entity_sprite(ent: Entity, visibles: &ReadStorage<Visible>, inventories: &Rea None } -fn cell_sprites(mut visibles: Vec<&Visible>) -> Vec<Sprite> { - visibles.sort_by(|a, b| b.height.partial_cmp(&a.height).unwrap()); - visibles.iter().map(|vis| vis.sprite.clone()).collect() +fn sprites_on(ground: &Read<Ground>, pos: Pos, visibles: &ReadStorage<Visible>, inventories: &ReadStorage<Inventory>) -> Vec<Sprite> { + ground.by_height(&pos, visibles) + .into_iter() + .filter_map(|e| + entity_sprite(e, visibles, inventories) + ).collect() } -fn draw_room(ground: &Read<Ground>, (width, height): (i64, i64), visible: &ReadStorage<Visible>) -> (Vec<usize>, Vec<Vec<Sprite>>){ +fn draw_room(ground: &Read<Ground>, (width, height): (i64, i64), visible: &ReadStorage<Visible>, inventories: &ReadStorage<Inventory>) -> (Vec<usize>, Vec<Vec<Sprite>>){ let size = width * height; let mut values :Vec<usize> = Vec::with_capacity(size as usize); let mut mapping: Vec<Vec<Sprite>> = Vec::new(); for y in 0..height { for x in 0..width { - let sprites: Vec<Sprite> = cell_sprites(ground.components_on(Pos{x, y}, visible)); + let sprites: Vec<Sprite> = sprites_on(ground, Pos{x, y}, visible, inventories);//cell_sprites(ground.components_on(Pos{x, y}, visible)); values.push( match mapping.iter().position(|x| x == &sprites) { Some(index) => { |
