From eac08bd05facbfba8c2a1359dcd1fe5ee0b05f38 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Thu, 2 Sep 2021 00:01:54 -0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Extract=20health=20bar=20b?= =?UTF-8?q?order=20color=20by=20monster=20type=20logic=20into=20local=20fu?= =?UTF-8?q?nction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This eliminates direct array indexing by an enum which allows us to move into enum class without casting. --- Source/qol/monhealthbar.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index 2d14c12e8..56325b6e4 100644 --- a/Source/qol/monhealthbar.cpp +++ b/Source/qol/monhealthbar.cpp @@ -83,9 +83,24 @@ void DrawMonsterHealthBar(const Surface &out) DrawArt(out, position + Displacement { border + 1, border + 1 }, &health, 0, barProgress, height - (border * 2) - 2); } + constexpr auto getBorderColor = [](_mc_id monsterClass) { + switch (monsterClass) { + case MC_UNDEAD: + return 248; + + case MC_DEMON: + return 232; + + case MC_ANIMAL: + return 150; + + default: + app_fatal("Invalid monster class '%i'.", monsterClass); + } + }; + if (sgOptions.Gameplay.bShowMonsterType) { - Uint8 borderColors[] = { 248 /*undead*/, 232 /*demon*/, 150 /*beast*/ }; - Uint8 borderColor = borderColors[monster.MData->mMonstClass]; + Uint8 borderColor = getBorderColor(monster.MData->mMonstClass); int borderWidth = width - (border * 2); UnsafeDrawHorizontalLine(out, { position.x + border, position.y + border }, borderWidth, borderColor); UnsafeDrawHorizontalLine(out, { position.x + border, position.y + height - border - 1 }, borderWidth, borderColor);