use bevy_ecs::prelude::Component;
use bevy_math::UVec2;
#[derive(Component, Debug, Clone, Copy, PartialEq, Default)]
pub enum Strategy3d {
#[default]
Halfblocks,
Luminance(LuminanceRamp),
Braille,
Depth(DepthRamp),
None,
}
impl Strategy3d {
pub(crate) const fn pixels_per_cell(&self) -> UVec2 {
match self {
Self::Halfblocks | Self::Luminance(_) | Self::Depth(_) | Self::None => UVec2::new(1, 2),
Self::Braille => UVec2::new(2, 4),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LuminanceRamp {
pub characters: &'static [char],
pub scale: f32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DepthRamp {
pub characters: &'static [char],
pub scale: f32,
}
const DEPTH_SCALE_DEFAULT: f32 = 30.0;
impl Default for DepthRamp {
fn default() -> Self {
Self {
characters: RAMP_ASCII,
scale: DEPTH_SCALE_DEFAULT,
}
}
}
pub const RAMP_ASCII: &[char] = &[' ', '.', ':', '+', '=', '!', '*', '?', '#', '%', '&', '@'];
pub const RAMP_SHADING: &[char] = &[' ', '░', '▒', '▓', '█'];
pub const RAMP_BLOCKS: &[char] = &[' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
pub const RAMP_BRAILLE: &[char] = &[' ', '⠂', '⠒', '⠖', '⠶', '⠷', '⠿', '⡿', '⣿'];
impl Default for LuminanceRamp {
fn default() -> Self {
Self {
characters: RAMP_ASCII,
scale: 10.0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn braille_targets_render_at_dot_density() {
assert_eq!(Strategy3d::Braille.pixels_per_cell(), UVec2::new(2, 4));
assert_eq!(Strategy3d::Halfblocks.pixels_per_cell(), UVec2::new(1, 2));
}
}