Skip to content

Commit

Permalink
Avoid loading terrain minimap images when not specified by WML
Browse files Browse the repository at this point in the history
Otherwise we build a bogus "terrain/.png" file path and produce spurious
`error display: could not open image 'terrain/.png'` messages in stderr.

Although this is primarily an issue found with certain special overlay
terrains such as ^Xo (Impassable Overlay), this fix covers base terrains
as well.
  • Loading branch information
irydacea committed Oct 20, 2015
1 parent 21391f9 commit 62e84fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/minimap.cpp
Expand Up @@ -137,14 +137,14 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
need_highlighting = true;
}

if(i == cache->end()) {
if(i == cache->end() && !terrain_info.minimap_image().empty()) {
std::string base_file =
"terrain/" + terrain_info.minimap_image() + ".png";
surface tile = get_image(base_file,image::HEXED);

//Compose images of base and overlay if necessary
// NOTE we also skip overlay when base is missing (to avoid hiding the error)
if(tile != NULL && tdata.get_terrain_info(terrain).is_combined()) {
if(tile != NULL && tdata.get_terrain_info(terrain).is_combined() && !terrain_info.minimap_image_overlay().empty()) {
std::string overlay_file =
"terrain/" + terrain_info.minimap_image_overlay() + ".png";
surface overlay = get_image(overlay_file,image::HEXED);
Expand Down
22 changes: 14 additions & 8 deletions src/terrain_builder.cpp
Expand Up @@ -345,19 +345,25 @@ void terrain_builder::rebuild_terrain(const map_location &loc)
btile.images_background.clear();
const std::string filename =
map().get_terrain_info(loc).minimap_image();
animated<image::locator> img_loc;
img_loc.add_frame(100,image::locator("terrain/" + filename + ".png"));
img_loc.start_animation(0, true);
btile.images_background.push_back(img_loc);

if(!filename.empty()) {
animated<image::locator> img_loc;
img_loc.add_frame(100,image::locator("terrain/" + filename + ".png"));
img_loc.start_animation(0, true);
btile.images_background.push_back(img_loc);
}

//Combine base and overlay image if necessary
if(map().get_terrain_info(loc).is_combined()) {
const std::string filename_ovl =
map().get_terrain_info(loc).minimap_image_overlay();
animated<image::locator> img_loc_ovl;
img_loc_ovl.add_frame(100,image::locator("terrain/" + filename_ovl + ".png"));
img_loc_ovl.start_animation(0, true);
btile.images_background.push_back(img_loc_ovl);

if(!filename_ovl.empty()) {
animated<image::locator> img_loc_ovl;
img_loc_ovl.add_frame(100,image::locator("terrain/" + filename_ovl + ".png"));
img_loc_ovl.start_animation(0, true);
btile.images_background.push_back(img_loc_ovl);
}
}
}
}
Expand Down

0 comments on commit 62e84fa

Please sign in to comment.