amethyst_core/transform/
bundle.rs

1//! ECS transform bundle
2
3use amethyst_error::Error;
4use specs_hierarchy::HierarchySystem;
5
6use crate::{
7    bundle::SystemBundle,
8    ecs::prelude::{DispatcherBuilder, World},
9    transform::*,
10    SystemDesc,
11};
12
13/// Transform bundle
14///
15/// Will register transform components, and the `TransformSystem`.
16/// `TransformSystem` will be registered with name "transform_system".
17///
18/// ## Errors
19///
20/// No errors will be returned by this bundle.
21///
22/// ## Panics
23///
24/// Panics in `TransformSystem` registration if the bundle is applied twice in the same dispatcher.
25///
26#[derive(Debug, Default)]
27pub struct TransformBundle<'a> {
28    dep: &'a [&'a str],
29}
30
31impl<'a> TransformBundle<'a> {
32    /// Create a new transform bundle
33    pub fn new() -> Self {
34        TransformBundle {
35            dep: Default::default(),
36        }
37    }
38
39    /// Set dependencies for the `TransformSystem`
40    pub fn with_dep(mut self, dep: &'a [&'a str]) -> Self {
41        self.dep = dep;
42        self
43    }
44}
45
46impl<'a, 'b, 'c> SystemBundle<'a, 'b> for TransformBundle<'c> {
47    fn build(
48        self,
49        world: &mut World,
50        builder: &mut DispatcherBuilder<'a, 'b>,
51    ) -> Result<(), Error> {
52        builder.add(
53            HierarchySystem::<Parent>::new(world),
54            "parent_hierarchy_system",
55            self.dep,
56        );
57        builder.add(
58            TransformSystemDesc::default().build(world),
59            "transform_system",
60            &["parent_hierarchy_system"],
61        );
62        Ok(())
63    }
64}