Mô đun:Basketball color

--
-- Mô đun này thực hiện
-- {{NBA color}}, {{NBA color cell}}, {{NBA color cell2}}
-- {{Euroleague color}}, {{Euroleague color cell}}, {{Euroleague color cell2}}, 
-- {{NBL colour}}, {{NBL colour cell}}, {{NBL colour cell2}},
-- {{PBA color}}, {{PBA color cell}}, {{PBA color cell2}},
-- {{European leagues color}}, {{European leagues color cell}}, {{European leagues color cell2}},
-- {{KBL color}}, {{KBL color cell}}, {{KBL color cell2}}
--
local p = {}

local data_module = "Mô đun:Basketball color/data"

local function stripwhitespace(text)
	return text:match("^%s*(.-)%s*$")
end

local function get_colors(team, unknown)
	team = stripwhitespace(team or '')
	unknown = unknown or {"DCDCDC", "000000", "000000", "FFFFFF"}
	
	local use_default = {
		[""] = 1,
		["retired"] = 1,
		["free agent"] = 1,
	}
	
	local colors = nil
	
	if ( team and use_default[team:lower()] ) then
		colors = {"DCDCDC", "000000", "DCDCDC", "FFFFFF"}
	else
		local all_colors = mw.loadData(data_module)
		colors = all_colors[team]
		if ( colors and type(colors) == 'string' ) then
			colors = all_colors[colors]
		end
	end

	return colors or unknown
end

local function team_color(team, num)
	local colors = get_colors(team, nil)

	num = tonumber(num:match('[1-4]') or '0')
	if ( num ) then
		return colors[num]
	else
		return ''
	end
end

local function bordercss(c, w)
	local s = 'inset ' .. w .. 'px ' .. w .. 'px 0 #' .. c 
		.. ', inset -' .. w .. 'px -' .. w .. 'px 0 #' .. c
	return '-moz-box-shadow: ' .. s .. '; -webkit-box-shadow: ' .. s .. '; box-shadow: ' .. s .. ';'
end

local function team_colorcell(team, borderwidth, bg, fg, bd, simple)
	local colors = get_colors(team, nil)
	local border = ''
	borderwidth = borderwidth or ''
	
	if (borderwidth ~= '') then
		if simple then
			border = 'border:' .. borderwidth .. 'px solid #' .. stripwhitespace(colors[bd]) .. ';'
		else
			border = bordercss(stripwhitespace(colors[bd]), borderwidth)
		end
	end
	
	return 'background-color:#' .. stripwhitespace(colors[bg]) .. ';color:#' .. stripwhitespace(colors[fg]) .. ';' .. border
end

local function team_check(team, unknown)
	local colors = get_colors(team, unknown)
	if type(colors) == 'table' then
		return 'known'
	else
		return unknown
	end
end

function p.color(frame)
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
	return team_color(args[1] or '', args[2] or '')
end

function p.colorcell(frame)
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
	return team_colorcell(args[1] or '', args['border'] or '', 1, 2, 3, args['simple'] and 1 or nil )
end

function p.colorcell2(frame)
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
	return team_colorcell(args[1] or '', args['border'] or '', 3, 4, 1, args['simple'] and 1 or nil )
end

function p.check(frame)
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
	return team_check(args[1] or '', args[2] or '')
end

return p
Chúng tôi bán
Bài viết liên quan
Nhân vật Erga Kenesis Di Raskreia trong Noblesse
Nhân vật Erga Kenesis Di Raskreia trong Noblesse
Erga Kenesis Di Raskreia (Kor. 에르가 케네시스 디 라스크레아) là Lãnh chúa hiện tại của Quý tộc. Cô ấy được biết đến nhiều hơn với danh hiệu Lord hơn là tên của cô ấy.
Một góc nhìn, quan điểm về Ngự tam gia, Tengen, Sukuna và Kenjaku
Một góc nhìn, quan điểm về Ngự tam gia, Tengen, Sukuna và Kenjaku
Ngự tam gia là ba gia tộc lớn trong chú thuật hồi chiến, với bề dày lịch sử lâu đời, Ngự Tam Gia - Zenin, Gojo và Kamo có thể chi phối hoạt động của tổng bộ chú thuật
Chàng Trai Khắc Kỷ Sẽ Sống Như Thế Nào?
Chàng Trai Khắc Kỷ Sẽ Sống Như Thế Nào?
Trước khi bắt đầu mình muốn bạn đọc nhập tâm là người lắng nghe thằng homie kể về người thứ 3
Enkanomiya rơi xuống từ… trên trời
Enkanomiya rơi xuống từ… trên trời
Nhiều người nghĩ Enkanomiya rơi từ trên mặt biển Inazuma xuống khi Vị thứ nhất và Vị thứ hai hỗn chiến