use crate::entities::query::Query;
use crate::entities::Entities;
use crate::resources::{Resources};
use eyre::Result;
use std::any::Any;
pub mod entities;
pub mod errors;
pub mod resources;
#[derive(Default, Debug)]
pub struct World {
resources: Resources,
entities: Entities,
}
impl World {
pub fn new() -> Self {
Self {
resources: Resources::new(),
entities: Entities::new()
}
}
pub fn add_resource(&mut self, resource: impl Any) {
self.resources.add(resource);
}
pub fn get_resource<T: Any>(&self) -> Option<&T> {
self.resources.get_ref::<T>()
}
pub fn get_resource_mut<T: Any>(&mut self) -> Option<&mut T> {
self.resources.get_mut::<T>()
}
pub fn delete_resource<T: Any>(&mut self) {
self.resources.remove::<T>();
}
pub fn register_component<T: Any>(&mut self) {
self.entities.register_component::<T>();
}
pub fn create_entity(&mut self) -> &mut Entities {
self.entities.create_entity()
}
pub fn query(&self) -> Query {
Query::new(&self.entities)
}
pub fn delete_component_by_entity_id<T: Any>(&mut self, index: usize) -> Result<()> {
self.entities.delete_component_by_entity_id::<T>(index)
}
pub fn add_component_by_entity_id(&mut self, data: impl Any, index: usize) -> Result<()> {
self.entities.add_component_by_entity_id(data, index)
}
pub fn delete_entity_by_id(&mut self, index: usize) -> Result<()> {
self.entities.delete_entity_by_id(index)
}
}
#[cfg(test)]
mod tests {}