缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!
该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!
全站通知:
模块:食物信息框
刷
历
编
跳到导航
跳到搜索
-- 食物信息框
local p = {}
local fstr = mw.ustring.format
local entityTemplate = "{{物品|%s}}"
local utils = require("Module:Utils")
local k0 = utils.K0
local po = require([[Module:Po]]).po
local i18ncr = require([[Module:I18n]]).loadMessages([[Module:I18n/Items]])
local infobox = require([[Module:信息框/食物]])
local getArgs = require("Module:Dev/Arguments").getArgs
local fDataPath = [[Module:Data/Food]]
local fData = mw.loadData(fDataPath)
local exception = {
["BEAN"] = "BEANPLANTSEED"
}
local arequation = '➠'
local cross = '×'
function p._main(foodData, foodCode)
local out = {}
local cat = {
"[[Category:食物]]"
}
out["ID"] = fstr("<code>%s</code>", foodData.Id)
out["名称"] = po(foodCode)
out["图片"] = fstr("%s.png", out["名称"])
out["图片说明"] = po(foodCode:sub(1, -6) .. ".DESC")
if foodData.CaloriesPerUnit ~= nil and foodData.CaloriesPerUnit > 0 then
out["能量"] = fstr("%s 千卡/单位", foodData.CaloriesPerUnit / 1000)
table.insert(cat, "[[Category:可食用物]]")
else
table.insert(cat, "[[Category:烹饪原料]]")
end
if foodData.CanRot then
out["是否会腐烂"] = "✔"
if foodData.StaleTime ~= nil then
-- out["变质时间"] = utils.float2str(foodData.StaleTime / 600) .. " 周期"
end
if foodData.SpoilTime ~= nil then
out["腐烂时间"] = utils.float2str(foodData.SpoilTime / 600) .. " 周期"
end
if foodData.RotTemperature ~= nil then
out["冷藏温度"] = utils.float2str(foodData.RotTemperature + k0) .. " °C"
end
if foodData.PreserveTemperature ~= nil then
out["深度冷冻温度"] = utils.float2str(foodData.PreserveTemperature + k0) .. " °C"
end
else
out["是否会腐烂"] = "✖"
end
if foodData.Quality ~= nil then
if foodData.Quality <= 6 and foodData.Quality >= -1 then
out["食物品质"] = fstr("{{食物品质|%s}}", foodData.Quality)
end
if foodData.qualityOfLife ~= nil and foodData.qualityOfLife ~= 0 then
out["士气加成"] = utils.float2str(foodData.qualityOfLife, nil, true)
end
end
if foodData.primaryElement ~= nil then
out["元素"] = fstr("{{物品|%s}}", utils.getEntry(foodData.primaryElement.Name))
out["质量"] = utils.kg2str(foodData.primaryElement.Mass)
-- out["初始温度"] = utils.float2str(foodData.primaryElement.InternalTemperature + k0) .. " °C"
end
if foodData.recipes then
local function sortByOutputAmount(a, b)
if not a.output or not a.output[1] then return false end
if not b.output or not b.output[1] then return true end
return a.output[1].amount > b.output[1].amount
end
local mergedRecipes = utils.mergeRecipes(foodData.recipes)
-- mw.logObject(mergedRecipes)
table.sort(mergedRecipes, sortByOutputAmount)
out["制作建筑"] = mergedRecipes[1].fabricator
out["制作时间"] = mergedRecipes[1].workTime
local equations = {}
for _, recipe in ipairs(mergedRecipes) do
if out["制作建筑"] ~= recipe.fabricator or out["制作时间"] ~= recipe.workTime then
error("配方的制作建筑/制作时间不一致")
end
-- 等式的原料部分
local equation = ""
local function formatOpts(opts)
-- 检查所有选项的数量是否相同
local allSameAmount = true
local commonAmount = nil
for i, opt in ipairs(opts) do
if i == 1 then
commonAmount = opt.amount
elseif opt.amount ~= commonAmount then
allSameAmount = false
break
end
end
local parts = {}
if allSameAmount and commonAmount == 1 then
-- 所有选项数量都为 1,合并显示
local elements = {}
for _, opt in ipairs(opts) do
table.insert(elements, opt.element)
end
table.sort(elements)
return table.concat(utils.map(elements, function(code)
return entityTemplate:format(utils.getEntry(code))
end), "/")
else
-- 分别显示
for _, opt in ipairs(opts) do
table.insert(parts, entityTemplate:format(utils.getEntry(opt.element)) .. cross .. opt.amount)
end
return table.concat(parts, "/")
end
end
for i, opts in ipairs(recipe.input) do
if #recipe.input == 1 then
equation = formatOpts(opts)
else
equation = equation .. ("原料 %d:%s<br>"):format(i, formatOpts(opts))
end
end
-- 箭头和产物部分
equation = equation .. ("<div style='text-align:right'>%s %s</div>"):format(arequation,
table.concat(utils.map(recipe.output, function(o)
return entityTemplate:format(utils.getEntry(o.element)) .. cross .. o.amount
end), "<br>& "))
table.insert(equations, equation)
end
if out["制作建筑"] then
out["制作建筑"] = ("{{物品|%s}}"):format(utils.getEntry(out["制作建筑"]))
end
out["制作时间"] = (out["制作时间"] or 0) .. " 秒"
out["配方"] = "<div class='infobox-recipe'>" .. table.concat(equations, "") .. "</div>"
end
if foodData.Effects then
local effects = {}
for _, effect in pairs(foodData.Effects) do
local efCode = "STRINGS.DUPLICANTS.MODIFIERS." .. effect:upper()
table.insert(effects, fstr("<abbr title='{{Po|%s.TOOLTIP}}'>{{Po|%s.NAME}}<abbr>", efCode, efCode))
end
out["效果"] = table.concat(effects, "<br>")
end
return out, table.concat(cat, "")
end
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="烤肉串"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="冰霜汉堡"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="小吃豆"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="生蛋"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="烤海鲜"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, "Burger"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, "BeanPlantSeed"}))
function p.main(frame)
local args = getArgs(frame)
local infos = {}
local foods = {}
local pageCats = {}
if args[1] ~= nil then
for _, foodId in ipairs(args) do
local _, _, foodCode = utils.getEntry(foodId)
if foodCode == nil then
return {
["名称"] = fstr("找不到食物 '%s',请使用参数1或检查 [[%s]]。", foodId, fDataPath)
}
end
table.insert(foods, {
id = foodId,
code = foodCode
})
end
else
local foodCode = i18ncr:msgRev({
key = args.pagename,
args = {
prefix = "STRINGS.ITEMS.FOOD."
}
} or "")
if foodCode == nil then
return {
["名称"] = fstr("找不到食物 '%s',请使用参数1或检查 [[%s]]。", args.pagename, fDataPath)
}
end
local foodId = foodCode:match("([%u_]+).NAME$")
table.insert(foods, {
id = foodId,
code = foodCode
})
end
for _, food in pairs(foods) do
if exception[food.id] then
food.id = exception[food.id]
local _
_, _, food.code = utils.getEntry(food.id)
end
for k, v in pairs(fData) do
if k:upper() == food.id:upper() then
local curr, cat = p._main(v, food.code)
table.insert(infos, {
label = curr["名称"],
data = curr
})
if args.nocat then
cat = ""
end
table.insert(pageCats, cat)
end
end
end
if args.debug then
mw.logObject(infos)
end
local infoboxTitle = #infos > 1 and args.pagename or infos[1].label
return infobox.main(infoboxTitle, infos) .. table.concat(pageCats, "")
end
return p