模块:Iconbar:修订间差异
来自RIA | Wiki
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p.bar(frame) | 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 '' -- 改名为sizeValue避免冲突 | |||
local title = args.title or '' | |||
local reverse = args.reverse or '' | |||
if not full then | |||
return '错误:缺少必需的full参数' | |||
end | |||
if title:lower() == 'none' then | |||
title = '' | |||
elseif title ~= '' then | |||
title = ' title="' .. title .. '"' | |||
else | |||
title = ' title="' .. value .. '"' | |||
end | |||
local fullIcon = '' | |||
local halfIcon = '' | |||
local emptyIcon = '' | |||
-- 修复:使用新的变量存储文件参数 | |||
local sizeParam = '' | |||
if sizeValue ~= '' then | |||
if tonumber(sizeValue) then | |||
sizeParam = '|' .. sizeValue .. 'px' | |||
else | |||
sizeParam = '|' .. sizeValue -- 直接使用em等单位 | |||
end | |||
end | |||
-- 生成图标(使用sizeParam而不是sizeValue) | |||
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"' .. title .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>' | |||
else | |||
return '<span class="pixel-image nowrap"' .. title .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>' | |||
end | |||
end | end | ||
return p | return p | ||
2025年9月24日 (三) 14:10的版本
此模板改编自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 '' -- 改名为sizeValue避免冲突
local title = args.title or ''
local reverse = args.reverse or ''
if not full then
return '错误:缺少必需的full参数'
end
if title:lower() == 'none' then
title = ''
elseif title ~= '' then
title = ' title="' .. title .. '"'
else
title = ' title="' .. value .. '"'
end
local fullIcon = ''
local halfIcon = ''
local emptyIcon = ''
-- 修复:使用新的变量存储文件参数
local sizeParam = ''
if sizeValue ~= '' then
if tonumber(sizeValue) then
sizeParam = '|' .. sizeValue .. 'px'
else
sizeParam = '|' .. sizeValue -- 直接使用em等单位
end
end
-- 生成图标(使用sizeParam而不是sizeValue)
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"' .. title .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>'
else
return '<span class="pixel-image nowrap"' .. title .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>'
end
end
return p