Stage changes for multiple tilesets per tmx file
parent
6fe992cb33
commit
32874109d8
|
@ -6,7 +6,7 @@ use super::ecs;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct TiledTilemap {
|
||||
pub tileset: TiledTileset,
|
||||
pub tileset: Vec<TiledTileset>,
|
||||
pub layers: Vec<Layer>,
|
||||
ecs: Vec<ecs::Entity>,
|
||||
pub width: usize,
|
||||
|
@ -207,6 +207,7 @@ pub fn get_tiled_tilemap( path: &str ) -> Result<TiledTilemap, Box<dyn Error>> {
|
|||
}
|
||||
|
||||
let tileset = get_tiles( tileset, &working_directory )?;
|
||||
let tileset = vec![ tileset ];
|
||||
|
||||
// Get the layers
|
||||
let layers: Vec<Layer> = map.descendants()
|
||||
|
|
|
@ -16,17 +16,18 @@ pub fn get_tiles( tilemap: &TiledTilemap ) -> Result<(Vec<u8>, Vec<u8>), Box<dyn
|
|||
];
|
||||
let mut all_tiles: Vec<u8> = 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<u8>, Vec<u8>), Box<dyn
|
|||
* In `--system md`, this outputs tilemap B and then tilemap A
|
||||
*/
|
||||
pub fn get_tilemap( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
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<Vec<u8>, Box<dyn Error>>
|
|||
|
||||
// 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<Vec<u8>, Box<dyn Error>>
|
|||
|
||||
// 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<Vec<u8>, Box<dyn Er
|
|||
* Get a helper .asm or .c file that ties all the level components together
|
||||
*/
|
||||
pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -> Result<String, Box<dyn Error>> {
|
||||
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}
|
||||
|
||||
|
|
Loading…
Reference in New Issue