Is your feature request related to a problem? Please describe.
There is a clear pattern in sfml_resources::get_tile_sprite:
sf::Texture &sfml_resources::get_tile_sprite(const tile &t) noexcept //!OCLINT too long, needs to be fixed
{
switch (t.get_type()) //!OCLINT too few branches for now
{
case tile_type::tundra:
if (t.get_width() > 100) {
assert(t.get_height() == 100.0);
return m_tundra_laying;
}
assert(t.get_width() == 100.0);
return m_tundra_standing;
case tile_type::beach:
if (t.get_width() > 100) {
return m_beach_laying;
}
return m_beach_standing;
case tile_type::water:
if (t.get_width() > 100) {
return m_water_laying;
}
return m_water_standing;
case tile_type::dunes:
if (t.get_width() > 100) {
return m_dunes_laying;
}
return m_dunes_standing;
case tile_type::hills:
if (t.get_width() > 100) {
return m_hills_laying;
}
return m_hills_standing;
default:
return m_empty_tile;
}
}
For each tile, first the tile_type is checked, then its orientation. Reversing this simplifies the code and makes it more readable.
Describe the solution you'd like
(note: I think 'portrait' is the more commonly used name for 'standing', 'landscape' for 'lying')
[ ] Move code to these two new private member functions of sfml_resources:
sf::Texture &sfml_resources::get_tile_sprite_portrait(const tile_type t) noexcept //!OCLINT cannot be simpler
and
sf::Texture &sfml_resources::get_tile_sprite_landscape(const tile_type t) noexcept //!OCLINT cannot be simpler
[ ] Call the new function from the existing code
sf::Texture &sfml_resources::get_tile_sprite(const tile &t) noexcept
{
if (t.get_width() > t.get_height()
{
return get_tile_sprite_landscape(t.get_type());
}
else
{
//There are no square tiles (yet?)
assert(t.get_width() < t.get_height()
return get_tile_sprite_portrait(t.get_type());
}
}
[ ] Activate the test
//#define FIX_ISSUE_538
#ifdef FIX_ISSUE_538
// Can get the sprite of a tile type
{
assert(resources.get_tile_sprite_portrait(tile_type::grassland).getSize().x > 0);
assert(resources.get_tile_sprite_landscape(tile_type::grassland).getSize().x > 0);
}
#endif // FIX_ISSUE_538
Remove the preprocessor directives. If it compiles, you are done :+1:
Is your feature request related to a problem? Please describe.
There is a clear pattern in
sfml_resources::get_tile_sprite
:For each tile, first the
tile_type
is checked, then its orientation. Reversing this simplifies the code and makes it more readable.Describe the solution you'd like
(note: I think 'portrait' is the more commonly used name for 'standing', 'landscape' for 'lying')
sfml_resources
:and
Remove the preprocessor directives. If it compiles, you are done :+1:
Describe alternatives you've considered
None.
Additional context
None.