use bevy::{
ecs::{component::Component, entity::Entity},
math::{IVec2, IVec3},
prelude::Deref,
};
mod chunk_query;
pub use chunk_query::*;
#[derive(Component, Clone, Copy, Deref, Debug)]
pub struct InMap(pub(crate) Entity);
#[derive(Component, Deref, Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct ChunkCoord<const N: usize>(pub(crate) [i32; N]);
impl From<IVec2> for ChunkCoord<2> {
fn from(value: IVec2) -> Self {
Self(value.into())
}
}
impl From<IVec3> for ChunkCoord<3> {
fn from(value: IVec3) -> Self {
Self(value.into())
}
}
#[derive(Component, Debug)]
pub struct Chunk(pub(crate) Vec<Option<Entity>>);
impl Chunk {
pub(crate) fn new(chunk_size: usize) -> Self {
Self(vec![None; chunk_size])
}
pub(crate) fn get(&self, tile_i: usize) -> Option<Entity> {
self.0.get(tile_i).cloned().flatten()
}
}