Also deduplicate for the dungeon puzzler

This commit is contained in:
Gwilym Inzani 2023-08-29 15:17:50 +01:00
parent a73e817f02
commit c9bf56755a
3 changed files with 27 additions and 18 deletions

View file

@ -165,6 +165,8 @@ impl Tile {
pub struct TileSetting(u16); pub struct TileSetting(u16);
impl TileSetting { impl TileSetting {
pub const BLANK: Self = TileSetting::new(1023, false, false, 0);
#[must_use] #[must_use]
pub const fn new(tile_id: u16, hflip: bool, vflip: bool, palette_id: u8) -> Self { pub const fn new(tile_id: u16, hflip: bool, vflip: bool, palette_id: u8) -> Self {
Self( Self(
@ -180,6 +182,16 @@ impl TileSetting {
Self(raw) Self(raw)
} }
#[must_use]
pub const fn hflip(self, should_flip: bool) -> Self {
Self(self.0 ^ ((should_flip as u16) << 10))
}
#[must_use]
pub const fn vflip(self, should_flip: bool) -> Self {
Self(self.0 ^ ((should_flip as u16) << 11))
}
fn index(self) -> u16 { fn index(self) -> u16 {
self.0 & ((1 << 10) - 1) self.0 & ((1 << 10) - 1)
} }

View file

@ -331,12 +331,10 @@ fn export_tiles(map: &tiled::Map, background: TokenStream) -> TokenStream {
tile_tileset_x * 2 + x_offset + tile_tileset_y * 9 * 4 + y_offset * 9 * 2; tile_tileset_x * 2 + x_offset + tile_tileset_y * 9 * 4 + y_offset * 9 * 2;
let gba_tile_id = gba_tile_id as u16; let gba_tile_id = gba_tile_id as u16;
let palette_id = quote! { backgrounds::#background.tile_settings[#gba_tile_id as usize].hflip(#hflip).vflip(#vflip) }
quote! { backgrounds::#background.palette_assignments[#gba_tile_id as usize] };
quote! { TileSetting::new(#gba_tile_id, #hflip, #vflip, #palette_id) }
} }
None => { None => {
quote! { TileSetting::new(1023, false, false, 0) } quote! { TileSetting::BLANK }
} }
} }
}); });
@ -361,12 +359,11 @@ fn export_ui_tiles(map: &tiled::Map, background: TokenStream) -> TokenStream {
let tile_id = tile.id() as u16; let tile_id = tile.id() as u16;
let vflip = tile.flip_v; let vflip = tile.flip_v;
let hflip = tile.flip_h; let hflip = tile.flip_h;
let palette_id =
quote! { backgrounds::#background.palette_assignments[#tile_id as usize] }; quote! { backgrounds::#background.tile_settings[#tile_id as usize].hflip(#hflip).vflip(#vflip) }
quote! { TileSetting::new(#tile_id, #hflip, #vflip, #palette_id) }
} }
None => { None => {
quote! { TileSetting::new(1023, false, false, 0) } quote! { TileSetting::BLANK }
} }
} }
}); });

View file

@ -1,12 +1,12 @@
use agb::{ use agb::{
display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, VRamManager}, display::tiled::{RegularMap, TileFormat, TileSet, VRamManager},
include_background_gfx, include_background_gfx,
}; };
include_background_gfx!(backgrounds, "1e151b", include_background_gfx!(backgrounds, "1e151b",
ui => "maps/ui_tiles.png", ui => deduplicate "maps/ui_tiles.png",
level => "maps/level.png", level => deduplicate "maps/level.png",
ending => "gfx/ending_page.aseprite", ending => deduplicate "gfx/ending_page.aseprite",
); );
mod tilemaps { mod tilemaps {
@ -56,13 +56,13 @@ pub fn load_ending_page(map: &mut RegularMap, vram_manager: &mut VRamManager) {
for y in 0..20u16 { for y in 0..20u16 {
for x in 0..30u16 { for x in 0..30u16 {
let tile_pos = y * 30 + x; let tile_pos = y * 30 + x;
let tile_setting = TileSetting::new(
tile_pos, map.set_tile(
false, vram_manager,
false, (x, y).into(),
backgrounds::ending.palette_assignments[tile_pos as usize], &ending_tileset,
backgrounds::ending.tile_settings[tile_pos as usize],
); );
map.set_tile(vram_manager, (x, y).into(), &ending_tileset, tile_setting);
} }
} }
} }