Deduplicate everything in hatwiz

This commit is contained in:
Gwilym Inzani 2023-08-29 15:05:57 +01:00
parent 201a127673
commit a73e817f02
3 changed files with 24 additions and 24 deletions

View file

@ -72,7 +72,7 @@ impl Tile {
fn vflipped(&self) -> Self { fn vflipped(&self) -> Self {
let mut new_data = self.data; let mut new_data = self.data;
for y in 0..8 { for y in 0..4 {
for x in 0..8 { for x in 0..8 {
new_data.swap(y * 8 + x, (7 - y) * 8 + x); new_data.swap(y * 8 + x, (7 - y) * 8 + x);
} }
@ -85,7 +85,7 @@ impl Tile {
let mut new_data = self.data; let mut new_data = self.data;
for y in 0..8 { for y in 0..8 {
for x in 0..8 { for x in 0..4 {
new_data.swap(y * 8 + x, y * 8 + (7 - x)); new_data.swap(y * 8 + x, y * 8 + (7 - x));
} }
} }

View file

@ -3,10 +3,10 @@ use agb::display::{
HEIGHT, WIDTH, HEIGHT, WIDTH,
}; };
const LEVEL_START: u16 = 12 * 28; const LEVEL_START: usize = 12 * 28;
const NUMBERS_START: u16 = 12 * 28 + 3; const NUMBERS_START: usize = 12 * 28 + 3;
const HYPHEN: u16 = 12 * 28 + 11; const HYPHEN: usize = 12 * 28 + 11;
pub const BLANK: u16 = 11 * 28; pub const BLANK: usize = 11 * 28;
pub fn write_level( pub fn write_level(
map: &mut RegularMap, map: &mut RegularMap,
@ -14,15 +14,16 @@ pub fn write_level(
level: u32, level: u32,
tileset: &'_ TileSet<'_>, tileset: &'_ TileSet<'_>,
vram: &mut VRamManager, vram: &mut VRamManager,
tile_settings: &[TileSetting],
) { ) {
for (i, &tile) in [ for (i, &tile) in [
LEVEL_START, LEVEL_START,
LEVEL_START + 1, LEVEL_START + 1,
LEVEL_START + 2, LEVEL_START + 2,
BLANK, BLANK,
world as u16 + NUMBERS_START - 1, world as usize + NUMBERS_START - 1,
HYPHEN, HYPHEN,
level as u16 + NUMBERS_START - 1, level as usize + NUMBERS_START - 1,
] ]
.iter() .iter()
.enumerate() .enumerate()
@ -31,7 +32,7 @@ pub fn write_level(
vram, vram,
(i as u16, 0).into(), (i as u16, 0).into(),
tileset, tileset,
TileSetting::from_raw(tile), tile_settings[tile as usize],
); );
} }

View file

@ -11,7 +11,7 @@ use agb::{
object::{Graphics, OamManaged, Object, Tag, TagMap}, object::{Graphics, OamManaged, Object, Tag, TagMap},
tiled::{ tiled::{
InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TileSet, InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TileSet,
TileSetting, TiledMap, VRamManager, TiledMap, VRamManager,
}, },
Priority, HEIGHT, WIDTH, Priority, HEIGHT, WIDTH,
}, },
@ -101,7 +101,7 @@ mod map_tiles {
} }
} }
agb::include_background_gfx!(tile_sheet, "2ce8f4", background => "gfx/tile_sheet.png"); agb::include_background_gfx!(tile_sheet, "2ce8f4", background => deduplicate "gfx/tile_sheet.png");
const GRAPHICS: &Graphics = agb::include_aseprite!("gfx/sprites.aseprite"); const GRAPHICS: &Graphics = agb::include_aseprite!("gfx/sprites.aseprite");
const TAG_MAP: &TagMap = GRAPHICS.tags(); const TAG_MAP: &TagMap = GRAPHICS.tags();
@ -801,7 +801,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
&mut vram, &mut vram,
(x, y).into(), (x, y).into(),
&tileset, &tileset,
TileSetting::from_raw(level_display::BLANK), tile_sheet::background.tile_settings[level_display::BLANK],
); );
} }
} }
@ -846,6 +846,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
current_level % 8 + 1, current_level % 8 + 1,
&tileset, &tileset,
&mut vram, &mut vram,
tile_sheet::background.tile_settings,
); );
world_display.commit(&mut vram); world_display.commit(&mut vram);
@ -865,12 +866,11 @@ pub fn main(mut agb: agb::Gba) -> ! {
let level = &map_tiles::LEVELS[map_current_level as usize]; let level = &map_tiles::LEVELS[map_current_level as usize];
( (
&tileset, &tileset,
TileSetting::from_raw( tile_sheet::background.tile_settings[*level
*level .background
.background .get((pos.y * level.dimensions.x as i32 + pos.x) as usize)
.get((pos.y * level.dimensions.x as i32 + pos.x) as usize) .unwrap_or(&0)
.unwrap_or(&0), as usize],
),
) )
}), }),
); );
@ -884,12 +884,11 @@ pub fn main(mut agb: agb::Gba) -> ! {
let level = &map_tiles::LEVELS[map_current_level as usize]; let level = &map_tiles::LEVELS[map_current_level as usize];
( (
&tileset, &tileset,
TileSetting::from_raw( tile_sheet::background.tile_settings[*level
*level .foreground
.foreground .get((pos.y * level.dimensions.x as i32 + pos.x) as usize)
.get((pos.y * level.dimensions.x as i32 + pos.x) as usize) .unwrap_or(&0)
.unwrap_or(&0), as usize],
),
) )
}), }),
); );