Module:ProfessionTable
Used by {{ProfessionTable}}; currently integrated with {{RecipeTable/RecipeRow}}.
local getArgs = require('Module:Arguments').getArgs
local p = {}
local data = mw.loadData('Module:ProfessionTable/data')
local isGathering = {
Herbalism = true,
Skinning = true,
Mining = true,
}
local recipeHeader = [=[
{| class="darktable zebra plainlinks recipetable"
|+ %s
|-
! [[Recipe]]
! [[Materials]]
! Optional
! class="skill-orange" | Skill
! class="skill-yellow" | G.
! class="skill-green" | G.
! class="skill-gray" | G.
! Source
]=]
local gatherHeader = [=[
{| class="darktable zebra plainlinks gathertable"
|+ %s
|-
! [[Recipe]]
! class="skill-orange" | Skill
! class="skill-yellow" | G.
! class="skill-green" | G.
! class="skill-gray" | G.
]=]
local footer = [=[
|}
]=]
local rowSpacer = [=[
|-
| ]=] -- backwards compatibility {{RecipeTable}}
local pattern = "#using:%s" -- #using:Transmute: Iron to Gold --
--local patternProf = "#using:%s#%s"
local patternProf = "#using:%s"-- #using:Minor Mana Potion#Alchemy
local function append(tableData, frame, v, tpl, profession)
table.insert(tableData, rowSpacer)
if (type(v)=="string") then
if (v:find(":")) then
table.insert(tableData, frame:callParserFunction(pattern:format(v), tpl))
else
table.insert(tableData, frame:callParserFunction(patternProf:format(v, profession), tpl))
end
else
if(v[1]:find(":")) then
table.insert(tableData,frame:callParserFunction(pattern:format(v[1], profession), {
tpl,
["faction"]=v.faction, -- nil or true
["ranks"]=v.ranks, -- nil or true
}))
else
table.insert(tableData, frame:callParserFunction(patternProf:format(v[1], profession), {
tpl,
["faction"]=v.faction, -- nil or true
["ranks"]=v.ranks, -- nil or true
}))
end
end
end
function p.GenerateTable(frame)
local args = getArgs(frame, {wrappers = 'Template:ProfessionTable'})
local profession, expansion = args.profession, args.expansion
local info
if data[profession] and data[profession][expansion] then
info = data[profession][expansion]
end
local header, rowtpl = recipeHeader, "RecipeTable/RecipeRow"
if isGathering[profession] then
-- one fewer column
header, rowtpl = gatherHeader, "RecipeTable/GatherRow" -- placeholder; this doesn't exist yet
end
if info then
local tableData = {}
-- table.sort(data[args.category]) -- Would it be possible to sort once (when adding new info) vice every page view?
table.insert(tableData, frame:expandTemplate{ title = 'i-note', args = {data.lastUpdate}})
-- Anything that isn't in a subcategory will be listed in a table.
if (info[1]) then
table.insert(tableData, header:format(""))
for k,v in ipairs(info) do
append(tableData, frame, v, rowtpl, profession)
end
table.insert(tableData, footer)
end
-- Subcategories next, each with their own sortable table.
for k,v in pairs(info) do
if (type(k) == "string") then
table.insert(tableData, header:format(k))
for k2,v2 in ipairs(v) do
append(tableData, frame, v2, rowtpl, profession)
end
table.insert(tableData, footer)
end
end
return table.concat(tableData)
else
return args.expansion .. " does not exist in [[Module:ProfessionTable/data]]"
end
end
return p