Module:RecipeDetails/Pull: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) m (Kiokurashi moved page Module:RecipeDetails/dataformat to Module:RecipeDetails/Pull without leaving a redirect) |
Kiokurashi (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
local metat = mw. | local p = {} | ||
function | local metat = mw.ext.cargo | ||
local | |||
for | local function RecipeBreakdownFormatter(inFullTable) | ||
local | local fullTable = inFullTable | ||
local results = {} | |||
local Row = [==[<tr><td style="padding-left:%spx">{{CraftReq|%s}}</td><td>{{Numdisplay|%s}}</td></tr>]==] | |||
-- Format output rows. | |||
local n = 1 | |||
while n < #fullTable do | |||
-- Index is 6 for the first tier, and 20n+5 for the rest. | |||
local index = fullTable[n] | |||
local item = fullTable[n+1] | |||
local amount = fullTable[n+2] | |||
if index > 1 then index = index * 20 + 5 else padding = 6 end | |||
results[#results+1] = string.format(Row, index, item, amount) | |||
-- Iterate to the end of set. | |||
n = n + 3 | |||
end | |||
-- Concatenate strings together. | |||
return table.concat(results, "") | |||
end | |||
local function RecipeTotalsFormatter(inBaseIngTable) | |||
local baseIngTable = inBaseIngTable | |||
local result = {} | |||
local Row = [==[<tr><td style="text-align:right">{{CraftReq|%s}}</td><td>{{Numdisplay|%s}}</td></tr>]==] | |||
-- Format output rows. | |||
local n = 1 | |||
while n < #baseIngTable do | |||
local item = fullTable[n] | |||
local amount = fullTable[n+1] | |||
result[#result+1] = string.format(Row, item, amount) | |||
n = n + 2 | |||
end | end | ||
return | |||
return table.concat(result, "") | |||
end | |||
function p.Main( frame ) | |||
local item = frame.args.Item | |||
local tabstr = [[Recipe=%s | |||
|-|Totals=%s]] | |||
-- Query 'DetailedRecipes' table for the recipe and retrieve the outputs | |||
local tables = 'DetailedRecipes' | |||
local fields = 'Breakdown, Totals' | |||
local args = { | |||
where = 'DetailedRecipes.Item="' .. item .. '"', | |||
orderBy = 'DetailedRecipes.Item' | |||
} | |||
local results = cargo.query( tables, fields, args ) | |||
if #results == 0 then return end | |||
local tablehead = [[<table class="wikitable"> | |||
<tr><th style="width:80%;">Item</th><th>Qty</th></tr>]] | |||
-- build the data. | |||
local breakdown = tablehead..RecipeBreakdownFormatter(fullTableStruct).."</table>" | |||
local totals = tablehead..RecipeTotalsFormatter(baseIngredients).."</table>" | |||
return '<div class="detrecipe">' .. frame:extensionTag( 'tabber', string.format(tabstr, results[1].Breakdown, results[1].Totals)) .. "</div>" | |||
end | end | ||
return | return p |
Revision as of 02:11, 17 April 2024
Documentation for this module may be created at Module:RecipeDetails/Pull/doc
local p = {}
local metat = mw.ext.cargo
local function RecipeBreakdownFormatter(inFullTable)
local fullTable = inFullTable
local results = {}
local Row = [==[<tr><td style="padding-left:%spx">{{CraftReq|%s}}</td><td>{{Numdisplay|%s}}</td></tr>]==]
-- Format output rows.
local n = 1
while n < #fullTable do
-- Index is 6 for the first tier, and 20n+5 for the rest.
local index = fullTable[n]
local item = fullTable[n+1]
local amount = fullTable[n+2]
if index > 1 then index = index * 20 + 5 else padding = 6 end
results[#results+1] = string.format(Row, index, item, amount)
-- Iterate to the end of set.
n = n + 3
end
-- Concatenate strings together.
return table.concat(results, "")
end
local function RecipeTotalsFormatter(inBaseIngTable)
local baseIngTable = inBaseIngTable
local result = {}
local Row = [==[<tr><td style="text-align:right">{{CraftReq|%s}}</td><td>{{Numdisplay|%s}}</td></tr>]==]
-- Format output rows.
local n = 1
while n < #baseIngTable do
local item = fullTable[n]
local amount = fullTable[n+1]
result[#result+1] = string.format(Row, item, amount)
n = n + 2
end
return table.concat(result, "")
end
function p.Main( frame )
local item = frame.args.Item
local tabstr = [[Recipe=%s
|-|Totals=%s]]
-- Query 'DetailedRecipes' table for the recipe and retrieve the outputs
local tables = 'DetailedRecipes'
local fields = 'Breakdown, Totals'
local args = {
where = 'DetailedRecipes.Item="' .. item .. '"',
orderBy = 'DetailedRecipes.Item'
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return end
local tablehead = [[<table class="wikitable">
<tr><th style="width:80%;">Item</th><th>Qty</th></tr>]]
-- build the data.
local breakdown = tablehead..RecipeBreakdownFormatter(fullTableStruct).."</table>"
local totals = tablehead..RecipeTotalsFormatter(baseIngredients).."</table>"
return '<div class="detrecipe">' .. frame:extensionTag( 'tabber', string.format(tabstr, results[1].Breakdown, results[1].Totals)) .. "</div>"
end
return p