29 lines
831 B
Rust
29 lines
831 B
Rust
|
use ::specs::prelude::*;
|
||
|
|
||
|
use crate::components::{Equipped, InBackpack, WantsToRemoveItem};
|
||
|
|
||
|
pub struct ItemRemoveSystem {}
|
||
|
|
||
|
impl<'a> System<'a> for ItemRemoveSystem {
|
||
|
#[allow(clippy::type_complexity)]
|
||
|
type SystemData = (
|
||
|
Entities<'a>,
|
||
|
WriteStorage<'a, WantsToRemoveItem>,
|
||
|
WriteStorage<'a, Equipped>,
|
||
|
WriteStorage<'a, InBackpack>,
|
||
|
);
|
||
|
|
||
|
fn run(&mut self, data: Self::SystemData) {
|
||
|
let (entities, mut wants_remove, mut equipped, mut backpack) = data;
|
||
|
|
||
|
for (entity, to_remove) in (&entities, &wants_remove).join() {
|
||
|
equipped.remove(to_remove.item);
|
||
|
backpack
|
||
|
.insert(to_remove.item, InBackpack { owner: entity })
|
||
|
.expect("Unable to remove item and put in backpack");
|
||
|
}
|
||
|
|
||
|
wants_remove.clear();
|
||
|
}
|
||
|
}
|