use binrw::BinRead;
use crate::graphics::Rgba;
use crate::tileset::PaletteData;
use crate::tileset::TileData;
pub const MON_PIC_WIDTH_TILES: u8 = 8;
pub const MON_PIC_HEIGHT_TILES: u8 = 8;
pub const MON_PIC_PIXELS: u16 = 64;
pub const MON_PIC_BYTES: usize = 2048;
pub const POKEMON_PIC_BYTES: usize = 2048;
pub const POKEMON_PALETTE_BYTES: usize = 32;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SpeciesId(pub u16);
impl SpeciesId {
pub const NONE: Self = Self(0);
pub const EGG: Self = Self(412);
}
impl std::fmt::Display for SpeciesId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, BinRead)]
#[br(little)]
pub struct MonCoordsOnDisk {
pub size: u8,
pub y_offset: u8,
#[br(pad_size_to = 2)]
pub _padding: (),
}
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
pub struct MonCoords {
pub width_tiles: u8,
pub height_tiles: u8,
pub y_offset: u8,
}
impl MonCoords {
#[must_use]
pub fn from_disk(disk: &MonCoordsOnDisk) -> Self {
Self {
width_tiles: (disk.size >> 4) & 0x0F,
height_tiles: disk.size & 0x0F,
y_offset: disk.y_offset,
}
}
#[must_use]
pub fn width_pixels(&self) -> u32 {
u32::from(self.width_tiles) * 8
}
#[must_use]
pub fn height_pixels(&self) -> u32 {
u32::from(self.height_tiles) * 8
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SpriteSheet {
pub tiles: TileData,
pub coords: MonCoords,
}
#[derive(Debug, Clone)]
pub struct Sprite {
pub id: SpeciesId,
pub name: String,
pub front: Option<SpriteSheet>,
pub back: Option<SpriteSheet>,
pub palette: PaletteData,
pub shiny_palette: PaletteData,
pub front_coords: MonCoords,
pub back_coords: MonCoords,
}
#[derive(Debug, Clone)]
pub struct FormSprite {
pub base: SpeciesId,
pub form: String,
pub front_tiles: Option<Vec<u8>>,
pub back_tiles: Option<Vec<u8>>,
pub palette: Option<PaletteData>,
pub shiny_palette: Option<PaletteData>,
}
#[derive(Debug, Clone)]
pub struct SpriteExport {
pub id: u16,
pub name: String,
pub front_rgba: Option<Vec<u8>>,
pub back_rgba: Option<Vec<u8>>,
pub palette_rgba: Option<Vec<Rgba>>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn species_id_constants() {
assert_eq!(SpeciesId::NONE.0, 0);
assert_eq!(SpeciesId::EGG.0, 412);
}
#[test]
fn mon_coords_decode() {
let disk = MonCoordsOnDisk {
size: 0x45,
y_offset: 14,
_padding: (),
};
let c = MonCoords::from_disk(&disk);
assert_eq!(c.width_tiles, 4);
assert_eq!(c.height_tiles, 5);
assert_eq!(c.y_offset, 14);
assert_eq!(c.width_pixels(), 32);
assert_eq!(c.height_pixels(), 40);
}
}