use super::{remove_leading_newlines, Text};
use crate::elements::{
    view::{Modifier, ViewElement},
    Pixel, Vec2D,
};
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct Sprite {
    pub pos: Vec2D,
    pub texture: String,
    pub modifier: Modifier,
    }
impl Sprite {
    pub fn new(pos: Vec2D, texture: &str, modifier: Modifier) -> Self {
        Self {
            pos,
            texture: remove_leading_newlines(texture),
            modifier,
        }
    }
    pub fn draw(pos: Vec2D, texture: &str, modifier: Modifier) -> Vec<Pixel> {
        let mut pixels = vec![];
        let lines = texture.split('\n');
        for (y, line) in lines.enumerate() {
            pixels.extend(Text::draw(pos + Vec2D::new(0, y as isize), line, modifier));
        }
        pixels
    }
}
impl ViewElement for Sprite {
    fn active_pixels(&self) -> Vec<Pixel> {
        Self::draw(self.pos, &self.texture, self.modifier)
    }
}