跳转到内容

模块:物品收集度

来自Wymbot 共创站
NotBot​(留言 | 贡献)2026年10月24日 (六) 12:37的版本 (恢复旧站紧凑灰底收集度折叠表格,修复来源表其他单元格的异常段落间距)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在模块:物品收集度/doc创建

local C = require('模块:物品通用')
local D = require('模块:物品数据')
local p = {}
local function classify(result)
    local cats, pending = {}, result.status == 'pending'
    if result.status == 'none' then cats[#cats + 1] = '没有收集度信息的物品' end
    for _, entry in ipairs(result.entries or {}) do
        if entry.status == 'pending' then pending = true end
        if entry.level == 500 or entry.level == 10000 then
            if entry.status == 'known' then cats[#cats + 1] = '有' .. entry.level .. '%收集度信息的物品'
            elseif entry.level == 500 and entry.status == 'none' then cats[#cats + 1] = '没有500%收集度信息的物品' end
        end
    end
    if pending then cats[#cats + 1] = '物品收集度信息待完善的页面' end
    return cats
end
function p.main(frame)
    local c = C.context(frame)
    if not c.enabled then return '' end
    local selected = c.option('收集度档位', '')
    local result = D.getCollection(c.name, selected)
    local overall = selected ~= '' and D.getCollection(c.name, '') or result
    local parts = {}
    if result.status == 'error' or overall.status == 'error' then
        return C.finish(c, 'collection', C.heading(c, '这啥?', 3) .. C.diagnostic(result.status == 'error' and result or overall), { '物品数据异常的页面' })
    end
    local cats = classify(overall)
    if result.status == 'none' then return C.categories(c, cats) end
    local entries = result.entries or {}
    if #entries == 0 then
        entries = { { level = 100, status = 'pending' }, { level = 300, status = 'pending' }, { level = 500, status = 'pending' } }
    end
    for _, entry in ipairs(entries) do
        if entry.status == 'known' or (entry.status ~= 'none' and (entry.level == 100 or entry.level == 300)) then
            local text = entry.status == 'known' and C.literal(entry.text) or '具体信息还不是很清楚,多收集几个试试?<sup>[待完善]</sup>'
            parts[#parts + 1] = '<table class="wikitable mw-collapsible mw-collapsed wum-item-collection-entry">\n<tr><th class="wum-item-collection-heading">收集度达到' .. entry.level .. '%</th></tr>\n<tr><td class="wum-item-literal">' .. text .. '</td></tr>\n</table>'
        end
    end
    if #parts == 0 then return C.categories(c, cats) end
    return C.finish(c, 'collection', C.heading(c, '这啥?', 3) .. table.concat(parts, '\n'), cats)
end
return p