缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!
该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!
全站通知:
模块:流星雨信息框
刷
历
编
跳到导航
跳到搜索
-- Module:流星雨信息框
local p = {}
local getArgs = require("Module:Dev/Arguments").getArgs
local fstr = mw.ustring.format
local po = require([[Module:Po]]).po
local i18nc = require([[Module:I18n]]).loadMessages([[Module:I18n/Ui]])
local utils = require("Module:Utils")
local k0 = utils.K0
local infobox = require([[Module:信息框/流星雨]])
local fDataPath = [[Module:Data/MeteorShowers]]
local fData = mw.loadData(fDataPath)
local cData = mw.loadData([[Module:Data/Comets]])
local function isMatchMeteorId(fData, id)
if fData.id:upper() == id:upper() then
return true
elseif fData.clusterMapMeteorShowerID ~= nil then
if ("ClusterMapMeteorShower_" .. id):upper() == fData.clusterMapMeteorShowerID:upper() then
return true
end
elseif fData.id:upper() == ("MeteorShower" .. id .. "Event"):upper() then
return true
elseif fData.id:upper() == ("Cluster" .. id .. "Shower"):upper() then
return true
end
return false
end
local function getMeteorName(itemCode, meteorId)
if itemCode ~= nil then
return po(itemCode)
end
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")
}
return exception_name[meteorId]
end
local function getCometName(itemData)
if itemData.Name ~= nil then
local name = po(itemData.Name)
if not utils.isDefaultT(itemData.Name, name) then
return fstr("{{物品|%s}}", name)
end
end
return fstr("<code>%s</code>", itemData.Id)
end
function p._main(itemData, itemCode)
local out = {}
local pageCats = {}
out["ID"] = fstr("<code>%s</code>", itemData.id)
out["名称"] = getMeteorName(itemCode, itemData.id)
out["图片"] = fstr("%s.png", out["名称"])
out["图片说明"] = itemCode ~= nil and po(itemCode:sub(1, -6) .. ".DESCRIPTION") or nil
if itemData.clusterMapMeteorShowerID ~= nil then
out["星图ID"] = fstr("<code>%s</code>", itemData.clusterMapMeteorShowerID)
end
if itemData.duration ~= nil then
out['持续时间'] = fstr("%s 秒", utils.float2str(itemData.duration))
end
if itemData.secondsBombardmentOff ~= nil then
out['轰击间隔'] = fstr("%s ↔ %s 秒/轮", utils.float2str(itemData.secondsBombardmentOff.min),
utils.float2str(itemData.secondsBombardmentOff.max))
end
if itemData.secondsBombardmentOn ~= nil then
out['轰击时间'] = fstr("%s ↔ %s 秒/轮", utils.float2str(itemData.secondsBombardmentOn.min),
utils.float2str(itemData.secondsBombardmentOn.max))
end
if itemData.secondsPerMeteor ~= nil then
if itemData.affectedByDifficulty == true then
out['流星生成速率'] = {}
local difficulty = {
[0] = {
name = "初始值",
k = 1
},
[1] = {
name = "绵绵细雨",
k = 1.5
},
[2] = {
name = "宇宙风暴",
k = 0.8
},
[3] = {
name = "末日浩劫",
k = 0.5
}
}
for i = 0, 3 do
local di = difficulty[i]
if di ~= nil then
table.insert(out['流星生成速率'],
fstr("%s:%s 秒/颗", di.name, utils.float2str(itemData.secondsPerMeteor * di.k)))
end
end
out['流星生成速率'] = #out['流星生成速率'] > 0 and
table.concat(out['流星生成速率'], "<br/>") or nil
else
out['流星生成速率'] = fstr("%s 秒/颗", utils.float2str(itemData.secondsPerMeteor))
end
end
if itemData.affectedByDifficulty ~= nil then
out['受难度影响'] = itemData.affectedByDifficulty == true and "✔" or "✖"
end
if itemData.seasons ~= nil then
out['季节'] = {}
for _, season in ipairs(itemData.seasons) do
table.insert(out['季节'], fstr("<code>%s</code>", season))
end
out['季节'] = #out['季节'] > 0 and table.concat(out['季节'], "<br/>") or nil
end
-- if itemData.numTimesAllowed ~= nil then
-- end
-- if itemData.allowMultipleEventInstances ~= nil then
-- end
if itemData.bombardmentInfo ~= nil then
local max = 0
for _, bombInfo in ipairs(itemData.bombardmentInfo) do
max = max + bombInfo.weight
end
local comets = {}
for _, bombInfo in ipairs(itemData.bombardmentInfo) do
local cometData = cData[bombInfo.prefab]
if cometData ~= nil then
table.insert(comets, {
name = getCometName(cometData),
weight = bombInfo.weight
})
end
end
out['成分'] = #comets > 0 and table.concat(utils.map(comets, function(bombInfo)
return fstr('%s:<abbr title = "%s/%s">%s%%</abbr>', bombInfo.name, utils.float2str(bombInfo.weight),
utils.float2str(max), utils.float2str(bombInfo.weight / (max == 0 and 1 or max) * 100))
end), "<br/>") or nil
end
table.insert(pageCats, "[[Category:流星雨]]")
return out, pageCats
end
-- test by: = p.main(require("Module:debug").frame({},{debug=1, "MeteorShowerDustEvent"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, "MeteorShowerFullereneEvent"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="富勒烯流星雨", "MeteorShowerFullereneEvent"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="铜流星雨"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="铀流星雨"}))
function p.main(frame)
local args = getArgs(frame)
local meteors = {}
if args[1] ~= nil then
for _, meteorId in ipairs(args) do
for k, v in pairs(fData) do
if k:upper() == meteorId:upper() then
table.insert(meteors, {
id = meteorId,
code = v.clusterMapName
})
end
end
end
else
local meteorCode = i18nc:msgRev({
key = args.pagename,
args = {
prefix = "STRINGS.UI.SPACEDESTINATIONS.CLUSTERMAPMETEORSHOWERS."
}
} or "")
if meteorCode == nil then
error(fstr("找不到流星雨 '%s',请使用参数1或检查 [[%s]]。", args.pagename, fDataPath))
else
local meteorId = meteorCode:gsub("%.NAME$", "")
meteorId = meteorId:gsub("^STRINGS%.UI%.SPACEDESTINATIONS%.CLUSTERMAPMETEORSHOWERS%.", "")
table.insert(meteors, {
id = meteorId,
code = meteorCode
})
end
end
if #meteors <= 0 then
error(fstr("找不到流星雨 '%s',请使用参数1或检查 [[%s]]。", args.pagename, fDataPath))
end
-- 找到所有流量雨id
local infos = {}
local pageCatsSet = {}
for _, meteor in ipairs(meteors) do
for k, v in pairs(fData) do
if k:upper() == meteor.id:upper() or isMatchMeteorId(v, meteor.id) then
local curr, cats = p._main(v, meteor.code)
table.insert(infos, {
label = v.clusterMapMeteorShowerID ~= nil and "眼冒金星" or "本体",
data = curr
})
for _, cat in ipairs(cats) do
pageCatsSet[cat] = true
end
end
end
end
-- 分类
local pageCats = {}
if not (args.namespace or args.nocat) then
for cat, _ in pairs(pageCatsSet) do
table.insert(pageCats, cat)
end
table.sort(pageCats)
end
if args.debug then
mw.logObject(infos, "infos")
mw.logObject(pageCats, "pageCats")
end
local infoboxTitle = args.pagename
return infobox.main(infoboxTitle, infos) .. table.concat(pageCats, "")
end
return p