@ -27,16 +27,15 @@ namespace textures {
TMGR . sprite_textures . try_emplace ( name , sprite , texture ) ;
}
TMGR . floor = load_image ( assets [ " sprites " ] [ " floor " ] [ " path " ] ) ;
TMGR . ceiling = load_image ( assets [ " sprites " ] [ " ceiling " ] [ " path " ] ) ;
}
void load_tiles ( ) {
Config assets ( " assets/tiles.json " ) ;
auto & tiles = assets . json ( ) ;
TMGR . surfaces . resize ( tiles . size ( ) ) ;
TMGR . tile_set . resize ( tiles . size ( ) ) ;
TMGR . ceilings . resize ( tiles . size ( ) ) ;
TMGR . map_tile_set . resize ( tiles . size ( ) ) ;
for ( auto & el : tiles . items ( ) ) {
auto & config = el . value ( ) ;
@ -45,11 +44,22 @@ namespace textures {
if ( surface_i > = tiles . size ( ) ) {
TMGR . surfaces . resize ( surface_i + 1 ) ;
TMGR . tile_set . resize ( surface_i + 1 ) ;
TMGR . ceilings . resize ( surface_i + 1 ) ;
TMGR . map_tile_set . resize ( surface_i + 1 ) ;
}
TMGR . tile_set [ surface_i ] = config [ " display " ] ;
TMGR . map_ tile_set[ surface_i ] = config [ " display " ] ;
TMGR . surfaces [ surface_i ] = load_image ( texture_fname ) ;
// NOTE: ceilings defaults to 0 which is floor texture so only need to update
if ( config . contains ( " ceiling " ) ) {
const std : : string & name = config [ " ceiling " ] ;
dbc : : check ( tiles . contains ( name ) , fmt : : format ( " invalid ceiling name {} in tile config {} " , name , ( std : : string ) el . key ( ) ) ) ;
auto & ceiling = tiles [ name ] ;
TMGR . ceilings [ surface_i ] = ceiling [ " id " ] ;
}
}
}
@ -83,19 +93,16 @@ namespace textures {
return texture ;
}
std : : vector < wchar_t > & get_tile_set ( ) {
return TMGR . tile_set ;
std : : vector < wchar_t > & get_map_ tile_set ( ) {
return TMGR . map_ tile_set;
}
const uint32_t * get_surface ( size_t num ) {
return ( const uint32_t * ) TMGR . surfaces [ num ] . getPixelsPtr ( ) ;
}
const uint32_t * get_floor ( ) {
return ( const uint32_t * ) TMGR . floor . getPixelsPtr ( ) ;
}
const uint32_t * get_ceiling ( ) {
return ( const uint32_t * ) TMGR . ceiling . getPixelsPtr ( ) ;
const uint32_t * get_ceiling ( size_t num ) {
size_t ceiling_num = TMGR . ceilings [ num ] ;
return ( const uint32_t * ) TMGR . surfaces [ ceiling_num ] . getPixelsPtr ( ) ;
}
} ;