use std::{marker::PhantomData, ops::Deref, ops::DerefMut};
use uuid::Uuid;
pub struct BlockId;
pub type SysResult<T = ()> = anyhow::Result<T>;
pub trait Component: Send + Sync + 'static {}
impl<T> Component for T where T: Send + Sync + 'static {}
#[derive(Debug, thiserror::Error)]
pub enum ComponentError {
#[error("entity has been despawned")]
EntityDead,
#[error("entity does not have a component of type '{0}0")]
MissingComponent(&'static str),
}
pub struct ComponentRef<T> {
_todo: PhantomData<T>,
_not_send_sync: PhantomData<*mut ()>,
}
impl<T> Deref for ComponentRef<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
todo!()
}
}
pub struct ComponentRefMut<T> {
_todo: PhantomData<T>,
_not_send_sync: PhantomData<*mut ()>,
}
impl<T> Deref for ComponentRefMut<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
todo!()
}
}
impl<T> DerefMut for ComponentRefMut<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
todo!()
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct EntityRef {
_not_send_sync: PhantomData<*mut ()>,
}
impl EntityRef {
pub fn get<T: Component>(self) -> Result<ComponentRef<T>, ComponentError> {
todo!()
}
pub fn get_mut<T: Component>(self) -> Result<ComponentRefMut<T>, ComponentError> {
todo!()
}
pub fn add<T: Component>(self, _component: T) -> Result<(), EntityDead> {
todo!()
}
pub fn send_message(self, _message: &str) -> Result<(), ComponentError> {
todo!()
}
pub fn id(self) -> EntityId {
todo!()
}
pub fn position(self) -> Result<Position, ComponentError> {
todo!()
}
pub fn name(self) -> Result<Name, ComponentError> {
todo!()
}
pub fn uuid(self) -> Result<Uuid, ComponentError> {
todo!()
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct EntityId(u32);
#[derive(Copy, Clone, Debug)]
pub struct Position {
pub x: f64,
pub y: f64,
pub z: f64,
pub pitch: f32,
pub yaw: f32,
pub on_ground: bool,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct BlockPosition {
pub x: i32,
pub y: i32,
pub z: i32,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Name(pub String);
#[derive(Debug, thiserror::Error)]
#[error("entity has been despawned")]
pub struct EntityDead;
#[derive(Debug, thiserror::Error)]
#[error("block chunk is unloaded")]
pub struct ChunkNotLoaded;
#[derive(Debug, thiserror::Error)]
#[error("missing resource of type '{0}'")]
pub struct MissingResource(&'static str);
pub trait Resource: Send + Sync + 'static {}
impl<T> Resource for T where T: Send + Sync + 'static {}
#[derive(Debug)]
pub struct State;
impl State {
pub fn entity(&self, _id: EntityId) -> Result<EntityRef, EntityDead> {
todo!()
}
pub fn block(&self, _pos: BlockPosition) -> Result<BlockId, ChunkNotLoaded> {
todo!()
}
pub fn set_block(&self, _pos: BlockPosition, _block: BlockId) -> Result<(), ChunkNotLoaded> {
todo!()
}
pub fn resource<T: Resource>(&self) -> Result<&T, MissingResource> {
todo!()
}
pub fn resource_mut<T: Resource>(&self) -> Result<&mut T, MissingResource> {
todo!()
}
}
impl State {
pub fn player_by_name(&self, _name: &str) -> Option<EntityRef> {
todo!()
}
pub fn entity_by_uuid(&self, _uuid: Uuid) -> Option<EntityRef> {
todo!()
}
}
pub type CommandExecutor = fn(state: &mut State, sender: EntityRef, args: &[&str]) -> SysResult;
#[derive(Debug)]
pub struct CommandBuilder;
impl CommandBuilder {
pub fn new(_name: &str) -> Self {
todo!()
}
pub fn alias(&mut self, _alias: &str) -> &mut Self {
todo!()
}
pub fn build(&mut self, _executor: CommandExecutor, _setup: &mut Setup) {
todo!()
}
}
pub type System = fn(&mut State) -> SysResult;
#[derive(Debug)]
pub struct Setup;
impl Setup {
pub fn resource(&mut self, _resource: impl Resource) -> &mut Self {
todo!()
}
pub fn system(&mut self, _system: System) -> &mut Self {
todo!()
}
}