Fix bug in nametable exporter

stinkhead7ds
Ashley N. 2023-09-18 00:31:54 -04:00
parent 37f82daca1
commit 8d4ade5f8e
1 changed files with 7 additions and 3 deletions

View File

@ -76,8 +76,9 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Error>>
let layer_a: Option<&Layer> = tilemap.layers.iter().find( | layer | matches!( layer, Layer::Tile { system_plane: SystemPlane::MdPlaneA, tiles: _ } ) ); 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 // Each entry in a `--system md` tilemap is 16 bits
let mut nametable: Vec<u16> = vec![ 0; tilemap.width * tilemap.height ]; let mut total_nametable: Vec<u16> = Vec::new();
let mut nametable: Vec<u16> = vec![ 0; tilemap.width * tilemap.height ];
if let Some( layer_b ) = layer_b { if let Some( layer_b ) = layer_b {
let layer_b = match layer_b { let layer_b = match layer_b {
Layer::Tile { system_plane: _, tiles } => tiles, Layer::Tile { system_plane: _, tiles } => tiles,
@ -103,9 +104,11 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Error>>
} }
} }
} }
total_nametable.extend( nametable.iter() );
// Just do the same for layer a // Just do the same for layer a
// Copy pasted because i'm lazy and tired // Copy pasted because i'm lazy and tired
let mut nametable: Vec<u16> = vec![ 0; tilemap.width * tilemap.height ];
if let Some( layer_a ) = layer_a { if let Some( layer_a ) = layer_a {
let layer_a = match layer_a { let layer_a = match layer_a {
Layer::Tile { system_plane: _, tiles } => tiles, Layer::Tile { system_plane: _, tiles } => tiles,
@ -131,11 +134,12 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Error>>
} }
} }
} }
total_nametable.extend( nametable.iter() );
// Convert the u16's to a series of u8 data // Convert the u16's to a series of u8 data
let mut result: Vec<u8> = Vec::new(); let mut result: Vec<u8> = Vec::new();
for i in 0..nametable.len() { for i in 0..total_nametable.len() {
let bytes = nametable[ i ].to_be_bytes(); let bytes = total_nametable[ i ].to_be_bytes();
for i in 0..2 { for i in 0..2 {
result.push( bytes[ i ] ); result.push( bytes[ i ] );
} }