1
0
Fork 0

Codechange: Simplify weird range check.

pull/14203/head
frosch 2025-05-03 20:01:11 +02:00 committed by frosch
parent d464961c41
commit 48d09af039
1 changed files with 8 additions and 15 deletions

View File

@ -327,25 +327,18 @@ static bool ConZoomToLevel(std::span<std::string_view> argv)
return true; return true;
case 2: { case 2: {
auto level = ParseInteger(argv[1]); auto level = ParseInteger<std::underlying_type_t<ZoomLevel>>(argv[1]);
if (level.has_value()) { if (level.has_value()) {
/* In case ZOOM_LVL_MIN is more than 0, the next if statement needs to be amended. auto zoom_lvl = static_cast<ZoomLevel>(*level);
* A simple check for less than ZOOM_LVL_MIN does not work here because we are if (!IsInsideMM(zoom_lvl, ZOOM_LVL_BEGIN, ZOOM_LVL_END)) {
* reading an unsigned integer from the console, so just check for a '-' char. */ IConsolePrint(CC_ERROR, "Invalid zoom level. Valid range is {} to {}.", ZOOM_LVL_MIN, ZOOM_LVL_MAX);
static_assert(ZOOM_LVL_MIN == 0); } else if (!IsInsideMM(zoom_lvl, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max + 1)) {
if (argv[1][0] == '-') { IConsolePrint(CC_ERROR, "Current client settings limit zoom levels to range {} to {}.", _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
IConsolePrint(CC_ERROR, "Zoom-in levels below {} are not supported.", ZOOM_LVL_MIN);
} else if (*level < _settings_client.gui.zoom_min) {
IConsolePrint(CC_ERROR, "Current client settings do not allow zooming in below level {}.", _settings_client.gui.zoom_min);
} else if (*level > ZOOM_LVL_MAX) {
IConsolePrint(CC_ERROR, "Zoom-in levels above {} are not supported.", ZOOM_LVL_MAX);
} else if (*level > _settings_client.gui.zoom_max) {
IConsolePrint(CC_ERROR, "Current client settings do not allow zooming out beyond level {}.", _settings_client.gui.zoom_max);
} else { } else {
Window *w = GetMainWindow(); Window *w = GetMainWindow();
Viewport &vp = *w->viewport; Viewport &vp = *w->viewport;
while (vp.zoom > *level) DoZoomInOutWindow(ZOOM_IN, w); while (vp.zoom > zoom_lvl) DoZoomInOutWindow(ZOOM_IN, w);
while (vp.zoom < *level) DoZoomInOutWindow(ZOOM_OUT, w); while (vp.zoom < zoom_lvl) DoZoomInOutWindow(ZOOM_OUT, w);
} }
return true; return true;
} }