Refactor ternary into early-returning conditionals

Continuing precedent set in ef5ee38
This commit is contained in:
Chris Thrasher 2024-04-22 20:59:27 -06:00
parent a05daa62b7
commit ebf916edf8

View File

@ -346,19 +346,23 @@ sf::Color colorFromFloats(float r, float g, float b)
sf::Color getLowlandsTerrainColor(float moisture) sf::Color getLowlandsTerrainColor(float moisture)
{ {
sf::Color color = moisture < 0.27f ? colorFromFloats(240, 240, 180) if (moisture < 0.27f)
: moisture < 0.3f ? colorFromFloats(240 - (240 * (moisture - 0.27f) / 0.03f), return colorFromFloats(240, 240, 180);
if (moisture < 0.3f)
return colorFromFloats(240 - (240 * (moisture - 0.27f) / 0.03f),
240 - (40 * (moisture - 0.27f) / 0.03f), 240 - (40 * (moisture - 0.27f) / 0.03f),
180 - (180 * (moisture - 0.27f) / 0.03f)) 180 - (180 * (moisture - 0.27f) / 0.03f));
: moisture < 0.4f ? colorFromFloats(0, 200, 0) if (moisture < 0.4f)
: moisture < 0.48f ? colorFromFloats(0, 200 - (40 * (moisture - 0.4f) / 0.08f), 0) return colorFromFloats(0, 200, 0);
: moisture < 0.6f ? colorFromFloats(0, 160, 0) if (moisture < 0.48f)
: moisture < 0.7f ? colorFromFloats((34 * (moisture - 0.6f) / 0.1f), return colorFromFloats(0, 200 - (40 * (moisture - 0.4f) / 0.08f), 0);
if (moisture < 0.6f)
return colorFromFloats(0, 160, 0);
if (moisture < 0.7f)
return colorFromFloats((34 * (moisture - 0.6f) / 0.1f),
160 - (60 * (moisture - 0.6f) / 0.1f), 160 - (60 * (moisture - 0.6f) / 0.1f),
(34 * (moisture - 0.6f) / 0.1f)) (34 * (moisture - 0.6f) / 0.1f));
: colorFromFloats(34, 100, 34); return colorFromFloats(34, 100, 34);
return color;
} }