From 8d4ade5f8e5ce49b430c26f95ba6bdd75f712aa0 Mon Sep 17 00:00:00 2001 From: ashley Date: Mon, 18 Sep 2023 00:31:54 -0400 Subject: [PATCH] Fix bug in nametable exporter --- src/reskit/level/system.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index 66061fd..26a8040 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -76,8 +76,9 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result, Box> let layer_a: Option<&Layer> = tilemap.layers.iter().find( | layer | matches!( layer, Layer::Tile { system_plane: SystemPlane::MdPlaneA, tiles: _ } ) ); // Each entry in a `--system md` tilemap is 16 bits - let mut nametable: Vec = vec![ 0; tilemap.width * tilemap.height ]; + let mut total_nametable: Vec = Vec::new(); + let mut nametable: Vec = vec![ 0; tilemap.width * tilemap.height ]; if let Some( layer_b ) = layer_b { let layer_b = match layer_b { Layer::Tile { system_plane: _, tiles } => tiles, @@ -103,9 +104,11 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result, Box> } } } + total_nametable.extend( nametable.iter() ); // Just do the same for layer a // Copy pasted because i'm lazy and tired + let mut nametable: Vec = vec![ 0; tilemap.width * tilemap.height ]; if let Some( layer_a ) = layer_a { let layer_a = match layer_a { Layer::Tile { system_plane: _, tiles } => tiles, @@ -131,11 +134,12 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result, Box> } } } + total_nametable.extend( nametable.iter() ); // Convert the u16's to a series of u8 data let mut result: Vec = Vec::new(); - for i in 0..nametable.len() { - let bytes = nametable[ i ].to_be_bytes(); + for i in 0..total_nametable.len() { + let bytes = total_nametable[ i ].to_be_bytes(); for i in 0..2 { result.push( bytes[ i ] ); }