#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
#![forbid(missing_docs)]
use bevy::prelude::*;
use bevy::render::view::RenderLayers;
pub mod prelude {
pub use crate::{Pixelate, PixelateMeshPlugin, PIXELATION_RENDER_LAYERS};
}
mod creation;
mod ready_checks;
mod recursive_layering;
mod runtime;
mod shadow;
mod util;
#[derive(Debug)]
pub struct PixelateMeshPlugin<C: Component> {
_camera_type: std::marker::PhantomData<C>,
}
impl<C: Component> Default for PixelateMeshPlugin<C> {
fn default() -> Self {
Self {
_camera_type: std::marker::PhantomData,
}
}
}
impl<C> Plugin for PixelateMeshPlugin<C>
where
C: Component,
{
fn build(&self, app: &mut App) {
app.register_type::<Pixelate>()
.init_resource::<ready_checks::ToPixelate>()
.init_resource::<creation::Ordering>()
.init_resource::<shadow::SetSceneShadow>()
.add_event::<ready_checks::PixelationTargetReadyEvent>()
.add_systems(Startup, shadow::create_shadow_material)
.add_systems(
Update,
(
ready_checks::get_ready_pixelation_targets,
ready_checks::mark_for_pixelation,
creation::add_pixelation,
recursive_layering::recursively_set_layer,
shadow::add_shadow_caster,
shadow::set_scene_shadow,
runtime::update_pixelation,
),
)
.add_systems(
PostUpdate,
(
runtime::position_canvas::<C>,
runtime::sync_cameras::<C>,
runtime::despawn_dependent_types,
)
.chain(),
)
.add_systems(PostUpdate, runtime::set_visible);
}
}
#[derive(Debug, Component, Reflect, Default, Copy, Clone)]
#[reflect(Component)]
pub struct Pixelate {
pub horizontal_pixels: u32,
pub vertical_pixels: u32,
}
impl Pixelate {
pub fn splat(horizontal_and_vertical_pixels: u32) -> Self {
Self {
horizontal_pixels: horizontal_and_vertical_pixels,
vertical_pixels: horizontal_and_vertical_pixels,
}
}
}
#[derive(Debug, Component, Copy, Clone)]
struct Canvas {
pub(crate) target: Entity,
}
#[derive(Debug, Component, Copy, Clone)]
struct PixelationCamera {
pub(crate) target: Entity,
}
pub const PIXELATION_RENDER_LAYERS: RenderLayers = RenderLayers::layer(1);
#[cfg(doctest)]
#[doc = include_str!("../readme.md")]
mod test_readme {}