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
38
39
40
41
42
43
44
45
46
use crate::{
    engine::Engine,
    ecs::{ SceneManager, SceneHandle, Component, ComponentStorage }, 
};

use anyhow::{Result, Error};


pill_core::define_new_pill_slotmap_key! { 
    pub struct EntityHandle;
}

// --- Builder ---

pub struct EntityBuilder<'a> {
    pub engine: &'a mut Engine,
    pub entity_handle: EntityHandle,
    pub scene_handle: SceneHandle
}

impl<'a> EntityBuilder<'a> {
    pub fn with_component<T: Component<Storage = ComponentStorage::<T>>>(self, component: T) -> Self {
        self.engine.add_component_to_entity(self.scene_handle.clone(), self.entity_handle.clone(), component).unwrap();
        self
    }

    pub fn build(self) -> EntityHandle {
        self.entity_handle
    }
}  

// --- Entity ---

pub struct Entity {
    pub(crate) bitmask: u16,
    pub(crate) scene_handle: SceneHandle
}

impl Entity {
    pub fn new(scene_handle: SceneHandle) -> Self {
        Self {
            bitmask: 0b0000_0000_0000_0000,
            scene_handle,
        }
    }
}