From 8cf0a1648b6c984ac2ba160ee1bb81ea5106a36f Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 5 May 2020 10:07:37 -0700 Subject: [PATCH] Enforce stricter type compliance for HUD elements (#602) --- mods/ctf/ctf_colors/hud.lua | 6 +++--- mods/ctf/ctf_flag/hud.lua | 16 ++++++++-------- mods/ctf/ctf_marker/init.lua | 2 +- mods/pvp/hud_score/init.lua | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mods/ctf/ctf_colors/hud.lua b/mods/ctf/ctf_colors/hud.lua index 70948a2..2ea64d5 100644 --- a/mods/ctf/ctf_colors/hud.lua +++ b/mods/ctf/ctf_colors/hud.lua @@ -6,14 +6,14 @@ function ctf_colors.get_color(tplayer) end local tcolor_hex = ctf.flag_colors[tcolor_text] if not tcolor_hex then - tcolor_hex = "0x000000" + tcolor_hex = 0x000000 end - local tcolor_css = "#" .. tcolor_hex:sub(3, 8) + local tcolor_css = "#" .. tostring(tcolor_hex):sub(3, 8) return { text = tcolor_text, - hex = tcolor_hex, + hex = tonumber(tcolor_hex), css = tcolor_css } end diff --git a/mods/ctf/ctf_flag/hud.lua b/mods/ctf/ctf_flag/hud.lua index 2eee563..f2ee301 100644 --- a/mods/ctf/ctf_flag/hud.lua +++ b/mods/ctf/ctf_flag/hud.lua @@ -5,9 +5,9 @@ ctf.hud.register_part(function(player, name, tplayer) for _, flag in pairs(team.flags) do local hud = "ctf:hud_" .. tname local flag_name = flag.name or tname .. "'s base" - local color = ctf.flag_colors[team.data.color] + local color = tonumber(ctf.flag_colors[team.data.color]) if not color then - color = "0x000000" + color = 0x000000 end if ctf.hud:exists(player, hud) then @@ -36,7 +36,7 @@ end) ctf.hud.register_part(function(player, name, tplayer) -- Check all flags local alert = nil - local color = "0xFFFFFF" + local color = 0xFFFFFF if ctf.setting("flag.alerts") then if ctf.setting("flag.alerts.neutral_alert") then alert = "Punch the enemy flag! Protect your flag!" @@ -55,22 +55,22 @@ ctf.hud.register_part(function(player, name, tplayer) if teamHolder == name then if enemyHolder then alert = "You can't capture the flag until " .. enemyHolder .. " is killed!" - color = "0xFF0000" + color = 0xFF0000 else alert = "You've got the flag! Run back and punch your flag!" - color = "0xFF0000" + color = 0xFF0000 end elseif teamHolder then if enemyHolder then alert = "Kill " .. enemyHolder .. " to allow " .. teamHolder .. " to capture the flag!" - color = "0xFF0000" + color = 0xFF0000 else alert = "Protect " .. teamHolder .. ", they've got the enemy flag!" - color = "0xFF0000" + color = 0xFF0000 end elseif enemyHolder then alert = "Kill " .. enemyHolder .. ", they've got your flag!" - color = "0xFF0000" + color = 0xFF0000 end end diff --git a/mods/ctf/ctf_marker/init.lua b/mods/ctf/ctf_marker/init.lua index 36e2eb2..ac69786 100644 --- a/mods/ctf/ctf_marker/init.lua +++ b/mods/ctf/ctf_marker/init.lua @@ -44,7 +44,7 @@ local function add_marker(name, tname, pos, str) teams[tname].players[pname] = tplayer:hud_add({ hud_elem_type = "waypoint", name = str, - number = ctf.flag_colors[team.data.color], + number = tonumber(ctf.flag_colors[team.data.color]), world_pos = pos }) end diff --git a/mods/pvp/hud_score/init.lua b/mods/pvp/hud_score/init.lua index 61d621f..62acea3 100644 --- a/mods/pvp/hud_score/init.lua +++ b/mods/pvp/hud_score/init.lua @@ -27,7 +27,7 @@ local function update(name) for i, def in ipairs(temp) do -- If not the top-most element, prefix with "+ " - local text = def.value + local text = tostring(def.value) if i > 1 then text = "+ " .. text end @@ -41,7 +41,7 @@ local function update(name) alignment = {x = 0, y = 0}, position = {x = 0.5, y = 0.6}, offset = {x = 0, y = i * 20}, - number = def.color, + number = tonumber(def.color), text = text }) end