此模块的文档可以在Module:Icon/doc创建
local p = {}
local base = require("Module:Base")
local hero_data = mw.loadData('Module:hero.data')
-- 对外调用版本
function p.classicon(frame)
local class_en = {
['剑士'] = 'Warrior',
['骑士'] = 'Paladin',
['猎人'] = 'Hunter',
['弓手'] = 'Archer',
['法师'] = 'Wizard',
['祭司'] = 'Priest'
}
local class = frame.args[1] -- 职业
if not class_en[class] then
return "module:icon.classicon error:职业名称错误"
end
local args_list = {
['size'] = 'm', -- 大小(s m l)
['name'] = nil, -- name显示名字,否则只有图标
['link'] = nil, -- 图标和名字上会有链接
['bg'] = nil, -- 图标背后会有黑色背景
['linkpage'] = frame.args[2] or '', -- 当有链接时,可以自定义链接到的页面名称
}
for key, arg in ipairs(frame.args) do
if (arg == 's' or arg == 'm' or arg == 'l') then
args_list['size'] = arg
elseif (arg == 'name' or arg == 'link' or arg == 'bg') then
args_list[arg] = true
end
end
if args_list['linkpage'] == '' then
args_list['linkpage'] = class
end
local output_text = {}
output_text[#output_text+1] = '<span class="class_icon">'
output_text[#output_text+1] = '<span class="icon_'..args_list['size']
if args_list['bg'] then
output_text[#output_text+1] = ' bg'
end
output_text[#output_text+1] = '">'
output_text[#output_text+1] = '[[File:'..class_en[class]..'_icon_'..args_list['size']..'.png|link='
if args_list['link'] then
output_text[#output_text+1] = args_list['linkpage']
end
output_text[#output_text+1] = ']]</span>'
if args_list['name'] then
output_text[#output_text+1] = '<span class="class_name">'
if args_list['link'] then
output_text[#output_text+1] = '[['..args_list['linkpage']..'|'..class..']]'
else
output_text[#output_text+1] = class
end
output_text[#output_text+1] = '</span>'
end
output_text[#output_text+1] = '</span>'
return table.concat(output_text)
end
-- 改为其他Lua函数调用
function p.class(frame)
local class = frame.args[1]
local size = frame.args[2] or 'm'
local text = frame.args[3] or ''
local url = frame.args[4] or class
if text == true or text == 'full' or text == 'text' or text == 'name' then
text = 'text'
elseif text == 'url' then
text = 'url'
else
text = ''
end
local output_text = {}
local class_en = {
['剑士'] = 'Warrior',
['骑士'] = 'Paladin',
['猎人'] = 'Hunter',
['弓手'] = 'Archer',
['法师'] = 'Wizard',
['祭司'] = 'Priest'
}
output_text[#output_text+1] = '<span class="class_icon icon_'..size..'">'
output_text[#output_text+1] = '[[File:'..class_en[class]..'_icon_'..size..'.png|link='..url..']]'
if text == 'text' then
output_text[#output_text+1] = '<span class="class_name">'..class..'</span>'
elseif text == 'url' then
output_text[#output_text+1] = '<span class="class_name">[['..class..']]</span>'
end
output_text[#output_text+1] = '</span>'
return table.concat(output_text)
end
function p.res(frame)
local name = frame.args[1]
local text = frame.args[2] or ''
if text == true or text == 'full' or text == 'text' then
text = true
else
text = false
end
local res_list = {
['金币'] = {file='Gold'},
['宝石'] = {file='Diamond'},
['肉'] = {file='Meat'},
['面包'] = {file='Bread'},
['荣誉'] = {file='Honor'},
['钥匙'] = {file='Key'},
['铁'] = {file='Iron'},
['水晶粉末'] = {file='CrystalPowder',link='水晶'},
['水晶碎片'] = {file='CrystalShard',link='水晶'},
['水晶结晶'] = {file='Crystal',link='水晶'},
['武器'] = {file='Weapon'},
['勇士'] = {file='Hero'},
['竞技场入场卷'] = {file='ColosseumTicket',link='竞技场'},
['地图碎片'] = {file='Map'},
['果实'] = {file='Fruit'},
}
local output_text = {}
if res_list[name] then
output_text[#output_text+1] = '<span class="res_icon">'
if res_list[name]['link'] then
--output_text[#output_text+1] = '[[File:'..res_list[name]['file'] ..'.png|link='..res_list[name]['link']..'|'..name..']]'
output_text[#output_text+1] = '[[File:'..res_list[name]['file'] ..'.png|link=|'..name..']]'
else
--output_text[#output_text+1] = '[[File:'..res_list[name]['file'] ..'.png|link='..name..']]'
output_text[#output_text+1] = '[[File:'..res_list[name]['file'] ..'.png|link=|'..name..']]'
end
output_text[#output_text+1] = '</span>'
if text then
if res_list[name]['link'] then
--output_text[#output_text+1] = '[['..res_list[name]['link']..'|'..name..']]'
output_text[#output_text+1] = '<span>'..name..'</span>'
else
--output_text[#output_text+1] = '[['..name..']]'
output_text[#output_text+1] = '<span>'..name..'</span>'
end
end
end
return table.concat(output_text)
end
function p.star(frame)
local num = frame.args[1]
local text = frame.args[2] or ''
if text == true or text == 'full' or text == 'text' then
text = true
else
text = false
end
output_text = {}
output_text[#output_text+1] = '<span class="star_icon">'
if text then
output_text[#output_text+1] = '[[File:star.png|link=]]</span><span style="margin-left:2px">'..num..'</span>'
else
for i = 1,tonumber(num) do
output_text[#output_text+1] = '[[File:star.png|link=]]'
end
output_text[#output_text+1] = '</span>'
end
return table.concat(output_text)
end
function p.score(frame)
local normal = frame.args[1]
local plus = frame.args[2] or 0
normal = tonumber(normal)
plus = tonumber(plus)
if not normal then normal = 0 end
if not plus then plus = 0 end
if normal <= 0 then normal = 0 end
if normal > 5 then normal = 5 end
if plus ~= 0 then
if plus < normal then plus = normal end
if plus > 5 then plus = 5 end
end
output_text = {}
output_text[#output_text+1] = '<span class="star_icon">'
for i = 1, normal do
output_text[#output_text+1] = '[[File:star.png|link=]]'
end
if plus > normal then
diff = plus - normal
for i = 1, diff do
output_text[#output_text+1] = '[[File:plus_star.png|link=]]'
end
end
output_text[#output_text+1] = '</span>'
return table.concat(output_text)
end
function p.hero(frame)
local heroname = frame.args[1]
local size = frame.args[2] or 'm'
local full = frame.args[3] or '' -- 使用name或是full会显示名字
output_text = {}
size_list = {s='20',m='30',l='72'}
-- 图片链接
img_text = '[[File:'..heroname..'_icon.png|'..size_list[size]..'px|link='..heroname..'|★'..hero_data[heroname]['r']..' '..heroname..']]'
-- 移动端下的名字文本和链接,web端当第三个参数为name时也会显示
name_text = '[['..heroname..'|★'..hero_data[heroname]['r']..' '..heroname..']]'
if size ~= 'l' then
output_text[#output_text+1] = img_text
if (full == 'name' or full == 'full') then
output_text[#output_text+1] = ' '..name_text
end
else
local class = hero_data[heroname]['c']
output_text[#output_text+1] = '<div class="hero_icon">'..img_text
output_text[#output_text+1] = '<div class="star">'..hero_data[heroname]['r']..'</div>'
output_text[#output_text+1] = p.class{args={class, 's','',heroname}}
output_text[#output_text+1] = '</div>'
if (full == 'name' or full == 'full') then
output_text[#output_text+1] = ' [['..heroname..']]'
end
end
return table.concat(output_text)
end
return p