use bevy::prelude::*;
#[derive(Component, Clone)]
#[require(RatatuiCameraStrategy)]
pub struct RatatuiCamera {
pub dimensions: (u32, u32),
pub autoresize: bool,
pub autoresize_fn: fn((u32, u32)) -> (u32, u32),
}
impl Default for RatatuiCamera {
fn default() -> Self {
Self {
dimensions: (256, 256),
autoresize: false,
autoresize_fn: |(w, h)| (w * 2, h * 2),
}
}
}
impl RatatuiCamera {
pub fn new(dimensions: (u32, u32)) -> Self {
Self {
dimensions,
..default()
}
}
pub fn autoresize() -> Self {
Self {
autoresize: true,
..default()
}
}
pub fn with_dimensions(mut self, dimensions: (u32, u32)) -> Self {
self.dimensions = dimensions;
self
}
pub fn with_autoresize(mut self, autoresize: bool) -> Self {
self.autoresize = autoresize;
self
}
pub fn with_autoresize_fn(mut self, autoresize_fn: fn((u32, u32)) -> (u32, u32)) -> Self {
self.autoresize_fn = autoresize_fn;
self
}
}
#[derive(Component, Default, Clone)]
pub enum RatatuiCameraStrategy {
#[default]
HalfBlocks,
Luminance(LuminanceConfig),
None,
}
impl RatatuiCameraStrategy {
pub fn luminance_braille() -> Self {
Self::Luminance(LuminanceConfig {
luminance_characters: LuminanceConfig::LUMINANCE_CHARACTERS_BRAILLE.into(),
..default()
})
}
pub fn luminance_misc() -> Self {
Self::Luminance(LuminanceConfig {
luminance_characters: LuminanceConfig::LUMINANCE_CHARACTERS_MISC.into(),
..default()
})
}
pub fn luminance_shading() -> Self {
Self::Luminance(LuminanceConfig {
luminance_characters: LuminanceConfig::LUMINANCE_CHARACTERS_SHADING.into(),
..default()
})
}
}
#[derive(Clone)]
pub struct LuminanceConfig {
pub luminance_characters: Vec<char>,
pub luminance_scale: f32,
}
impl LuminanceConfig {
pub const LUMINANCE_CHARACTERS_BRAILLE: &'static [char] =
&[' ', '⠂', '⠒', '⠖', '⠶', '⠷', '⠿', '⡿', '⣿'];
pub const LUMINANCE_CHARACTERS_MISC: &'static [char] =
&[' ', '.', ':', '+', '=', '!', '*', '?', '#', '%', '&', '@'];
pub const LUMINANCE_CHARACTERS_SHADING: &'static [char] = &[' ', '░', '▒', '▓', '█'];
const LUMINANCE_SCALE_DEFAULT: f32 = 10.;
}
impl Default for LuminanceConfig {
fn default() -> Self {
Self {
luminance_characters: LuminanceConfig::LUMINANCE_CHARACTERS_BRAILLE.into(),
luminance_scale: LuminanceConfig::LUMINANCE_SCALE_DEFAULT,
}
}
}