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

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

模块:Iconbar:修订间差异

来自RIA | Wiki
秋月白留言 | 贡献
debug
秋月白留言 | 贡献
无编辑摘要
第11行: 第11行:
     local title = args.title or ''
     local title = args.title or ''
     local reverse = args.reverse or ''
     local reverse = args.reverse or ''
   
    -- 调试信息
    local debugInfo = {
        "调试信息:",
        "full: " .. tostring(full),
        "sizeValue: " .. tostring(sizeValue),
        "value: " .. tostring(value)
    }
      
      
     if not full then
     if not full then
第24行: 第16行:
     end
     end
      
      
    -- 处理标题
     if title:lower() == 'none' then
     if title:lower() == 'none' then
         title = ''
         title = ''
第32行: 第25行:
     end
     end
    
    
    local fullIcon = ''
    local halfIcon = ''
    local emptyIcon = ''
     -- 处理尺寸参数
     -- 处理尺寸参数
     local sizeParam = ''
     local sizeParam = ''
第41行: 第30行:
         if tonumber(sizeValue) then
         if tonumber(sizeValue) then
             sizeParam = '|' .. sizeValue .. 'px'
             sizeParam = '|' .. sizeValue .. 'px'
            table.insert(debugInfo, "sizeParam(数字): " .. sizeParam)
         else
         else
             sizeParam = '|' .. sizeValue
             sizeParam = '|' .. sizeValue
            table.insert(debugInfo, "sizeParam(单位): " .. sizeParam)
         end
         end
    else
        table.insert(debugInfo, "sizeParam: (空)")
     end
     end
      
      
    local fullIcon = ''
    local halfIcon = ''
    local emptyIcon = ''
     -- 生成图标
     -- 生成图标
     if value == 0 then
     if value == 0 then
         emptyIcon = '[[File:' .. empty .. sizeParam .. ']]'
         emptyIcon = '[[File:' .. empty .. sizeParam .. ']]'
        table.insert(debugInfo, "emptyIcon: " .. emptyIcon)
     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)
            table.insert(debugInfo, "fullIcon: " .. fullIcon)
         end
         end
          
          
         if math.floor(value) ~= value then
         if math.floor(value) ~= value then
             halfIcon = '[[File:' .. half .. sizeParam .. ']]'
             halfIcon = '[[File:' .. half .. sizeParam .. ']]'
            table.insert(debugInfo, "halfIcon: " .. halfIcon)
         end
         end
     end
     end
第71行: 第57行:
     if emptyCount > 0 then
     if emptyCount > 0 then
         emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount)
         emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount)
        table.insert(debugInfo, "emptyIcon(填充): " .. emptyIcon)
     end
     end
      
      
     local result
     -- 简化输出,移除span包装
     if reverse ~= '' then
     if reverse ~= '' then
         result = emptyIcon .. halfIcon .. fullIcon
         return emptyIcon .. halfIcon .. fullIcon
     else
     else
         result = fullIcon .. halfIcon .. emptyIcon
         return fullIcon .. halfIcon .. emptyIcon
     end
     end
   
    -- 返回调试信息 + 结果
    return table.concat(debugInfo, "<br>") .. "<br>结果:" .. result
end
end


return p
return p

2025年9月24日 (三) 14:14的版本

模块文档

此模板改编自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
    
    -- 处理标题
    if title:lower() == 'none' then
        title = ''
    elseif title ~= '' then
        title = ' title="' .. title .. '"'
    else
        title = ' title="' .. value .. '"'
    end
   
    -- 处理尺寸参数
    local sizeParam = ''
    if sizeValue ~= '' then
        if tonumber(sizeValue) then
            sizeParam = '|' .. sizeValue .. 'px'
        else
            sizeParam = '|' .. sizeValue
        end
    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
    
    -- 简化输出,移除span包装
    if reverse ~= '' then
        return emptyIcon .. halfIcon .. fullIcon
    else
        return fullIcon .. halfIcon .. emptyIcon
    end
end

return p