跳转到内容

模块:物品收集度

来自Wymbot 共创站
NotBot​(留言 | 贡献)2026年10月24日 (六) 12:01的版本 (建立模块化物品展示及用户提供的测试数据(不迁移旧掉落))
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在模块:物品收集度/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, '这啥?') .. 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
    for _, entry in ipairs(result.entries or {}) do
        if entry.status ~= 'none' then
            local text = entry.status == 'known' and C.literal(entry.text) or '具体信息待补充。'
            parts[#parts + 1] = '<div class="mw-collapsible mw-collapsed wum-item-collection-entry">\n<div class="wum-item-collection-heading">收集度达到 ' .. entry.level .. '%</div>\n<div class="mw-collapsible-content wum-item-literal">' .. text .. '</div>\n</div>'
        end
    end
    if #parts == 0 then parts[1] = '收集度信息待补充。' end
    return C.finish(c, 'collection', C.heading(c, '这啥?') .. table.concat(parts, '\n'), cats)
end
return p