summaryrefslogtreecommitdiff
path: root/src/systems/create.rs
blob: c995bcb2c972ee47acaf8143790ff65ef916061f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

use specs::{
	Read,
	Write,
	WriteStorage,
	System,
	Entities,
	LazyUpdate,
	Builder
};

use crate::components::{New, Position};
use crate::resources::{NewEntities};



pub struct Create;
impl <'a> System<'a> for Create {
	type SystemData = (
		Entities<'a>,
		Write<'a, NewEntities>,
		Read<'a, LazyUpdate>,
		WriteStorage<'a, New>
	);
	
	fn run(&mut self, (entities, mut new_entities, updater, mut new): Self::SystemData) {
		new.clear();
		for (pos, preentity) in &new_entities.to_build {
			let mut builder = updater.create_entity(&entities);
			for comp in preentity {
				builder = comp.build(builder);
			}
			builder.with(Position::new(*pos)).with(New).build();
		}
		new_entities.to_build.clear();
	}
}