Module:Sandbox/Ahecht/Gridiron color: Difference between revisions

Content deleted Content added
 
simplify, make more robust
 
(3 intermediate revisions by the same user not shown)
Line 22:
 
local function get_year(colors, year)
year = tonumber(year)
if year and (year > 0) and colors and colors[6] and type(colors[6] == 'table') then
for team, year_colors in pairs(colors[6]) do
local end_year = nil
if mw.ustring.find(team, "%d%d%d%dthru%d%d%d%d$") then
for team, year_colorsk in pairs(colors[6]) do
local start_year, end_year = mw.ustring.match(team, "(%d%d%d%d)thru(%d%d%d%d)$")
if (tonumber(start_year)year <= tonumber(year)k) and (tonumber(year)k <= tonumber(end_year or 32767)) then end_year = k end
return year_colors
end
end
end
if end_year then return colors[6][end_year] end
end
Line 69 ⟶ 67:
end
colors = get_year(color_data[team], year)
if year and year > 0 then
--code for handling year parameter
colors = get_year(color_data[team], year)
else
colors = color_data[team]
end
if ( colors and type(colors) == 'string' ) then
Line 94 ⟶ 87:
local args = frame.args.team and frame.args or frame:getParent().args
local colors = get_colors((args.team or args[1]), nil, args.year)
return '["' .. args.team .. '"] = {{ "' .. colors[1] .. '", '.. colors[2] ..
'", '.. colors[3] .. '", '.. colors[4] .. '", '.. colors[5] .. '"}}'
end