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

View File

@ -9,7 +9,13 @@ function ctf_colors.get_color(tplayer)
tcolor_hex = "0x000000"
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
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)
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 tcolor_text == "red" or tcolor_text == "blue" then
print("tinting hud! " .. tcolor_hex)
local tint_color = "#" .. string.sub(tcolor_hex, 3)
player:hud_set_hotbar_image("ctf_colors_hotbar_" .. tcolor_text .. ".png")
player:hud_set_hotbar_selected_image("ctf_colors_hotbar_selected_" .. tcolor_text .. ".png")
if tcolor.text == "red" or tcolor.text == "blue" then
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
ctf.error("ctfcolors", "Hint color not supported for " .. tcolor_text)
ctf.error("ctf_colors", "Hint color not supported for " .. tcolor.text)
end
end
if ctf.setting("colors.skins") and tcolor_text and tcolor_hex then
ctf_colors.set_skin(player, tcolor_text)
if ctf.setting("colors.skins") and tcolor.text then
ctf_colors.set_skin(player, tcolor.text)
end
if ctf.setting("hud.teamname") then
@ -70,13 +74,13 @@ function ctf_colors.update(player, name, tplayer)
position = {x = 1, y = 0},
scale = {x = 100, y = 100},
text = "Team " .. tplayer.team,
number = tcolor_hex,
number = tcolor.hex,
offset = {x = -20, y = 20},
alignment = {x = -1, y = 0}
})
else
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