make fields private

This commit is contained in:
Corwin 2022-02-22 20:16:58 +00:00
parent 6bafa3ebab
commit 02e6194073

View file

@ -40,12 +40,12 @@ const TILE_SPRITE: usize = 0x06010000;
const OBJECT_ATTRIBUTE_MEMORY: usize = 0x0700_0000; const OBJECT_ATTRIBUTE_MEMORY: usize = 0x0700_0000;
pub struct Sprite { pub struct Sprite {
pub palette: &'static Palette16, palette: &'static Palette16,
pub data: &'static [u8], data: &'static [u8],
pub size: Size, size: Size,
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum Size { pub enum Size {
// stored as attr0 attr1 // stored as attr0 attr1
S8x8 = 0b00_00, S8x8 = 0b00_00,
@ -66,12 +66,12 @@ pub enum Size {
#[macro_export] #[macro_export]
macro_rules! include_aseprite { macro_rules! include_aseprite {
($aseprite_path: expr) => {{ ($($aseprite_path: expr),*) => {{
use $crate::display::object::{Size, Sprite, Tag, TagMap}; use $crate::display::object::{Size, Sprite, Tag, TagMap};
use $crate::display::palette16::Palette16; use $crate::display::palette16::Palette16;
use $crate::phf; use $crate::phf;
$crate::include_aseprite_inner!($aseprite_path); $crate::include_aseprite_inner!($($aseprite_path),*);
(SPRITES, TAGS) (SPRITES, TAGS)
}}; }};
@ -185,6 +185,23 @@ impl Size {
(_, _) => panic!("Bad width and height!"), (_, _) => panic!("Bad width and height!"),
} }
} }
pub const fn to_width_height(self) -> (usize, usize) {
match self {
Size::S8x8 => (8, 8),
Size::S16x16 => (16, 16),
Size::S32x32 => (32, 32),
Size::S64x64 => (64, 64),
Size::S16x8 => (16, 8),
Size::S32x8 => (32, 8),
Size::S32x16 => (32, 16),
Size::S64x32 => (64, 32),
Size::S8x16 => (8, 16),
Size::S8x32 => (8, 32),
Size::S16x32 => (16, 32),
Size::S32x64 => (32, 64),
}
}
} }
pub struct SpriteBorrow<'a> { pub struct SpriteBorrow<'a> {
@ -438,6 +455,9 @@ impl Sprite {
size, size,
} }
} }
pub const fn size(&self) -> Size {
self.size
}
} }
impl SpriteController { impl SpriteController {
@ -519,8 +539,7 @@ impl SpriteControllerInner {
} }
fn return_sprite(&mut self, sprite: &'static Sprite) { fn return_sprite(&mut self, sprite: &'static Sprite) {
let entry = self self.sprite
.sprite
.entry(sprite.get_id()) .entry(sprite.get_id())
.and_replace_entry_with(|_, mut storage| { .and_replace_entry_with(|_, mut storage| {
storage.count -= 1; storage.count -= 1;
@ -532,10 +551,7 @@ impl SpriteControllerInner {
} }
}); });
match entry { self.return_palette(sprite.palette)
Entry::Occupied(_) => {}
Entry::Vacant(_) => self.return_palette(sprite.palette),
}
} }
fn return_palette(&mut self, palette: &'static Palette16) { fn return_palette(&mut self, palette: &'static Palette16) {