summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-05-12 21:51:37 +0200
committertroido <troido@protonmail.com>2020-05-12 21:51:37 +0200
commit1b380b31f50035f10f651e220effe8a2970c0fd5 (patch)
tree5a25b839a4ee70ba96f7f096161ea59c08842492 /src/systems
parent6c5b15758fbceef7987b40ee50a71ddc9624372d (diff)
removed 'substitute' part of encyclopedia
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/mod.rs6
-rw-r--r--src/systems/replace.rs46
-rw-r--r--src/systems/spawntrigger.rs34
3 files changed, 85 insertions, 1 deletions
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index 024f54f..7323dee 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -22,6 +22,8 @@ mod timeout;
mod clear;
mod building;
mod deduplicate;
+mod spawntrigger;
+mod replace;
pub use self::{
controlinput::ControlInput,
@@ -46,5 +48,7 @@ pub use self::{
timeout::Timeout,
clear::Clear,
building::Building,
- deduplicate::Deduplicate
+ deduplicate::Deduplicate,
+ spawntrigger::SpawnTrigger,
+ replace::Replace
};
diff --git a/src/systems/replace.rs b/src/systems/replace.rs
new file mode 100644
index 0000000..4ed516b
--- /dev/null
+++ b/src/systems/replace.rs
@@ -0,0 +1,46 @@
+
+use specs::{
+ ReadStorage,
+ System,
+ Join,
+ Write,
+ WriteStorage,
+ Entities
+};
+
+use crate::{
+ components::{
+ Position,
+ Substitute,
+ Removed,
+ Serialise
+ },
+ resources::{NewEntities}
+};
+
+
+pub struct Replace;
+impl <'a> System<'a> for Replace {
+ type SystemData = (
+ Entities<'a>,
+ ReadStorage<'a, Position>,
+ Write<'a, NewEntities>,
+ ReadStorage<'a, Substitute>,
+ WriteStorage<'a, Removed>,
+ ReadStorage<'a, Serialise>
+ );
+
+ fn run(&mut self, (entities, positions, mut new, substitutes, mut removeds, serialisations): Self::SystemData) {
+ for (entity, position, substitute, serialisation) in (&entities, &positions, &substitutes, (&serialisations).maybe()).join(){
+ // todo: better error handling
+ let mut template = substitute.into.clone();
+ if let Some(serialise) = serialisation {
+ // todo: extraction?
+ template = template.merge(serialise.template.clone());
+ }
+ let preent = new.encyclopedia.construct(&template).unwrap();
+ new.to_build.push((position.pos, preent));
+ removeds.insert(entity, Removed).unwrap();
+ }
+ }
+}
diff --git a/src/systems/spawntrigger.rs b/src/systems/spawntrigger.rs
new file mode 100644
index 0000000..95e95a8
--- /dev/null
+++ b/src/systems/spawntrigger.rs
@@ -0,0 +1,34 @@
+
+
+use specs::{
+ WriteStorage,
+ ReadStorage,
+ Entities,
+ System,
+ Join
+};
+
+use crate::{
+ components::{
+ TriggerBox,
+ OnSpawn,
+ New
+ }
+};
+
+
+pub struct SpawnTrigger;
+impl <'a> System<'a> for SpawnTrigger {
+ type SystemData = (
+ Entities<'a>,
+ WriteStorage<'a, TriggerBox>,
+ ReadStorage<'a, OnSpawn>,
+ ReadStorage<'a, New>
+ );
+
+ fn run(&mut self, (entities, mut triggerboxes, onspawns, news): Self::SystemData) {
+ for (entity, onspawn, _new) in (&entities, &onspawns, &news).join(){
+ TriggerBox::add_message(&mut triggerboxes, entity, onspawn.trigger);
+ }
+ }
+}