打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

目前wiki关闭了自行注册账号的功能,如需注册账号,请查阅Help:注册账号

模块:Iconbar:修订间差异

来自RIA | Wiki
秋月白留言 | 贡献
无编辑摘要
秋月白留言 | 贡献
无编辑摘要
 
(未显示同一用户的6个中间版本)
第1行: 第1行:
local p = {}
local p = {}
function p.bar(frame)
function p.bar(frame)
local args = frame.args or {}
    local args = frame.args or {}
   
-- 先检查所有必需参数
    local full = args.full
     if not args.full then
    local half = args.half or 'Half ' .. full
         local debug_info = "接收到的参数:"
    local empty = args.empty or 'Empty ' .. full
         for k, v in pairs(args) do
    local value = math.abs(tonumber(args.value) or 0) / 2
             debug_info = debug_info .. k .. "=" .. tostring(v) .. ", "
    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
         end
         return '错误:缺少必需的full参数。' .. debug_info
    else
         sizeParam = '|16px'
     end
     end
      
      
local full = args.full
    local fullIcon = ''
local half = args.half or 'Half ' .. full
    local halfIcon = ''
local empty = args.empty or 'Empty ' .. full
    local emptyIcon = ''
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 ''


     -- 添加调试信息
     if value == 0 then
     local debug_info = ""
        emptyIcon = '[[File:' .. empty .. sizeParam .. ']]'
    for k, v in pairs(args) do
     else
         debug_info = debug_info .. k .. "=" .. tostring(v) .. ", "
        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
     end
      
      
     -- 检查full参数
     local emptyCount = min - math.ceil(value)
     if not args.full then
     if emptyCount > 0 then
         return '错误:full参数为nil。接收到的参数:' .. debug_info
         emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount)
     end
     end
      
      
if title:lower() == 'none' then
    if reverse ~= '' then
title = ''
        return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>'
elseif title ~= '' then
    else
title = ' title="' .. title .. '"'
        return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>'
else
    end
title = ' title="' .. value .. '"'
end
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
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