Module:表格/食物
跳转到导航
跳转到搜索
可在Module:表格/食物/doc创建此模块的帮助文档
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local getArgs = require('Dev:Arguments').getArgs
local fData = mw.loadData("Module:Data/Food")
local function ingredient(ings)
local list = {}
for _, ing in ipairs(ings) do
---- 多配方适配
local recp = ""
for w in ing["原料"]:gmatch("[^%/]+") do
recp = recp..fstr("{{物品|%s}}/", w)
end
recp = string.sub(recp,1,-2)
table.insert(list, fstr("%s %s", recp, ing["数量"]))
end
return table.concat(list, "<wbr>")
end
function p._main(args)
local out = {}
local ks = {};
for k, _ in pairs(fData) do
table.insert(ks, k)
end
table.sort(ks, function(a, b) -- put SO food (& potentially disabled food) at the back
if fData[a]["游戏本体"] ~= fData[b]["游戏本体"] then
return fData[a]["游戏本体"]
end
return a < b
end
)
for _, k in ipairs(ks) do
local food = fData[k]
local name = fstr("{{物品|%s|%s}}", food.id, food["名称"])
if food["眼冒金星"] == true and food["游戏本体"] == false then
name = name .. "<wbr>{{眼冒金星图标}}"
end
local cal = food["能量"]
local quality = fstr("{{食物品质|%d}}", food["品质"])
local spoil = food["腐烂时间"] ~= 0 and food["腐烂时间"] or "永不腐烂"
local ingredient = ingredient(food["原料"])
table.insert(out, {name, cal, {quality, {['data-sort-value'] = food["品质"]}}, spoil, ingredient})
end
return require([[Module:表格]]).table(out, args)
end
-- test by: p.main()
function p.main(frame)
return p._main(getArgs(frame))
end
return p