此模块的文档可以在Module:Data/Food/doc创建
-- Module:Data/Food
local fstr = mw.ustring.format -- shortcut for formattig a string
local yesno = require('Dev:Yesno')
local sepEntry = "@@@@@@@@"
local sepField = "@@$$"
local fields = {
"名称", --
"图片", --
"描述", --
"游戏本体", -- default true
"眼冒金星", -- default true
"能量", --
"品质", --
"冷藏温度", --
"深度冷冻温度", --
"腐烂时间", --
"原料1", --
"原料 1", --
"数量1", --
"数量 1", --
"原料2", --
"原料 2", --
"数量2", --
"数量 2", --
"原料3", --
"原料 3", --
"数量3", --
"数量 3" --
}
local paramInclude = {}
for _, v in ipairs(fields) do
table.insert(paramInclude, fstr("{食物信息框}:%s", v))
end
paramInclude = table.concat(paramInclude, ",")
local dplArgs = {
uses = "Template:食物信息框",
notcategory = nil,
namespace = "",
include = paramInclude,
format = ",@@@@@@@@%TITLE%,",
secseparators = sepField,
includesubpages = "false",
skipthispage = "no"
}
local dplResult = mw.getCurrentFrame():callParserFunction('#dpl:', dplArgs)
local entries = mw.text.split(dplResult, sepEntry, true)
local p = {}
for i = 2, #entries do
local curr = entries[i]
local currFields = mw.text.split(curr, sepField, true)
local namedFs = {}
namedFs.id = currFields[1]
for i, f in ipairs(fields) do
namedFs[fields[i]] = #currFields[i + 1] > 0 and currFields[i + 1] or nil
end
local currOut = {}
currOut["id"] = namedFs.id
currOut["名称"] = namedFs["名称"] or namedFs.id
currOut["图片"] = namedFs["图片"] or
fstr("File:%s.png", currOut["名称"])
currOut["描述"] = namedFs["描述"]
currOut["游戏本体"] = yesno(namedFs["游戏本体"] or '', true)
currOut["眼冒金星"] = yesno(namedFs["眼冒金星"] or '', true)
currOut["能量"] = tonumber(namedFs["能量"])
currOut["品质"] = tonumber(namedFs["品质"])
currOut["冷藏温度"] = tonumber(namedFs["冷藏温度"])
currOut["深度冷冻温度"] = tonumber(namedFs["深度冷冻温度"])
currOut["腐烂时间"] = tonumber(namedFs["腐烂时间"]) and
tonumber(namedFs["腐烂时间"]) > 0 and
tonumber(namedFs["腐烂时间"]) or 0 -- 0 for infinity
local ingredients = {}
for j = 1, 5 do
local vname = namedFs[fstr("原料 %d", j)]
vname = vname or namedFs[fstr("原料%d", j)]
local vnum = namedFs[fstr("数量 %d", j)]
vnum = vnum or namedFs[fstr("数量%d", j)]
if vname ~= nil and vnum ~= nil then
table.insert(ingredients, {["原料"] = vname, ["数量"] = vnum})
end
end
currOut["原料"] = ingredients
p[namedFs.id] = currOut
end
return p
-- mw.logObject(p)