模块:Iconbar:修订间差异
来自RIA | Wiki
更多操作
debug |
无编辑摘要 |
||
| (未显示同一用户的3个中间版本) | |||
| 第11行: | 第11行: | ||
local title = args.title or '' | local title = args.title or '' | ||
local reverse = args.reverse or '' | local reverse = args.reverse or '' | ||
if not full then | if not full then | ||
| 第24行: | 第16行: | ||
end | end | ||
local titleAttr = '' | |||
if title:lower() == 'none' then | if title:lower() == 'none' then | ||
titleAttr = '' | |||
elseif title ~= '' then | elseif title ~= '' then | ||
titleAttr = ' title="' .. title .. '"' | |||
else | else | ||
local displayValue = (tonumber(args.value) or 0) | |||
titleAttr = ' title="' .. displayValue .. '"' | |||
end | end | ||
local sizeParam = '' | local sizeParam = '' | ||
if sizeValue ~= '' then | if sizeValue ~= '' then | ||
if tonumber(sizeValue) then | if tonumber(sizeValue) then | ||
sizeParam = '|' .. sizeValue .. 'px' | sizeParam = '|' .. sizeValue .. 'px' | ||
elseif sizeValue:match('em') then | |||
local emValue = tonumber(sizeValue:match('([%d%.]+)em')) or 1 | |||
local pixelSize = math.floor(emValue * 16) | |||
sizeParam = '|' .. pixelSize .. 'px' | |||
else | else | ||
sizeParam = '|' .. sizeValue | sizeParam = '|' .. sizeValue | ||
end | end | ||
else | else | ||
sizeParam = '|16px' | |||
end | end | ||
local fullIcon = '' | |||
local halfIcon = '' | |||
local emptyIcon = '' | |||
if value == 0 then | if value == 0 then | ||
emptyIcon = '[[File:' .. empty .. sizeParam .. ']]' | emptyIcon = '[[File:' .. empty .. sizeParam .. ']]' | ||
else | else | ||
local fullCount = math.floor(value) | local fullCount = math.floor(value) | ||
if fullCount > 0 then | if fullCount > 0 then | ||
fullIcon = string.rep('[[File:' .. full .. sizeParam .. ']]', fullCount) | fullIcon = string.rep('[[File:' .. full .. sizeParam .. ']]', fullCount) | ||
end | end | ||
if math.floor(value) ~= value then | if math.floor(value) ~= value then | ||
halfIcon = '[[File:' .. half .. sizeParam .. ']]' | halfIcon = '[[File:' .. half .. sizeParam .. ']]' | ||
end | end | ||
end | end | ||
local emptyCount = min - math.ceil(value) | local emptyCount = min - math.ceil(value) | ||
if emptyCount > 0 then | if emptyCount > 0 then | ||
emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount) | emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount) | ||
end | end | ||
if reverse ~= '' then | if reverse ~= '' then | ||
return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>' | |||
else | else | ||
return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>' | |||
end | end | ||
end | end | ||
return p | return p | ||
2025年9月24日 (三) 14:29的最新版本
此模板改编自Minecraft中文维基,原页面为mcwiki:模块:Iconbar。
local p = {}
function p.bar(frame)
local args = frame.args or {}
local full = args.full
local half = args.half or 'Half ' .. full
local empty = args.empty or 'Empty ' .. full
local value = math.abs(tonumber(args.value) or 0) / 2
local min = math.ceil(math.abs(tonumber(args.min) or 0) / 2)
local sizeValue = args.size or ''
local title = args.title or ''
local reverse = args.reverse or ''
if not full then
return '错误:缺少必需的full参数'
end
local titleAttr = ''
if title:lower() == 'none' then
titleAttr = ''
elseif title ~= '' then
titleAttr = ' title="' .. title .. '"'
else
local displayValue = (tonumber(args.value) or 0)
titleAttr = ' title="' .. displayValue .. '"'
end
local sizeParam = ''
if sizeValue ~= '' then
if tonumber(sizeValue) then
sizeParam = '|' .. sizeValue .. 'px'
elseif sizeValue:match('em') then
local emValue = tonumber(sizeValue:match('([%d%.]+)em')) or 1
local pixelSize = math.floor(emValue * 16)
sizeParam = '|' .. pixelSize .. 'px'
else
sizeParam = '|' .. sizeValue
end
else
sizeParam = '|16px'
end
local fullIcon = ''
local halfIcon = ''
local emptyIcon = ''
if value == 0 then
emptyIcon = '[[File:' .. empty .. sizeParam .. ']]'
else
local fullCount = math.floor(value)
if fullCount > 0 then
fullIcon = string.rep('[[File:' .. full .. sizeParam .. ']]', fullCount)
end
if math.floor(value) ~= value then
halfIcon = '[[File:' .. half .. sizeParam .. ']]'
end
end
local emptyCount = min - math.ceil(value)
if emptyCount > 0 then
emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount)
end
if reverse ~= '' then
return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>'
else
return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>'
end
end
return p