模块:Filename
1.38>牛腩面2022年7月6日 (三) 12:11的版本 (创建页面,内容为“-- <pre> local Filename = {} local lib = require('Module:Feature') function Filename.ability(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end return…)
此模块的文档可以在模块:Filename/doc创建
-- <pre>
local Filename = {}
local lib = require('Module:Feature')
function Filename.ability(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %s.png', args['ability'] or args[1], args['variant'] or args[2])
or
formatnil('%s.png', args['ability'] or args[1])
or
'Placeholder.svg')))
end
--placeholder for WR
function Filename.WRability(frame)
return Filename.ability(frame)
end
function Filename.buff(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s buff %s.png', args['buff'] or args[1], args['variant'] or args[2])
or
formatnil('%s buff.png', args['buff'] or args[1])
or
'Placeholder.svg')))
end
--placeholder for WR
function Filename.WRbuff(frame)
return Filename.buff(frame)
end
function Filename.championcircle(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sCircle %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sCircle.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'ChampionSquare.png')))
end
function Filename.WRchampioncircle(frame)
--return Filename.championcircle(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sCircle WR %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sCircle WR.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'ChampionSquare.png')))
end
function Filename.championsquare(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sSquare %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sSquare.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'ChampionSquare.png')))
end
function Filename.WRchampionsquare(frame)
--return Filename.championsquare(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sSquare WR %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sSquare WR.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'ChampionSquare.png')))
end
function Filename.chroma(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %s (%s) %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['chroma'] or args[3], args['variant'] or args[4])
or
formatnil('%s %s (%s).png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['chroma'] or args[3])
or
'Placeholder.svg')))
end
--placeholder for WR
function Filename.WRchroma(frame)
return Filename.chroma(frame)
end
function Filename.item(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
if (args['enchantment']) then
result = handleArgs(args, mw.text.trim(encode(
formatnil('%s (%s) item %s.png', args['item'] or args[1], args['enchantment'] or args[2], args['variant'] or args[3])
or
formatnil('%s (%s) item.png', args['item'] or args[1], args['enchantment'] or args[2])
or
'Placeholder.svg')))
else
result = handleArgs(args, mw.text.trim(encode(
formatnil('%s item %s.png', args['item'] or args[1], args['variant'] or args[2])
or
formatnil('%s item.png', args['item'] or args[1])
or
'Placeholder.svg')))
end
return result
end
function Filename.writem(frame)
return Filename.WRitem(frame)
end
function Filename.WRitem(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
if (args['enchantment']) then
result = handleArgs(args, mw.text.trim(encode(
formatnil('%s (Wild Rift) (%s) item %s.png', args['item'] or args[1], args['enchantment'] or args[2], args['variant'] or args[3])
or
formatnil('%s (Wild Rift) (%s) item.png', args['item'] or args[1], args['enchantment'] or args[2])
or
'Placeholder.svg')))
else
result = handleArgs(args, mw.text.trim(encode(
formatnil('%s (Wild Rift) item %s.png', args['item'] or args[1], args['variant'] or args[2])
or
formatnil('%s (Wild Rift) item.png', args['item'] or args[1])
or
'Placeholder.svg')))
end
return result
end
function Filename.loading(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sLoading %s.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sLoading.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'Champion SkinLoading.jpg')))
end
function Filename.WRloading(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sLoading WR %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sLoading WR.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'Champion SkinLoading.jpg')))
end
function Filename.render(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %s Render %s.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %s Render.png', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'Champion Render.png')))
end
function Filename.mastery(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s mastery %d.png', args['mastery'] or args[1], tonumber(args['season'] or args[2]))
or
'Placeholder.svg')))
end
function Filename.monster(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%sSquare %s.png', args['monster'] or args[1], args['variant'] or args[2])
or
formatnil('%sSquare.png', args['monster'] or args[1])
or
'Placeholder.svg')))
end
function Filename.profileicon(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s profileicon %s.png', args['profileicon'] or args[1], args['variant'] or args[2])
or
formatnil('%s profileicon.png', args['profileicon'] or args[1])
or
'Placeholder.svg')))
end
function Filename.rune(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s rune %s.png', args['rune'] or args[1], args['variant'] or args[2])
or
formatnil('%s rune.png', args['rune'] or args[1])
or
'Placeholder.svg')))
end
function Filename.WRrune(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s (Wild Rift) rune %s.png', args['rune'] or args[1], args['variant'] or args[2])
or
formatnil('%s (Wild Rift) rune.png', args['rune'] or args[1])
or
'Placeholder.svg')))
end
function Filename.runeold(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %s %d.png', args['stat'] or args[1], args['rune'] or args[2], tonumber(args['tier'] or args[3]))
or
'Placeholder.svg')))
end
function Filename.skin(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sSkin %s.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sSkin.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'Champion SkinSkin.jpg')))
end
function Filename.WRskin(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sSkin WR %s.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sSkin WR.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'Champion SkinSkin.jpg')))
end
function Filename.wrskin(frame)
return Filename.WRskin(frame)
end
function Filename.skincentered(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %sCentered %s.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''), args['variant'] or args[3])
or
formatnil('%s %sCentered.jpg', args['champion'] or args[1], string.gsub(args['skin'] or args[2] or 'Original', ' ', ''))
or
'Champion SkinSkin.jpg')))
end
function Filename.spell(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(
formatnil('%s %s.png', args['spell'] or args[1], args['variant'] or args[2])
or
formatnil('%s.png', args['spell'] or args[1])
or
'Placeholder.svg')))
end
function Filename.ward(frame)
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
return handleArgs(args, mw.text.trim(encode(formatnil('%s Ward.png', args['ward'] or args[1]) or 'Placeholder.svg')))
end
-- Helper functions
function Filename.encode(frame)
return mw.text.trim(encode(frame.args[1]))
end
function encode(text)
if text == nil then return nil end
text = mw.ustring.gsub(text, ':', '-')
text = mw.ustring.gsub(text, '/', '')
return text
end
function handleArgs(args, filename)
local result = filename
if args['prefix'] then filename = args['prefix'] .. filename end
if args['suffix'] then filename = filename .. args['suffix'] end
if args['parse'] then filename = mw.getCurrentFrame():preprocess(filename) end
return result
end
function formatnil(text, ...)
if select("#", ...) == 0 then return text end
for i=1, select("#", ...) do
if select(i, ...) == nil then return nil end
end
return mw.ustring.format(text, ...)
end
return Filename
-- </pre>
-- [[Category:Lua]]