跳转到内容

模块:物品产出:修订间差异

来自Wymbot 共创站
NotBot​(留言 | 贡献)
建立模块化物品展示及用户提供的测试数据(不迁移旧掉落)
 
NotBot​(留言 | 贡献)
掉落最小/最大数量支持字符串原文显示,保留数字排序与数值范围校验;同步使用文档
 
(未显示同一用户的2个中间版本)
第2行: 第2行:
local D = require('模块:物品数据')
local D = require('模块:物品数据')
local p = {}
local p = {}
local function numberCell(value, display)
    -- Only real numbers get numeric sort keys; text stays literal and blanks stay blank.
    local key = type(value) == 'number' and tostring(value) or ''
    local text = display or (value ~= nil and C.literal(value) or '')
    return 'data-sort-value="' .. key .. '" | ' .. text
end
function p.main(frame)
function p.main(frame)
     local c = C.context(frame)
     local c = C.context(frame)
第11行: 第19行:
     end
     end
     local rows = {}
     local rows = {}
    local showDetails = result.kind == 'travel' or result.kind == 'planting'
     for _, entry in ipairs(result.entries) do
     for _, entry in ipairs(result.entries) do
         rows[#rows + 1] = '|-\n| ' .. C.link(entry.item) .. ' || ' .. C.probability(entry)
         local cells = { C.link(entry.item) }
        if showDetails then
            cells[#cells + 1] = numberCell(entry.probabilityStatus == 'known' and entry.probability or nil, C.probability(entry))
            cells[#cells + 1] = numberCell(entry.minQuantity)
            cells[#cells + 1] = numberCell(entry.maxQuantity)
            cells[#cells + 1] = C.literal(entry.note or '')
        end
        rows[#rows + 1] = '|-\n| ' .. table.concat(cells, ' || ')
     end
     end
     return C.finish(c, 'outputs', C.heading(c, '会掉什么?') ..
    local headers = '! 物品'
         '{| class="wikitable wum-item-table"\n! 物品 !! 掉落概率\n' .. table.concat(rows, '\n') .. '\n|}')
    if showDetails then
        headers = headers .. ' !! data-sort-type="number" | 掉落概率' ..
            ' !! data-sort-type="number" | 最小掉落数 !! data-sort-type="number" | 最大掉落数 !! 备注'
    end
     return C.finish(c, 'outputs', C.heading(c, result.kind == 'shop' and '可购买物品' or '会掉什么?') ..
         '{| class="wikitable' .. (showDetails and ' sortable' or '') .. ' wum-item-table"\n' .. headers .. '\n' .. table.concat(rows, '\n') .. '\n|}')
end
end
return p
return p

2026年11月4日 (三) 23:09的最新版本

此模块的文档可以在模块:物品产出/doc创建

local C = require('模块:物品通用')
local D = require('模块:物品数据')
local p = {}

local function numberCell(value, display)
    -- Only real numbers get numeric sort keys; text stays literal and blanks stay blank.
    local key = type(value) == 'number' and tostring(value) or ''
    local text = display or (value ~= nil and C.literal(value) or '')
    return 'data-sort-value="' .. key .. '" | ' .. text
end

function p.main(frame)
    local c = C.context(frame)
    if not c.enabled then return '' end
    local result = D.getOutputs(c.name)
    if result.status == 'pending' or result.status == 'none' then return '' end
    if result.status == 'error' then
        return C.finish(c, 'outputs', C.heading(c, '会掉什么?') .. C.diagnostic(result), { '物品数据异常的页面' })
    end
    local rows = {}
    local showDetails = result.kind == 'travel' or result.kind == 'planting'
    for _, entry in ipairs(result.entries) do
        local cells = { C.link(entry.item) }
        if showDetails then
            cells[#cells + 1] = numberCell(entry.probabilityStatus == 'known' and entry.probability or nil, C.probability(entry))
            cells[#cells + 1] = numberCell(entry.minQuantity)
            cells[#cells + 1] = numberCell(entry.maxQuantity)
            cells[#cells + 1] = C.literal(entry.note or '')
        end
        rows[#rows + 1] = '|-\n| ' .. table.concat(cells, ' || ')
    end
    local headers = '! 物品'
    if showDetails then
        headers = headers .. ' !! data-sort-type="number" | 掉落概率' ..
            ' !! data-sort-type="number" | 最小掉落数 !! data-sort-type="number" | 最大掉落数 !! 备注'
    end
    return C.finish(c, 'outputs', C.heading(c, result.kind == 'shop' and '可购买物品' or '会掉什么?') ..
        '{| class="wikitable' .. (showDetails and ' sortable' or '') .. ' wum-item-table"\n' .. headers .. '\n' .. table.concat(rows, '\n') .. '\n|}')
end
return p