Module:Infobox Recipe: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
(Switch to mw.html fluent builder; Use {{Currency cell}} to align currency)
Line 1: Line 1:
local currency = require('Module:Currency')

local function currency_cell(amount)
return currency._cell(amount, { html = 'yes' })
end

local p = {}
local p = {}


function p._main(frame)
function p._main(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local mw = require('mw')
local currency = require('Module:Currency').parse
local parse = require('Module:Param Parse')
local parse = require('Module:Param Parse')
local yn = require('Module:Yesno')
local yn = require('Module:Yesno')
Line 87: Line 91:
local materialBuyPrice = getBuyPrice(item)
local materialBuyPrice = getBuyPrice(item)
rawMaterialCost = rawMaterialCost + materialBuyPrice
rawMaterialCost = rawMaterialCost + materialBuyPrice
return mw.html.create('tr')
local row = {}
:tag('td')
table.insert(row, '| [[File:' .. item['name'] .. '.png|30px]]')
table.insert(row, '| [[' .. item['name'] .. ']]')
:wikitext('[[File:' .. item.name .. '.png|30px]]')
:done()
table.insert(row, '| style="text-align: right;" | ' .. (quantity or 1))
:tag('td')
table.insert(row, '| style="text-align: right;" | ' .. currency(materialBuyPrice))
:wikitext('[[' .. item.name .. ']]')
table.insert(row, '|-')
:done()
return row
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(quantity or 1)
:done()
:wikitext(currency_cell(materialBuyPrice))
:done()
end
end


--Creates a row suitable for the intermediate materials section of the infobox. Quantity is optional, if no value is provided it will default to 1
--Creates a row suitable for the intermediate materials section of the infobox. Quantity is optional, if no value is provided it will default to 1
local function createIntermediateMaterialRow(item, quantity)
local function createIntermediateMaterialRow(item, quantity)
local row = {}
local facility = getFacility(item)
local facility = getFacility(item)
return mw.html.create('tr')
table.insert(row, '| [[File:' .. item .. '.png|30px]]')
:tag('td')
table.insert(row, '| [[' .. item .. ']]')
:wikitext('[[File:' .. item .. '.png|30px]]')
table.insert(row, '| style="text-align: right;" | ' .. (quantity or 1))
:done()
table.insert(row, '| style="text-align: right;" | [[File:' .. facility .. '.png|30px]] [[' .. facility .. ']]')
table.insert(row, '|-')
:tag('td')
:wikitext('[[' .. item .. ']]')
return row
:done()
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(quantity or 1)
:done()
:tag('td')
:attr{ colspan = '10' }
:css{ ['text-align'] = 'right' }
:wikitext('[[File:' .. facility .. '.png|30px]] [[' .. facility .. ']]')
:done()
:done()
end
end


-- Recipe Table Head
-- Recipe Table Head
local out = {}
local out = mw.html.create('table')
table.insert(out, '{| class="wikitable"')
:addClass('wikitable')
:tag('tr')
table.insert(out, '! colspan="4" | Requirements')
:tag('th')
table.insert(out, '|-')
table.insert(out, '! colspan="2" | Facility')
:attr{ colspan = '13' }
:wikitext('Requirements')
table.insert(out, '| colspan="2" | ' .. (args.facility and '[[' .. args.facility .. ']]' or 'Unknown'))
:done()
table.insert(out, '|-')
:done()
table.insert(out, '! colspan="2" | Profession')
:tag('tr')
table.insert(out, '! Level')
:tag('th')
table.insert(out, '! XP')
:attr{ colspan = '2' }
table.insert(out, '|-')
:wikitext('Facility')
table.insert(out, '| colspan="2" style="text-align:center;" | ' .. (args.profession and '[[' .. args.profession .. ']]' or 'Unknown'))
:done()
table.insert(out, '| style="text-align: center;" | ' .. (args.level or 'Unknown'))
:tag('td')
table.insert(out, '| style="text-align: center;" | ' .. (args.exp or 'Unknown'))
:attr{ colspan = '11' }
table.insert(out, '|-')
:wikitext(args.facility and '[[' .. args.facility .. ']]' or 'Unknown')
:done()
:done()
:tag('tr')
:tag('th')
:attr{ colspan = '2' }
:wikitext('Profession')
:done()
:tag('th')
:wikitext('Level')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('XP')
:done()
:done()
:tag('tr')
:tag('td')
:attr{ colspan = '2' }
:css{ ['text-align'] = 'center' }
:wikitext(args.profession and '[[' .. args.profession .. ']]' or 'Unknown')
:done()
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext(args.level or 'Unknown')
:done()
:tag('td')
:attr{ colspan = '10' }
:css{ ['text-align'] = 'center' }
:wikitext(args.exp or 'Unknown')
:done()
:done()


-- Add raw materials
-- Add raw materials
-- Headers
-- Headers
:tag('tr')
table.insert(out, '! colspan="2" | Raw Ingredient')
:tag('th')
table.insert(out, '! Quantity')
:attr{ colspan = '2' }
table.insert(out, '! Cost')
:wikitext('Raw Ingredient')
table.insert(out, '|-')
:done()
:tag('th')
:wikitext('Quantity')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Cost')
:done()
:done()


-- Values
-- Values
for _, material in ipairs(rawMaterials) do
for _, material in ipairs(rawMaterials) do
local row = createRawMaterialRow(material)
out:node(createRawMaterialRow(material))
for _, value in ipairs(row) do
table.insert(out, value)
end
end
end


-- Add total raw cost
-- Add total raw cost
out
table.insert(out, '! colspan="3" | Total Raw cost')
:tag('tr')
table.insert(out, '| style="text-align: right;" | ' .. currency(rawMaterialCost))
:tag('th')
table.insert(out, '|-')
:attr{ colspan = '3' }
:wikitext('Total Raw cost')
:done()
:wikitext(currency_cell(rawMaterialCost))
:done()


-- Add Intermediate steps if required
-- Add Intermediate steps if required
-- Headers
-- Headers
if next(intermediateMaterials) ~= nil then
if next(intermediateMaterials) ~= nil then
-- Headers
-- Headers
out
table.insert(out, '! colspan="2" | Intermediate Ingredient')
:tag('tr')
table.insert(out, '! Quantity')
:tag('th')
table.insert(out, '! Facility')
:attr{ colspan = '2' }
table.insert(out, '|-')
:wikitext('Intermediate Ingredient')
:done()
:tag('th')
:wikitext('Quantity')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Faciltity')
:done()
:done()


-- Values
-- Values
for _, material in ipairs(intermediateMaterials) do
for _, material in ipairs(intermediateMaterials) do
local row = createIntermediateMaterialRow(material['name'])
out:node(createIntermediateMaterialRow(material.name))
for _, value in ipairs(row) do
table.insert(out, value)
end
end
end
end
end


-- Add output data
-- Add output data
out
-- Headers
-- Headers
table.insert(out, '! colspan="2" | Output')
:tag('tr')
table.insert(out, '! Quantity')
:tag('th')
table.insert(out, '! Value')
:attr{ colspan = '2' }
table.insert(out, '|-')
:wikitext('Output')
:done()
:tag('th')
:wikitext('Quantity')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Value')
:done()
:done()


-- Values
-- Values
:tag('tr')
table.insert(out, '| [[File:' .. args.output1 .. '.png|30px]]')
:tag('td')
table.insert(out, '| ' .. (args.output1 and '[[' .. args.output1 .. ']]' or 'Unknown'))
:wikitext('[[File:' .. args.output1 .. '.png|30px]]')
table.insert(out, '| style="text-align: right;" | ' .. (args.output1qty or 1))
:done()
table.insert(out, '| style="text-align: right;" | ' .. currency(output1TotalValue))
:tag('td')
table.insert(out, '|-')
:wikitext(args.output1 and '[[' .. args.output1 .. ']]' or 'Unknown')
:done()
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(args.output1qty or 1)
:done()
:wikitext(currency_cell(output1TotalValue))
:done()


-- Add profit data
-- Add profit data
:tag('tr')
table.insert(out, '! colspan="3" | Profit')
:tag('th')
table.insert(out, '| style="text-align: right;" | ' .. currency(output1TotalValue - rawMaterialCost))
:attr{ colspan = '3' }
table.insert(out, '|}')
:wikitext('Profit')
:done()
:wikitext(currency_cell(output1TotalValue - rawMaterialCost))
:done()


return table.concat(out, '\n')
return out
end
end