Module:表格/流星雨季

来自缺氧 Wiki
跳转到导航 跳转到搜索

可在Module:表格/流星雨季/doc创建此模块的帮助文档

-- Module:表格/流星雨季节
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local getArgs = require('Dev:Arguments').getArgs
local tb = require([[Module:表格]])
local po = require([[Module:Po]]).po
local utils = require([[Module:Utils]])
local sData = mw.loadData([[Module:Data/GameplaySeasons]])
local mData = mw.loadData([[Module:Data/MeteorShowers]])

local exception_name = {
    MeteorShowerIronEvent = po("STRINGS.UI.SPACEDESTINATIONS.CLUSTERMAPMETEORSHOWERS.IRON.NAME"),
    MeteorShowerGoldEvent = po("STRINGS.UI.SPACEDESTINATIONS.CLUSTERMAPMETEORSHOWERS.GOLD.NAME"),
    MeteorShowerCopperEvent = po("STRINGS.UI.SPACEDESTINATIONS.CLUSTERMAPMETEORSHOWERS.COPPER.NAME"),
    MeteorShowerFullereneEvent = po("STRINGS.ELEMENTS.FULLERENE.NAME") ..
        po("STRINGS.UI.FRONTEND.CUSTOMGAMESETTINGSSCREEN.SETTINGS.METEORSHOWERS.NAME")
}

local function getMeteorName(itemCode, meteorId)
    if itemCode ~= nil then
        return po(itemCode)
    end
    local name = exception_name[meteorId]
    if name ~= nil then
        return name
    end
    return nil
end

local DLCS = {
    [""] = 1,
    ["EXPANSION1_ID"] = 2,
    ["DLC2_ID"] = 3
}

-- test by: = p._main({})
function p._main(seasonData)
    local out = {}

    table.insert(out, fstr("<code>%s</code>", seasonData.Id))
    local dlcIcon = utils.DLC_ICONS[seasonData.dlcId]
    table.insert(out, dlcIcon ~= nil and dlcIcon or "")
    table.insert(out, seasonData.period)
    if seasonData.eventIds ~= nil then
        local events = {}
        for _, eventId in ipairs(seasonData.eventIds) do
            local meteorData = mData[eventId]
            if meteorData ~= nil then
                table.insert(events, {
                    name = getMeteorName(meteorData.clusterMapName, meteorData.id),
                    id = eventId
                })
            end
        end
        table.insert(out, table.concat(utils.map(events, function(event)
            if event.name ~= nil then
                return fstr("{{物品|%s}}", event.name)
            else
                return ""
            end
        end), "<br/>"))
        table.insert(out, table.concat(utils.map(events, function(event)
            if event.id == nil then
                return ""
            else
                return fstr("<code>%s</code>", event.id)
            end
        end), "<br/>"))
    else
        table.insert(out, "")
        table.insert(out, "")
    end
    if seasonData.clusterTravelDuration ~= nil then
        table.insert(out, seasonData.clusterTravelDuration == -1 and "无" or
            utils.float2str(seasonData.clusterTravelDuration / 600))
    else
        table.insert(out, "无")
    end
    table.insert(out, seasonData.affectedByDifficultySettings == true and "是" or "否")
    return out
end

-- test by: = p.main({})
-- test by: = p.main({dlc=""})
-- test by: = p.main({dlc="EXPANSION1_ID"})
function p.main(frame)
    local args = getArgs(frame)
    local infos = {}

    local dlc = args.dlc
    for seasonId, seasonData in pairs(sData) do
        if dlc == nil or (dlc ~= nil and dlc == seasonData.dlcId) then
            local info = p._main(seasonData)
            table.insert(infos, {
                info = info,
                dlc = seasonData.dlcId
            })
        end
    end
    table.sort(infos, function(a, b)
        if DLCS[a.dlc] == nil then
            return true
        elseif DLCS[b.dlc] == nil then
            return false
        else
            return DLCS[a.dlc] < DLCS[b.dlc]
        end
    end)
    infos = utils.map(infos, function(info)
        return info.info
    end)

    -- mw.logObject(infos)
    return tb.table(infos, args)
end

return p