模块:Iconbar:修订间差异
来自RIA | Wiki
更多操作
debug |
debug |
||
| 第2行: | 第2行: | ||
function p.bar(frame) | function p.bar(frame) | ||
local args = frame:getParent().args or {} | local args = frame:getParent().args or {} | ||
-- 先检查所有必需参数 | |||
if not args.full then | |||
local debug_info = "接收到的参数:" | |||
for k, v in pairs(args) do | |||
debug_info = debug_info .. k .. "=" .. tostring(v) .. ", " | |||
end | |||
return '错误:缺少必需的full参数。' .. debug_info | |||
end | |||
local full = args.full | local full = args.full | ||
local half = args.half or 'Half ' .. full | local half = args.half or 'Half ' .. full | ||
2025年9月24日 (三) 13:39的版本
此模板改编自Minecraft中文维基,原页面为mcwiki:模块:Iconbar。
local p = {}
function p.bar(frame)
local args = frame:getParent().args or {}
-- 先检查所有必需参数
if not args.full then
local debug_info = "接收到的参数:"
for k, v in pairs(args) do
debug_info = debug_info .. k .. "=" .. tostring(v) .. ", "
end
return '错误:缺少必需的full参数。' .. debug_info
end
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 size = args.size or ''
local title = args.title or ''
local reverse = args.reverse or ''
-- 添加调试信息
local debug_info = ""
for k, v in pairs(args) do
debug_info = debug_info .. k .. "=" .. tostring(v) .. ", "
end
-- 检查full参数
if not args.full then
return '错误:full参数为nil。接收到的参数:' .. debug_info
end
if title:lower() == 'none' then
title = ''
elseif title ~= '' then
title = ' title="' .. title .. '"'
else
title = ' title="' .. value .. '"'
end
local fullIcon = ''
local halfIcon = ''
local emptyIcon = ''
if tonumber( size ) then
size = '|' .. size .. 'px'
elseif size ~= '' then
size = '|' .. size
end
if value == 0 then
emptyIcon = '[[File:' .. empty .. size .. ']]'
else
fullIcon = string.rep( '[[File:' .. full .. size .. ']]', math.floor( value ) )
if math.floor( value ) ~= value then
halfIcon = '[[File:' .. half .. size .. ']]'
end
end
if min - value >= 1 then
emptyIcon = string.rep( '[[File:' .. empty .. size .. ']]', min - math.ceil( value ) )
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