From 8f7e7748e2225987663d5cba6ea98a3820032210 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 7 Mar 2022 20:38:06 +0000 Subject: [PATCH] Graphics --- agb/src/display/object.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index b0ffb3ec..1a74cc5d 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -67,15 +67,32 @@ pub enum Size { #[macro_export] macro_rules! include_aseprite { ($($aseprite_path: expr),*) => {{ - use $crate::display::object::{Size, Sprite, Tag, TagMap}; + use $crate::display::object::{Size, Sprite, Tag, TagMap, Graphics}; use $crate::display::palette16::Palette16; $crate::include_aseprite_inner!($($aseprite_path),*); - (SPRITES, TAGS) + &Graphics::new(SPRITES, TAGS) }}; } +pub struct Graphics { + sprites: &'static [Sprite], + tag_map: &'static TagMap, +} + +impl Graphics { + pub const fn new(sprites: &'static [Sprite], tag_map: &'static TagMap) -> Self { + Self { sprites, tag_map } + } + pub const fn tags(&self) -> &TagMap { + self.tag_map + } + pub const fn sprites(&self) -> &[Sprite] { + self.sprites + } +} + pub struct TagMap { tags: &'static [(&'static str, Tag)], } @@ -170,8 +187,10 @@ impl Tag { } } + #[doc(hidden)] pub const fn new(sprites: &'static [Sprite], from: usize, to: usize, direction: usize) -> Self { assert!(from <= to); + assert!(to < sprites.len()); Self { sprites: &sprites[from] as *const Sprite, len: to - from + 1,