缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!

该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!

全站通知:

模块:表格/太空矿带

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:表格/太空矿带/doc创建

-- Module:表格/太空地点
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local getArgs = require('Module:Dev/Arguments').getArgs
local tb = require([[Module:表格]])
local po = require([[Module:Po]]).po
local utils = require([[Module:Utils]])
local poiData = mw.loadData([[Module:Data/HarvestablePOI]])

function p._main(poi)
	local hType = poi.harvestablePOIType
	if not hType then return nil end
	local aType = poi.artifactPOIType
	
    local out = {}

    -- 名称
    local name = po(("STRINGS.UI.SPACEDESTINATIONS.HARVESTABLE_POI.%s.NAME")
    	:format(hType.id:upper()))
    local lastDlc = poi.requiredDlcIds[2] or "nope" -- dlc other than spaced out
    name = ("{{图|48|%s}}%s<br>%s"):format(name, utils.DLC_ICONS[lastDlc] or "", name)
    table.insert(out, name)
    
    -- 起始资源
    local initialResources = {}
    if (hType.initialDataBanks or 0) > 0 then
    	table.insert(initialResources, 
    		("{{物品|数据磁盘}}:%s 单位"):format(hType.initialDataBanks))
    end
	for resource, mass in pairs(hType.initialLiberatedResources or {}) do
		table.insert(initialResources, 
			("{{物品|{{Po|STRINGS.ELEMENTS.%s.NAME}}}}:%s")
			:format(resource:upper(), utils.kg2str(mass)))
	end
    if hType.canProvideArtifacts == true and aType ~= nil then
        if aType.harvestableArtifactID ~= nil then
            table.insert(initialResources, 
            	("{{物品|{{Po|STRINGS.UI.SPACEARTIFACTS.%s.NAME}}:1 单位")
            	:format(aType.harvestableArtifactID:gsub("^artifact_", "")))
        else
            table.insert(initialResources, 
            	"[[File:图标 工艺品.png|x24px|class=dark-invert]] [[工艺品]]:1 单位")
        end
    end
    table.insert(out, table.concat(initialResources, "<br>"))
	
    -- 组成
    if hType.harvestableElements ~= nil then
        local sumWeight = 0
        for el, weight in pairs(hType.harvestableElements) do
            sumWeight = sumWeight + weight
        end
        local elements = {}
        for el, weight in pairs(hType.harvestableElements) do
            local elName = po("STRINGS.ELEMENTS." .. el:upper() .. ".NAME")
            local elPercent = weight / sumWeight * 100
            table.insert(elements, fstr("<span style='white-space: nowrap'>{{物品|%s}} %s%%</span>", elName,
                utils.float2str(elPercent, 2)))
        end
        local elItems = table.concat(elements, "<br/>")
        table.insert(out, elItems)
    else
        table.insert(out, "")
    end
    -- 资源容量
    table.insert(out, fstr("%s ↔ %s", utils.kg2str(hType.poiCapacityMin), utils.kg2str(hType.poiCapacityMax)))
    -- 完全恢复时间
    table.insert(out, fstr("%s ↔ %s", hType.poiRechargeMin / 600, hType.poiRechargeMax / 600))
    -- 描述
    local desc = "STRINGS.UI.SPACEDESTINATIONS.HARVESTABLE_POI." .. hType.id:upper() .. ".DESC"
    table.insert(out, po(desc))

    return out
end

-- test by: = p.main({})
function p.main(frame)
    local args = getArgs(frame)
    local infos = {}
    local sortedPoiData = {}
    for _, poi in pairs(poiData) do
    	table.insert(sortedPoiData, poi)
    end
    table.sort(sortedPoiData, function(a, b)
    	if a.requiredDlcIds[2] or b.requiredDlcIds[2] then
			return (a.requiredDlcIds[2] or "") < (b.requiredDlcIds[2] or "")
		else return a.name < b.name end
    end)
	-- mw.logObject(sortedPoiData)
    for _, poi in ipairs(sortedPoiData) do
        table.insert(infos, p._main(poi or {}))
    end

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

return p