add OwnedTileSet

This commit is contained in:
Alex Janka 2024-11-16 10:36:14 +11:00
parent 6d942b07d0
commit 22167ac608
2 changed files with 34 additions and 1 deletions

View file

@ -14,7 +14,7 @@ pub use map::{AffineMap, MapLoan, RegularMap, TiledMap};
pub use tiled0::Tiled0;
pub use tiled1::Tiled1;
pub use tiled2::Tiled2;
pub use vram_manager::{DynamicTile, TileFormat, TileIndex, TileSet, VRamManager};
pub use vram_manager::{DynamicTile, OwnedTileSet, TileFormat, TileIndex, TileSet, VRamManager};
use map::TRANSPARENT_TILE_INDEX;

View file

@ -60,6 +60,39 @@ impl<'a> TileSet<'a> {
fn reference(&self) -> NonNull<[u8]> {
self.tiles.into()
}
pub fn to_owned(&self) -> OwnedTileSet {
OwnedTileSet {
tiles: self.tiles.to_vec(),
format: self.format,
}
}
}
pub struct OwnedTileSet {
tiles: Vec<u8>,
format: TileFormat,
}
impl OwnedTileSet {
pub fn tile_set(&self) -> TileSet<'_> {
TileSet {
tiles: &self.tiles,
format: self.format,
}
}
pub fn tiles(&self) -> &[u8] {
&self.tiles
}
pub fn tiles_mut(&mut self) -> &mut [u8] {
&mut self.tiles
}
pub fn format(&self) -> TileFormat {
self.format
}
}
#[derive(Debug, Clone, Copy)]