diff --git a/src/reskit/level/converter.rs b/src/reskit/level/converter.rs index 85d508b..f2d8e5d 100644 --- a/src/reskit/level/converter.rs +++ b/src/reskit/level/converter.rs @@ -6,7 +6,7 @@ use super::ecs; #[derive(Debug)] pub struct TiledTilemap { - pub tileset: TiledTileset, + pub tileset: Vec, pub layers: Vec, ecs: Vec, pub width: usize, @@ -207,6 +207,7 @@ pub fn get_tiled_tilemap( path: &str ) -> Result> { } let tileset = get_tiles( tileset, &working_directory )?; + let tileset = vec![ tileset ]; // Get the layers let layers: Vec = map.descendants() diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index 0538e79..1061948 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -16,17 +16,18 @@ pub fn get_tiles( tilemap: &TiledTilemap ) -> Result<(Vec, Vec), Box = vec![0; 32]; // --system md, start with a blank buffer tile - let tiles_height = tilemap.tileset.image.height() / 8; // --system md - let tiles_width = tilemap.tileset.image.width() / 8; // --system md + let tileset = tilemap.tileset.first().ok_or( "internal error: no tileset" )?; + let tiles_height = tileset.image.height() / 8; // --system md + let tiles_width = tileset.image.width() / 8; // --system md for tile_y in 0..tiles_height { for tile_x in 0..tiles_width { let tile_index = ( tile_y * tiles_width ) + tile_x; - let tile = tilemap.tileset.image.clone().crop( tile_x * 8, tile_y * 8, 8, 8 ); + let tile = tileset.image.clone().crop( tile_x * 8, tile_y * 8, 8, 8 ); // Fake palette (see below) let mut fake: [u16; 16] = [ 0; 16 ]; - let selected_pal = tilemap.tileset.palettes[ tile_index as usize ]; + let selected_pal = tileset.palettes[ tile_index as usize ]; let tile_bin = image_to_tiles( &tile, @@ -72,6 +73,8 @@ pub fn get_tiles( tilemap: &TiledTilemap ) -> Result<(Vec, Vec), Box Result, Box> { + let tileset = tilemap.tileset.first().ok_or( "internal error: no tileset" )?; + let layer_b: Option<&Layer> = tilemap.layers.iter().find( | layer | matches!( layer, Layer::Tile { system_plane: SystemPlane::MdPlaneB, tiles: _ } ) ); let layer_a: Option<&Layer> = tilemap.layers.iter().find( | layer | matches!( layer, Layer::Tile { system_plane: SystemPlane::MdPlaneA, tiles: _ } ) ); @@ -94,7 +97,7 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result, Box> // From the starting point of x, y "stamp" the target tile's indices let nametable_entry = target_tile; - let selected_pal = tilemap.tileset.palettes[ source_tile as usize ]; + let selected_pal = tileset.palettes[ source_tile as usize ]; if let Some( selected_pal ) = selected_pal { nametable[ ( y * tilemap.width ) + x ] = ( ( selected_pal as u16 ) << 13 ) | nametable_entry; } else { @@ -124,7 +127,7 @@ pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result, Box> // From the starting point of x, y "stamp" the target tile's indices let nametable_entry = target_tile; - let selected_pal = tilemap.tileset.palettes[ source_tile as usize ]; + let selected_pal = tileset.palettes[ source_tile as usize ]; if let Some( selected_pal ) = selected_pal { nametable[ ( y * tilemap.width ) + x ] = ( ( selected_pal as u16 ) << 13 ) | nametable_entry; } else { @@ -173,10 +176,12 @@ pub fn get_collision_map( tilemap: &TiledTilemap ) -> Result, Box Result> { + let tileset = tilemap.tileset.first().ok_or( "internal error: no tileset" )?; + let version = env!( "CARGO_PKG_VERSION" ); let level_label = symbol_to_pascal( level_name ); let ( width, height ) = ( tilemap.width, tilemap.height ); - let num_tiles = ( tilemap.tileset.image.width() / 8 ) * ( tilemap.tileset.image.height() / 8 ); // --system md + let num_tiles = ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 ); // --system md let file = format!( r#"; Level definition file ; Generated by reskit v{version}