use std::{
any::TypeId,
collections::HashMap,
ops::{Add, AddAssign},
};
use crate::components::{AnyComponent, Component};
#[derive(Clone, Copy, Debug, Default, Hash, Eq, PartialEq)]
pub struct Entity(u64);
impl Entity {
#[must_use]
pub fn builder() -> EntityBuilder {
EntityBuilder::new()
}
#[must_use]
pub fn raw(self) -> u64 {
self.0
}
}
impl Add<u64> for Entity {
type Output = Self;
fn add(self, rhs: u64) -> Self::Output {
Self(self.0 + rhs)
}
}
impl AddAssign<u64> for Entity {
fn add_assign(&mut self, rhs: u64) {
self.0 += rhs;
}
}
#[derive(Default)]
pub struct EntityBuilder {
pub(crate) components: HashMap<TypeId, Box<dyn AnyComponent>>,
}
impl EntityBuilder {
#[must_use]
fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_component<C: Component>(mut self, component: C) -> Self {
self.components
.insert(TypeId::of::<C>(), Box::new(component));
self
}
}