summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/controlinput.rs2
-rw-r--r--src/systems/mod.rs2
-rw-r--r--src/systems/take.rs65
3 files changed, 66 insertions, 3 deletions
diff --git a/src/systems/controlinput.rs b/src/systems/controlinput.rs
index 0771b1e..608de06 100644
--- a/src/systems/controlinput.rs
+++ b/src/systems/controlinput.rs
@@ -18,8 +18,6 @@ use crate::hashmap;
use crate::template::Template;
use crate::parameter::Parameter;
-// use crate::assemblages::Player;
-
pub struct ControlInput;
impl <'a> System<'a> for ControlInput {
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index 904e833..6989e95 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -5,5 +5,5 @@ pub mod moving;
pub mod view;
pub mod remove;
pub mod create;
-
+pub mod take;
diff --git a/src/systems/take.rs b/src/systems/take.rs
new file mode 100644
index 0000000..95bec1b
--- /dev/null
+++ b/src/systems/take.rs
@@ -0,0 +1,65 @@
+
+use std::collections::HashSet;
+
+use specs::{
+ Entities,
+ ReadStorage,
+ WriteStorage,
+ System,
+ Join,
+ Write
+};
+
+use super::super::pos::Pos;
+
+use super::super::components::{
+ Controller,
+ Position,
+ Removed,
+ Inventory,
+ Item
+};
+
+use super::super::controls::{Control};
+use super::super::resources::{Ground, NewEntities};
+
+
+
+pub struct Take;
+impl <'a> System<'a> for Take {
+ type SystemData = (
+ Entities<'a>,
+ ReadStorage<'a, Controller>,
+ WriteStorage<'a, Position>,
+ Write<'a, Ground>,
+ WriteStorage<'a, Removed>,
+ ReadStorage<'a, Item>,
+ WriteStorage<'a, Inventory>,
+ Write<'a, NewEntities>
+ );
+
+ fn run(&mut self, (entities, controllers, positions, ground, mut removed, items, mut inventories, mut new): Self::SystemData) {
+ for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){
+ match &controller.0 {
+ Control::Take(_rank) => {
+ let mut ents = ground.cells.get(&position.pos).unwrap_or(&HashSet::new()).clone();
+ ents.remove(&ent);
+ for ent in ents {
+ if let Some(item) = items.get(ent) {
+ inventory.items.push(item.clone());
+ if let Err(msg) = removed.insert(ent, Removed) {
+ println!("{:?}", msg);
+ }
+ }
+ }
+ }
+ Control::Drop(_rank) => {
+ if let Some(item) = inventory.items.pop() {
+ new.templates.push((position.pos, item.ent));
+ }
+ }
+ _ => {}
+ }
+ }
+ }
+}