缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!
该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!
全站通知:
模块:元素信息框
刷
历
编
跳到导航
跳到搜索
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local utils = require([[Module:Utils]])
local infobox = require([[Module:信息框/元素]])
local i18nde = require([[Module:I18n]]).loadMessages([[Module:I18n/Elements]])
local i18ndt = require([[Module:I18n]]).loadMessages([[Module:I18n/Misc]])
local elData = mw.loadData([[Module:Data/Elements]])
local _e = function(...)
return i18nde:msg(...)
end
local _t = function(...)
return i18ndt:msg(...)
end
local getArgs = require('Module:Dev/Arguments').getArgs
function p.tagCode(t)
return "STRINGS.MISC.TAGS." .. string.upper(t)
end
function p.id2locName(id)
local lID = elData[id] and elData[id].localizationID or id
local t = _e(lID)
if utils.isDefaultT(lID, t) then
return id
end
return t
end
function p.id2pageName(id)
local t = {}
if t[id] ~= nil then
return t[id]
end
return p.id2locName(id)
end
local function toPercent(n)
local n = tonumber(n)
n = n * 100
if n % 1 < 1e-5 then
n = math.floor(n)
return fstr("%d%%", n)
end
return fstr("%.2f%%", n)
end
function p._main(args, ele)
local out = {}
out["名称"] = _e(ele.localizationID)
out["图片"] = (args.img and #(args.img) ~= 0) and mw.text.nowiki(args.img) or
fstr("%s.png", _e(ele.localizationID))
local descCode = mw.ustring.gsub(ele.localizationID, "NAME", "DESC")
out["图片说明"] = _e(descCode)
if utils.isDefaultT(descCode, out["图片说明"]) then
out["图片说明"] = nil
end
out["ID"] = fstr("<code>%s</code>", ele.elementId)
out["比热"] = ele.specificHeatCapacity
out["热导率"] = ele.thermalConductivity
out["低温相变温度"] = ele.lowTemp and fstr("%.2f", tonumber(ele.lowTemp) - 273.15)
if ele.lowTempTransitionOreId ~= nil then
local page1 = p.id2pageName(ele.lowTempTransitionTarget)
local page2 = p.id2pageName(ele.lowTempTransitionOreId)
local ratio2 = tonumber(ele.lowTempTransitionOreMassConversion)
local ratio1 = 1 - ratio2
out["低温相变产物"] = fstr("{{物品|%s}}:%.2f <br> {{物品|%s}}:%.2f", page1, ratio1, page2, ratio2)
elseif ele.lowTempTransitionTarget ~= nil then
local page1 = p.id2pageName(ele.lowTempTransitionTarget)
out["低温相变产物"] = fstr("{{物品|%s}}", page1)
end
if ele.state == "Liquid" and ele.lowTempTransitionTarget ~= nil then
local target = elData[ele.lowTempTransitionTarget]
if target.state ~= "Liquid" then -- 盐水相变主要产物为浓盐水,因此不结块
local ratio = 1 - tonumber(ele.lowTempTransitionOreMassConversion or 0)
out["结块临界质量"] = 0.8 * target.defaultMass / ratio
end
end
out["高温相变温度"] = ele.highTemp and fstr("%.2f", tonumber(ele.highTemp) - 273.15)
if ele.highTempTransitionOreId ~= nil then
local page1 = p.id2pageName(ele.highTempTransitionTarget)
local page2 = p.id2pageName(ele.highTempTransitionOreId)
local ratio2 = tonumber(ele.highTempTransitionOreMassConversion)
local ratio1 = 1 - ratio2
out["高温相变产物"] = fstr("{{物品|%s}}:%.2f <br> {{物品|%s}}:%.2f", page1, ratio1, page2, ratio2)
elseif ele.highTempTransitionTarget ~= nil then
local page1 = p.id2pageName(ele.highTempTransitionTarget)
out["高温相变产物"] = fstr("{{物品|%s}}", page1)
end
out["硬度"] = ele.hardness
out["毒性"] = ele.toxicity and ele.toxicity ~= 0 and ele.toxicity or nil
out["摩尔质量"] = ele.molarMass and fstr("%.2f", ele.molarMass)
out["光吸收率"] = ele.lightAbsorptionFactor and toPercent(ele.lightAbsorptionFactor)
out["辐射吸收率"] = ele.radiationAbsorptionFactor and toPercent(ele.radiationAbsorptionFactor)
out["辐射"] = ele.radiationPer1000Mass and ele.radiationPer1000Mass ~= 0 and
math.ceil(ele.radiationPer1000Mass * 1.1) or nil
out["最大流动速度"] = ele.speed
out["标签"] = {}
for _, t in ipairs(ele.tags or {}) do
local tName = _t(p.tagCode(t))
if utils.isDefaultT(p.tagCode(t), tName) then
tName = t
end
table.insert(out["标签"], fstr("[[:category:%s|%s]]", tName, tName))
end
out["标签"] = #out["标签"] > 0 and table.concat(out["标签"], ",") or nil
out["分类"] = ele.materialCategory and
fstr("[[:category:%s|%s]]", _t(p.tagCode(ele.materialCategory)),
_t(p.tagCode(ele.materialCategory)))
out["单格最大质量"] = ele.maxMass
out["最小垂直流动"] = ele.minVerticalFlow
out["最小水平流动"] = ele.minHorizontalFlow
-- add categories
local pageCats = {}
-- empty args.namespace stands for main pages
if (not args.namespace and not args.nocat) then
if ele.materialCategory then
table.insert(pageCats, fstr("[[category:%s]]", _t(p.tagCode(ele.materialCategory))))
end
for _, t in ipairs(ele.tags or {}) do
local tName = _t(p.tagCode(t))
if utils.isDefaultT(p.tagCode(t), tName) then
tName = t
end
table.insert(pageCats, fstr("[[category:%s]]", tName))
end
if ele.state then
local sName = _e("STRINGS.ELEMENTS.STATE." .. ele.state:upper())
table.insert(pageCats, fstr("[[category:%s]]", sName))
end
out["分类"] = #(pageCats) > 0 and table.concat(pageCats, "\n") or nil
end
return out, pageCats
end
-- test by: =p.main(require("Module:debug").frame({},{debug=1, pagename="气态铝"}))
-- test by: =p.main(require("Module:debug").frame({},{debug=1, "AluminumGas"}))
-- test by: =p.main(require("Module:debug").frame({},{debug=1, "Brine"}))
-- test by: =p.main(require("Module:debug").frame({},{debug=1, "Aerogel"}))
-- test by: =p.main(require("Module:debug").frame({},{debug=1, "Vacuum"}))
function p.main(frame)
local args = getArgs(frame)
local elements = {}
if args ~= nil and args[1] ~= nil then
for _, elementId in ipairs(args) do
local element = elData[elementId]
if element ~= nil then
table.insert(elements, {
id = elementId,
data = element
})
end
end
else
local elementCode = i18nde:msgRev({
key = args.pagename,
args = {
prefix = "STRINGS.ELEMENTS."
}
} or "")
if elementCode == nil then
error(fstr("找不到元素 '%s',请使用参数1或检查 [[%s]]。", args.pagename,
"[[Module:Data/Elements]]"))
else
for k, v in pairs(elData) do
if v.localizationID ~= nil and v.localizationID == elementCode then
table.insert(elements, {
id = k,
data = v
})
break
end
end
end
end
if #elements <= 0 then
error(fstr("找不到元素 '%s',请使用参数1或检查 [[%s]]。", args.pagename,
"[[Module:Data/Elements]]"))
end
-- 找到所有元素id
local infos = {}
local pageCatsSet = {}
for _, element in ipairs(elements) do
local curr, cats = p._main(args, element.data)
table.insert(infos, {
label = curr['名称'],
data = curr
})
for _, cat in ipairs(cats) do
pageCatsSet[cat] = true
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