-- Module:Llsifitem -- Made with ♥ by User:Leranjun -- This module implements {{tl|Llsifitem}}. -- Please refrain from invoking this module directly. local p = {} local getArgs = require("Module:Arguments").getArgs local DATA = mw.loadData("Module:Llsifitem/data") local FILES = DATA.FILES local BORDER_KW = DATA.BORDER_KW local COLORS = DATA.COLORS local LEVELS = DATA.LEVELS local TABLEATTRS = DATA.TABLEATTRS local function notempty(s) return (s and s ~= "") end function p.main(frame) return p._main(getArgs(frame, {removeBlanks = false}), frame) end function p._main(args, frame) local arg1, arg2, arg3 = mw.ustring.lower(args[1] or ""), args[2], mw.ustring.lower(args[3] or "") local r = "" if (FILES[arg1]) then local data = FILES[arg1] if (data.aka) then data = FILES[data.aka] end local src = "" if (data.switch) then src = (data[data.switch[arg3]] or data[1]) else if (BORDER_KW[arg3] and data[2]) then src = data[2] else src = data[1] end end src = frame:callParserFunction("filepath", src .. ".png") r = r .. tostring(mw.html.create("img"):attr("src", src):css("width", "24px")) .. " " .. data.before local after = {} if (data.after[1]) then after = data.after else after[1] = data.after end if (arg2 ~= "0") then if (data.force2 or notempty(arg2)) then r = r .. arg2 .. after[1] else r = r .. (data.default or "1") .. after[1] end else if (data.force2) then r = r .. "{{{2}}}" end r = r .. (after[2] or "") end elseif (COLORS[arg1]) then local data = COLORS[arg1] if (data.aka) then data = COLORS[data.aka] end r = r .. frame:preprocess("[[File:sif" .. data[1] .. ".png|20px|link=]] ") r = r .. frame:expandTemplate {title = "color", args = {data[2], (arg2 or data[1])}} elseif (TABLEATTRS[arg1]) then r = TABLEATTRS[arg1] else local src = LEVELS[arg1] src = frame:callParserFunction("filepath", src .. ".png") r = r .. tostring(mw.html.create("img"):attr("src", src):css("width", "24px")) .. " " if (notempty(arg2) or notempty(arg3)) then local color = "" if (COLORS[mw.ustring.lower(arg2)]) then if (COLORS[mw.ustring.lower(arg2)].aka) then color = COLORS[COLORS[mw.ustring.lower(arg2)].aka][2] else color = COLORS[mw.ustring.lower(arg2)][2] end elseif (COLORS[arg3]) then if (COLORS[arg3].aka) then color = COLORS[COLORS[arg3].aka][2] else color = COLORS[arg3][2] end else color = "black" end local content = "" if (COLORS[arg3]) then content = frame:preprocess("'''" .. arg2 .. "'''") else content = frame:preprocess("'''" .. arg3 .. "'''") end r = r .. frame:expandTemplate {title = "color", args = {color, content}} end end return r end return p