“模块:NewCraftsCN/Sandbox”的版本间的差异

来自维阿百科
跳转至: 导航搜索
1.38>牛腩面
(导入1个版本)
 
(导入1个版本)
 
(没有差异)

2022年7月8日 (五) 21:15的最新版本

此模块的文档可以在模块:NewCraftsCN/Sandbox/doc创建

local p = {}

function p.show(frame)
    local function ce_list(key)
        local res_list = {}
        local list0 = mw.text.split(frame:callParserFunction{name = '#lst:用户:Uksin/lab', args = {key}}, ',', true)
        for _, id in ipairs(list0) do
            if id ~= "" then
                res_list[tonumber(id)] = true
            end
        end
        return res_list
    end

    local n_ce0 = tonumber(frame:callParserFunction{name = '#lst:用户:Uksin/lab', args = {'cnprevces'}})
    local n_ce1 = tonumber(frame:callParserFunction{name = '#lst:用户:Uksin/lab', args = {'cnces'}})
    local ex_ce0 = ce_list('cnprevskippedces')
    local ex_ce1 = ce_list('cnskippedces')
    local in_ce0 = ce_list('cnprevaheadces')
    local in_ce1 = ce_list('cnaheadces')

    local id_display = {}
    for id = n_ce0 + 1, n_ce1 do
        if not ex_ce1[id] then table.insert(id_display, id) end
    end
    for id, _ in pairs(in_ce1) do
        if id > n_ce1 and (not in_ce0[id]) then table.insert(id_display, id) end
    end
    for id, _ in pairs(ex_ce0) do
        if id <= n_ce0 and (not ex_ce1[id]) then table.insert(id_display, id) end
    end

    local t_name = (#id_display > 7) and "新增卡牌/礼装小图标" or "新增卡牌/礼装大图标"
    table.sort(id_display)

    local ce_links = mw.text.split(frame:callParserFunction{name = string.format('#ask:[[分类:礼装图鉴]][[礼装序号::>>%d]][[礼装序号::<%d]]', n_ce0, n_ce1), args = {link = 'none', limit = 500, sort = '礼装序号'}}, ',', true)
    if #ce_links ~= n_ce1 - n_ce0 then ce_links = {} end

    local ces = {}
    for _, id in ipairs(id_display) do
        local link = ''
        if id > n_ce0 and id <= n_ce1 then
            link = ce_links[id - n_ce0]
        else
            link = frame:callParserFunction{name = '#ask:[[分类:礼装图鉴]][[礼装序号::' .. id .. ']]', args = {link = 'none'}}
        end
        table.insert(ces, frame:expandTemplate{ title = t_name, args = { mw.text.trim(link), id } })
    end

    return table.concat(ces)
end

return p