summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-02 16:07:32 +0200
committertroido <troido@protonmail.com>2020-04-02 16:07:32 +0200
commitb597d2279db7beb0d619fac472481b7f707609c8 (patch)
tree3d45ea9f45a8897a3aec5c30b16bb0db12b162b2 /src/systems
parent1e8fe74740fc4fb11b660415b2db182c6a63a3c2 (diff)
built doors
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/attacking.rs2
-rw-r--r--src/systems/droploot.rs2
-rw-r--r--src/systems/interact.rs25
-rw-r--r--src/systems/take.rs2
-rw-r--r--src/systems/useitem.rs2
5 files changed, 21 insertions, 12 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs
index 4318695..e4001c9 100644
--- a/src/systems/attacking.rs
+++ b/src/systems/attacking.rs
@@ -64,7 +64,7 @@ impl <'a> System<'a> for Attacking {
}
if let Some(position) = positions.get(ent){
if wounded {
- new.create(position.pos, Template::empty("wound")).unwrap();
+ new.create(position.pos, &Template::empty("wound")).unwrap();
}
}
}
diff --git a/src/systems/droploot.rs b/src/systems/droploot.rs
index 1b8f824..5eff7f7 100644
--- a/src/systems/droploot.rs
+++ b/src/systems/droploot.rs
@@ -32,7 +32,7 @@ impl <'a> System<'a> for DropLoot{
for (template, chance) in &loot.loot {
if *chance > rand::thread_rng().gen_range(0.0, 1.0) {
// todo: better error handling
- new.create(position.pos, template.clone()).unwrap();
+ new.create(position.pos, &template).unwrap();
}
}
}
diff --git a/src/systems/interact.rs b/src/systems/interact.rs
index 4c0245d..e3b8358 100644
--- a/src/systems/interact.rs
+++ b/src/systems/interact.rs
@@ -6,7 +6,8 @@ use specs::{
WriteStorage,
System,
Join,
- Read
+ Read,
+ Write
};
use crate::components::{
@@ -14,11 +15,12 @@ use crate::components::{
Position,
ControlCooldown,
Interactable,
- Dead
+ Dead,
+ Removed
};
use crate::controls::{Control};
-use crate::resources::{Ground};
+use crate::resources::{Ground, NewEntities};
@@ -31,18 +33,21 @@ impl <'a> System<'a> for Interact {
Read<'a, Ground>,
WriteStorage<'a, ControlCooldown>,
ReadStorage<'a, Interactable>,
- WriteStorage<'a, Dead>
+ WriteStorage<'a, Dead>,
+ WriteStorage<'a, Removed>,
+ Write<'a, NewEntities>
);
- fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut deads): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut deads, mut removeds, mut new): Self::SystemData) {
for (entity, controller, position) in (&entities, &controllers, &positions).join(){
let mut target = None;
match &controller.control {
Control::Interact(directions) => {
'targets: for direction in directions {
- for ent in ground.cells.get(&(position.pos + direction.to_position())).unwrap_or(&HashSet::new()) {
+ let pos = position.pos + direction.to_position();
+ for ent in ground.cells.get(&pos).unwrap_or(&HashSet::new()) {
if let Some(interactable) = interactables.get(*ent) {
- target = Some((*ent, interactable));
+ target = Some((*ent, interactable, pos));
break 'targets;
}
}
@@ -50,11 +55,15 @@ impl <'a> System<'a> for Interact {
}
_ => {}
}
- if let Some((ent, interactable)) = target {
+ if let Some((ent, interactable, pos)) = target {
match interactable {
Interactable::Harvest => {
deads.insert(ent, Dead).unwrap();
}
+ Interactable::Change(into) => {
+ new.create(pos, into).unwrap();
+ removeds.insert(ent, Removed).unwrap();
+ }
}
cooldowns.insert(entity, ControlCooldown{amount: 2}).unwrap();
}
diff --git a/src/systems/take.rs b/src/systems/take.rs
index 0652fdb..9eb76e7 100644
--- a/src/systems/take.rs
+++ b/src/systems/take.rs
@@ -63,7 +63,7 @@ impl <'a> System<'a> for Take {
return
}
let (item, _is_equipped) = inventory.items.remove(*rank);
- let _ = new.create(position.pos, item.ent);
+ let _ = new.create(position.pos, &item.ent);
}
_ => {}
}
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs
index d96f6ef..8763843 100644
--- a/src/systems/useitem.rs
+++ b/src/systems/useitem.rs
@@ -48,7 +48,7 @@ impl <'a> System<'a> for Use {
Build(template, required_flags, blocking_flags) => {
let ground_flags = ground.flags_on(position.pos, &flags);
if required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){
- new.create(position.pos, template.clone()).unwrap();
+ new.create(position.pos, &template).unwrap();
inventory.items.remove(*rank);
}
}