Editing Module:Sandbox/User:The Gaffer/Modules/Infobox Recipe
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
-- Lua module to replicate the functionality of the Infobox Recipe template |
|||
local p = {} |
local p = {} |
||
function p._main(frame) |
function p._main(frame) |
||
local args = frame |
local args = frame.args |
||
local mw = require('mw') |
local mw = require('mw') |
||
local currency = require('Module:Currency').parse |
|||
-- Define raw material costs based on Semantic MediaWiki queries |
|||
-- get the buy price from the query result |
|||
⚫ | |||
local function getCost(queryResult) |
|||
⚫ | |||
if type(queryResult) == "table" and queryResult[1]['Shop buy price'] then |
|||
⚫ | |||
return tonumber(queryResult[1]['Shop buy price']) or 0 |
|||
end |
|||
return 0 |
|||
end |
|||
⚫ | |||
-- Get buy prices of raw materials |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- Calculate output cost total and profit |
-- Calculate output cost total and profit |
||
⚫ | |||
⚫ | |||
⚫ | |||
local profit = output1costTotal - totalCost |
local profit = output1costTotal - totalCost |
||
-- |
-- Generate the output table |
||
local out = {} |
local out = {} |
||
table.insert(out, '{| class="wikitable"') |
table.insert(out, '{| class="wikitable"') |
||
Line 35: | Line 27: | ||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
table.insert(out, '! colspan="2" | Facility') |
table.insert(out, '! colspan="2" | Facility') |
||
table.insert(out, ' |
table.insert(out, '! colspan="2" | ' .. (args.facility and '[[' .. args.facility .. ']]' or 'Unknown')) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
table.insert(out, '! colspan="2" | Profession') |
table.insert(out, '! colspan="2" | Profession') |
||
Line 41: | Line 33: | ||
table.insert(out, '! XP') |
table.insert(out, '! XP') |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
table.insert(out, '| colspan="2 |
table.insert(out, '| colspan="2" | ' .. (args.profession and '[[' .. args.profession .. ']]' or 'Unknown')) |
||
table.insert(out, '| style="text-align: center;" | ' .. (args.level or 'Unknown')) |
table.insert(out, '| style="text-align: center;" | ' .. (args.level or 'Unknown')) |
||
table.insert(out, '| style="text-align: center;" | ' .. (args.exp or 'Unknown')) |
table.insert(out, '| style="text-align: center;" | ' .. (args.exp or 'Unknown')) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
-- Add raw materials |
|||
-- Headers |
|||
table.insert(out, '! colspan="2" | Raw Ingredient') |
table.insert(out, '! colspan="2" | Raw Ingredient') |
||
table.insert(out, '! Quantity') |
table.insert(out, '! Quantity') |
||
Line 53: | Line 42: | ||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
-- Add each raw material to the table |
|||
-- Values |
|||
if args.rawmat1 then |
if args.rawmat1 then |
||
table.insert(out, '| [[File:' .. args.rawmat1 .. '.png|30px]]') |
table.insert(out, '| [[File:' .. args.rawmat1 .. '.png|30px]]') |
||
table.insert(out, '| [[' .. args.rawmat1 .. ']]') |
table.insert(out, '| [[' .. args.rawmat1 .. ']]') |
||
table.insert(out, '| style="text-align: right;" | ' .. (args.rawmat1qty or 1)) |
table.insert(out, '| style="text-align: right;" | ' .. (args.rawmat1qty or 1)) |
||
table.insert(out, '| style="text-align: right;" | ' .. |
table.insert(out, '| style="text-align: right;" | ' .. rawmat1cost) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
end |
end |
||
Line 65: | Line 54: | ||
table.insert(out, '| [[' .. args.rawmat2 .. ']]') |
table.insert(out, '| [[' .. args.rawmat2 .. ']]') |
||
table.insert(out, '| style="text-align: right;" | ' .. (args.rawmat2qty or 1)) |
table.insert(out, '| style="text-align: right;" | ' .. (args.rawmat2qty or 1)) |
||
table.insert(out, '| style="text-align: right;" | ' .. |
table.insert(out, '| style="text-align: right;" | ' .. rawmat2cost) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
end |
end |
||
Line 72: | Line 61: | ||
table.insert(out, '| [[' .. args.rawmat3 .. ']]') |
table.insert(out, '| [[' .. args.rawmat3 .. ']]') |
||
table.insert(out, '| style="text-align: right;" | ' .. (args.rawmat3qty or 1)) |
table.insert(out, '| style="text-align: right;" | ' .. (args.rawmat3qty or 1)) |
||
table.insert(out, '| style="text-align: right;" | ' .. |
table.insert(out, '| style="text-align: right;" | ' .. rawmat3cost) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
end |
end |
||
Line 78: | Line 67: | ||
-- Add total raw cost |
-- Add total raw cost |
||
table.insert(out, '! colspan="3" | Total Raw cost') |
table.insert(out, '! colspan="3" | Total Raw cost') |
||
table.insert(out, '| style="text-align: right;" | ' .. |
table.insert(out, '| style="text-align: right;" | ' .. totalCost) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
-- Add Intermediate steps if required |
|||
-- Headers |
|||
table.insert(out, '! colspan="2" | Intermediate Ingredient') |
|||
table.insert(out, '! Quantity') |
|||
table.insert(out, '! Facility') |
|||
table.insert(out, '|-') |
|||
-- Values |
|||
if args.preparedmat1 then |
|||
table.insert(out, '| [[File:' .. args.preparedmat1 .. '.png|30px]]') |
|||
table.insert(out, '| [[' .. args.preparedmat1 .. ']]') |
|||
table.insert(out, '| style="text-align: right;" | ' .. (args.preparedmat1qty or 1)) |
|||
table.insert(out, '| style="text-align: right;" | [[File:' .. args.preparedmat1fac .. '.png|30px]] [[' .. args.preparedmat1fac .. ']]') |
|||
table.insert(out, '|-') |
|||
end |
|||
if args.preparedmat2 then |
|||
table.insert(out, '| [[File:' .. args.preparedmat2 .. '.png|30px]]') |
|||
table.insert(out, '| [[' .. args.preparedmat2 .. ']]') |
|||
table.insert(out, '| style="text-align: right;" | ' .. (args.preparedmat2qty or 1)) |
|||
table.insert(out, '| style="text-align: right;" | [[File:' .. args.preparedmat2fac .. '.png|30px]] [[' .. args.preparedmat2fac .. ']]') |
|||
table.insert(out, '|-') |
|||
end |
|||
if args.preparedmat3 then |
|||
table.insert(out, '| [[File:' .. args.preparedmat3 .. '.png|30px]]') |
|||
table.insert(out, '| [[' .. args.preparedmat3 .. ']]') |
|||
table.insert(out, '| style="text-align: right;" | ' .. (args.preparedmat3qty or 1)) |
|||
table.insert(out, '| style="text-align: right;" | [[File:' .. args.preparedmat3fac .. '.png|30px]] [[' .. args.preparedmat3fac .. ']]') |
|||
table.insert(out, '|-') |
|||
end |
|||
-- Add output data |
-- Add output data and profit |
||
-- Headers |
|||
table.insert(out, '! colspan="2" | Output') |
table.insert(out, '! colspan="2" | Output') |
||
table.insert(out, '! Quantity') |
table.insert(out, '! Quantity') |
||
table.insert(out, '! Value') |
table.insert(out, '! Value') |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
-- Values |
|||
table.insert(out, '| [[File:' .. args.output1 .. '.png|30px]]') |
|||
table.insert(out, '| ' .. (args.output1 and '[[' .. args.output1 .. ']]' or 'Unknown')) |
table.insert(out, '| ' .. (args.output1 and '[[' .. args.output1 .. ']]' or 'Unknown')) |
||
table.insert(out, '| style="text-align: right;" | ' .. (args.output1qty or 1)) |
table.insert(out, '| style="text-align: right;" | ' .. (args.output1qty or 1)) |
||
table.insert(out, '| style="text-align: right;" | ' .. |
table.insert(out, '| style="text-align: right;" | ' .. output1costTotal) |
||
table.insert(out, '|-') |
table.insert(out, '|-') |
||
-- Add profit data |
|||
table.insert(out, '! colspan="3" | Profit') |
table.insert(out, '! colspan="3" | Profit') |
||
table.insert(out, '| style="text-align: right;" | ' .. |
table.insert(out, '| style="text-align: right;" | ' .. profit) |
||
table.insert(out, '|}') |
table.insert(out, '|}') |
||