Make ctf_colors.get_color return a table (#35)

- The table includes the following fields:
  - `text`: Name of the color. e.g. `"red"`
  - `hex`: Hex-formatted color. e.g. `"0x00FFFF"`
  - `css`: CSS-style hex format. e.g. `"#FFFF00"`
This commit is contained in:
ANAND 2019-04-09 13:54:07 +05:30 committed by GitHub
parent 93ba341695
commit 3d5421ae7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 25 deletions

View File

@ -343,10 +343,10 @@ minetest.register_chatcommand("t", {
chatplus.log("<" .. name .. "> ** ".. param .. " **") chatplus.log("<" .. name .. "> ** ".. param .. " **")
end end
local color, colorHex = ctf_colors.get_color(ctf.player(name)) tcolor = ctf_colors.get_color(ctf.player(name))
for username, to in pairs(team.players) do for username, to in pairs(team.players) do
minetest.chat_send_player(username, minetest.chat_send_player(username,
minetest.colorize("#" .. colorHex:sub(3, 8), "<" .. name .. "> ** " .. param .. " **")) minetest.colorize(tcolor.css, "<" .. name .. "> ** " .. param .. " **"))
end end
if minetest.global_exists("irc") and irc.feature_mod_channel then if minetest.global_exists("irc") and irc.feature_mod_channel then
irc:say(irc.config.channel, tname .. "<" .. name .. "> ** " .. param .. " **", true) irc:say(irc.config.channel, tname .. "<" .. name .. "> ** " .. param .. " **", true)
@ -383,25 +383,25 @@ if minetest.global_exists("chatplus") then
end end
function chatplus.send_message_to_sender(from, msg) function chatplus.send_message_to_sender(from, msg)
local color, colorHex = ctf_colors.get_color(ctf.player(from)) local tcolor = ctf_colors.get_color(ctf.player(from))
minetest.chat_send_player(from, minetest.colorize("#" .. colorHex:sub(3, 8), "<" .. from .. "> ") .. msg) minetest.chat_send_player(from, minetest.colorize(tcolor.css, "<" .. from .. "> ") .. msg)
end end
chatplus.register_handler(function(from, to, msg) chatplus.register_handler(function(from, to, msg)
if not ctf.setting("chat.team_channel") then if not ctf.setting("chat.team_channel") then
-- Send to global -- Send to global
return nil return
end end
if ctf.setting("chat.default") ~= "team" then if ctf.setting("chat.default") ~= "team" then
local team_name = ctf.player(from).team local team_name = ctf.player(from).team
if team_name then if team_name then
local color, colorHex = ctf_colors.get_color(ctf.player(from)) local tcolor = ctf_colors.get_color(ctf.player(from))
minetest.chat_send_player(to, minetest.chat_send_player(to,
minetest.colorize("#" .. colorHex:sub(3, 8), "<" .. from .. "> ") .. msg) minetest.colorize(tcolor.css, "<" .. from .. "> ") .. msg)
return false return false
else else
return nil return
end end
end end
@ -441,9 +441,8 @@ else
end end
end end
local color, colorHex = ctf_colors.get_color(ctf.player(name)) local tcolor = ctf_colors.get_color(ctf.player(name))
local scolor = "#" .. colorHex:sub(3, 8) minetest.chat_send_all(minetest.colorize(tcolor.css, "<" .. name .. "> ") .. message)
minetest.chat_send_all(minetest.colorize(scolor, "<" .. name .. "> ") .. message)
return true return true
else else
return nil return nil
@ -454,8 +453,8 @@ else
minetest.registered_chatcommands["me"].func = function(name, param) minetest.registered_chatcommands["me"].func = function(name, param)
local team_name = ctf.player(name).team local team_name = ctf.player(name).team
if team_name then if team_name then
local color, colorHex = ctf_colors.get_color(ctf.player(name)) local tcolor = ctf_colors.get_color(ctf.player(name))
name = minetest.colorize("#" .. colorHex:sub(3, 8), "* " .. name) name = minetest.colorize(tcolor.css, "* " .. name)
else else
name = "* ".. name name = "* ".. name
end end

View File

@ -9,7 +9,13 @@ function ctf_colors.get_color(tplayer)
tcolor_hex = "0x000000" tcolor_hex = "0x000000"
end end
return tcolor_text, tcolor_hex local tcolor_css = "#" .. tcolor_hex:sub(3, 8)
return {
text = tcolor_text,
hex = tcolor_hex,
css = tcolor_css
}
end end
function ctf_colors.get_irc_color(tplayer) function ctf_colors.get_irc_color(tplayer)
@ -46,21 +52,19 @@ function ctf_colors.update(player, name, tplayer)
player = minetest.get_player_by_name(name) player = minetest.get_player_by_name(name)
end end
local tcolor_text, tcolor_hex = ctf_colors.get_color(tplayer) local tcolor = ctf_colors.get_color(tplayer)
if ctf.setting("colors.hudtint") then if ctf.setting("colors.hudtint") then
if tcolor_text == "red" or tcolor_text == "blue" then if tcolor.text == "red" or tcolor.text == "blue" then
print("tinting hud! " .. tcolor_hex) player:hud_set_hotbar_image("ctf_colors_hotbar_" .. tcolor.text .. ".png")
local tint_color = "#" .. string.sub(tcolor_hex, 3) player:hud_set_hotbar_selected_image("ctf_colors_hotbar_selected_" .. tcolor.text .. ".png")
player:hud_set_hotbar_image("ctf_colors_hotbar_" .. tcolor_text .. ".png")
player:hud_set_hotbar_selected_image("ctf_colors_hotbar_selected_" .. tcolor_text .. ".png")
else else
ctf.error("ctfcolors", "Hint color not supported for " .. tcolor_text) ctf.error("ctf_colors", "Hint color not supported for " .. tcolor.text)
end end
end end
if ctf.setting("colors.skins") and tcolor_text and tcolor_hex then if ctf.setting("colors.skins") and tcolor.text then
ctf_colors.set_skin(player, tcolor_text) ctf_colors.set_skin(player, tcolor.text)
end end
if ctf.setting("hud.teamname") then if ctf.setting("hud.teamname") then
@ -70,13 +74,13 @@ function ctf_colors.update(player, name, tplayer)
position = {x = 1, y = 0}, position = {x = 1, y = 0},
scale = {x = 100, y = 100}, scale = {x = 100, y = 100},
text = "Team " .. tplayer.team, text = "Team " .. tplayer.team,
number = tcolor_hex, number = tcolor.hex,
offset = {x = -20, y = 20}, offset = {x = -20, y = 20},
alignment = {x = -1, y = 0} alignment = {x = -1, y = 0}
}) })
else else
ctf.hud:change(player, "ctf:hud_team", "text", "Team " .. tplayer.team) ctf.hud:change(player, "ctf:hud_team", "text", "Team " .. tplayer.team)
ctf.hud:change(player, "ctf:hud_team", "number", tcolor_hex) ctf.hud:change(player, "ctf:hud_team", "number", tcolor.hex)
end end
end end
end end