pub use draw::*;
use crate::{render::tile_view_pattern::TileShape, tcs::tiles::Tile};
mod draw;
pub struct RenderPhase<I: PhaseItem> {
items: Vec<I>,
}
impl<'a, I: PhaseItem> IntoIterator for &'a RenderPhase<I> {
type Item = <&'a Vec<I> as IntoIterator>::Item;
type IntoIter = <&'a Vec<I> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.items.iter()
}
}
impl<I: PhaseItem> Default for RenderPhase<I> {
fn default() -> Self {
Self { items: Vec::new() }
}
}
impl<I: PhaseItem> RenderPhase<I> {
pub fn add(&mut self, item: I) {
self.items.push(item);
}
pub fn sort(&mut self) {
self.items.sort_by_key(|d| d.sort_key());
}
pub fn clear(&mut self) {
self.items.clear();
}
pub fn size(&self) -> usize {
self.items.len()
}
}
pub struct LayerItem {
pub draw_function: Box<dyn Draw<LayerItem>>,
pub index: u32,
pub style_layer: String,
pub tile: Tile,
pub source_shape: TileShape, }
impl PhaseItem for LayerItem {
type SortKey = u32;
fn sort_key(&self) -> Self::SortKey {
self.index
}
fn draw_function(&self) -> &dyn Draw<LayerItem> {
self.draw_function.as_ref()
}
}
pub struct TileMaskItem {
pub draw_function: Box<dyn Draw<TileMaskItem>>,
pub source_shape: TileShape,
}
impl PhaseItem for TileMaskItem {
type SortKey = u32;
fn sort_key(&self) -> Self::SortKey {
0
}
fn draw_function(&self) -> &dyn Draw<TileMaskItem> {
self.draw_function.as_ref()
}
}