Module:Recipe: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Module:Recipe | -- Module:Recipe | ||
-- Displays crafting recipes | -- Displays crafting recipes in a clean table format | ||
-- Usage: {{#invoke:Recipe| | -- Usage: {{#invoke:Recipe|list|title=Recipes|recipe1=Item1+Item2=Output}} | ||
local p = {} | local p = {} | ||
| Line 25: | Line 25: | ||
end | end | ||
-- Main display function for a single recipe | -- Main display function for a single recipe (simple inline display) | ||
function p.display(frame) | function p.display(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
| Line 94: | Line 94: | ||
end | end | ||
-- Display a list of multiple recipes | -- Display a list of multiple recipes in a styled table | ||
function p.list(frame) | function p.list(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
| Line 159: | Line 159: | ||
table.insert(html, '<div class="recipe-list">') | table.insert(html, '<div class="recipe-list">') | ||
-- Header row | -- Title | ||
if title ~= "" then | |||
table.insert(html, string.format('<div class="recipe-list-title">%s</div>', title)) | |||
end | |||
-- Table with wikitable class for consistent styling | |||
table.insert(html, '<table class="wikitable sortable recipe-table">') | |||
-- Header row | |||
table.insert(html, '<tr>') | |||
table.insert(html, '<th>Item</th>') | |||
if hasAnyStation then | if hasAnyStation then | ||
table.insert(html, ' | table.insert(html, '<th>Station</th>') | ||
end | end | ||
table.insert(html, '<th>Materials</th>') | |||
table.insert(html, '</tr>') | |||
-- Render each recipe | -- Render each recipe | ||
for _, recipe in ipairs(recipes) do | for _, recipe in ipairs(recipes) do | ||
table.insert(html, '<tr | table.insert(html, '<tr>') | ||
-- | -- Item (output) cell | ||
local outQtyStr = "" | local outQtyStr = "" | ||
if tonumber(recipe.outputQty) > 1 then | if tonumber(recipe.outputQty) > 1 then | ||
outQtyStr = recipe.outputQty .. "× " | outQtyStr = recipe.outputQty .. " × " | ||
end | end | ||
table.insert(html, string.format( | table.insert(html, string.format( | ||
'<td class="recipe-cell- | '<td class="recipe-cell-item"><span class="recipe-item-inline">{{Sprite|%s|%s}} [[%s]]</span></td>', | ||
recipe.output, spriteSize | recipe.output, spriteSize, recipe.output | ||
)) | )) | ||
| Line 207: | Line 195: | ||
if recipe.station ~= "" then | if recipe.station ~= "" then | ||
table.insert(html, string.format( | table.insert(html, string.format( | ||
'<td class="recipe-cell-station"><span class="recipe-inline | '<td class="recipe-cell-station"><span class="recipe-item-inline">{{Sprite|%s|%s}} [[%s]]</span></td>', | ||
recipe.station, spriteSize, recipe.station | recipe.station, spriteSize, recipe.station | ||
)) | )) | ||
else | else | ||
table.insert(html, '<td class="recipe-cell-station"></td>') | table.insert(html, '<td class="recipe-cell-station">None</td>') | ||
end | end | ||
end | end | ||
-- Materials cell | |||
table.insert(html, '<td class="recipe-cell-materials">') | |||
for j, inp in ipairs(recipe.inputs) do | |||
local qtyStr = "1" | |||
if tonumber(inp.quantity) > 1 then | |||
qtyStr = inp.quantity | |||
end | |||
-- Alternate row colors for materials | |||
local rowClass = (j % 2 == 0) and "recipe-material-even" or "recipe-material-odd" | |||
table.insert(html, string.format( | |||
'<div class="%s"><span class="recipe-item-inline">%s × {{Sprite|%s|%s}} [[%s]]</span></div>', | |||
rowClass, qtyStr, inp.name, spriteSize, inp.name | |||
)) | |||
end | |||
table.insert(html, '</td>') | |||
table.insert(html, '</tr>') | table.insert(html, '</tr>') | ||
Latest revision as of 22:03, 27 January 2026
Module:Recipe Documentation
[edit source]This module displays crafting recipes showing how items combine to create new items.
Single Recipe
[edit source]Display a single crafting recipe:
{{#invoke:Recipe|display
|input1=Pumpkin_Slice
|input2=Empty_Bowl
|output=Pumpkin_Puree
}}
With quantities:
{{#invoke:Recipe|display
|input1=Pumpkin_Slice
|input1qty=3
|input2=Empty_Bowl
|input2qty=2
|output=Pumpkin_Puree
}}
Recipe Parameters
[edit source]| Parameter | Description |
|---|---|
| input1, input2, ... input6 | Input item names (up to 6 inputs) |
| input1qty, input2qty, etc. | Quantity for each input (default: 1) |
| output | The resulting item name |
| outputqty | Quantity produced (default: 1) |
| station | Required crafting station (optional) |
| spriteSize | Size of item sprites (default: 32) |
Recipe List
[edit source]Display multiple recipes in a table:
{{#invoke:Recipe|list
|title=Weapon Recipes
|recipe1=Wood+Stone=Stone Axe
|recipe2=Wood+Iron Bar=Iron Sword@Anvil
|recipe3=2xLeather+Iron Bar=Leather Armor@Workbench
|recipe4=3xWood+2xRope=Raft
}}
Recipe String Format
[edit source]Each recipe uses the format:
[qty]xItem1+[qty]xItem2=Output[@Station]
Examples:
Wood+Stone=Axe- Simple recipeWood+Iron Bar=Sword@Anvil- Recipe with station2xWood+3xStone=Wall- Recipe with quantities2xIron Bar=4xNails@Anvil- Multiple output
Inline Recipe
[edit source]For showing a recipe within text:
Combine {{#invoke:Recipe|inline|Wood|Stone|Axe}} to make your first tool.
Examples
[edit source]Cooking Recipes
[edit source]{{#invoke:Recipe|list
|title=Cooking Recipes
|recipe1=Raw Meat+Salt=Cooked Meat@Campfire
|recipe2=Flour+Water+Egg=Dough@Kitchen
|recipe3=Dough+Blueberry=Blueberry Muffin@Oven
|recipe4=2xFish+Lemon=Fish Dinner@Campfire
}}
Weapon Crafting
[edit source]{{#invoke:Recipe|list
|title=Weapons
|recipe1=2xWood+Silver Bar=Silver Dagger@Anvil
|recipe2=3xWood+2xString+Iron Bar=Crossbow@Workbench
|recipe3=Wood+4xIron Bar=Battle Axe@Anvil
|recipe4=2xWood+Iron Bar=Shovel@Workbench
}}
Single Featured Recipe
[edit source]{{#invoke:Recipe|display
|input1=Silver Bar
|input1qty=2
|input2=Wood
|input3=Magic Gem
|output=Silver Dagger
|station=Enchanting Table
|spriteSize=48
}}
Required CSS
[edit source]Add this to your wiki's Common.css:
/* Recipe Container */
.recipe-container {
display: flex;
align-items: center;
gap: 10px;
padding: 10px;
background-color: #1a1a2e;
border: 2px solid #4a4a6a;
border-radius: 5px;
margin: 10px 0;
width: fit-content;
}
.recipe-inputs {
display: flex;
align-items: center;
gap: 5px;
}
.recipe-slot {
display: flex;
flex-direction: column;
align-items: center;
padding: 5px;
background-color: #2a2a4e;
border: 1px solid #3a3a5a;
border-radius: 3px;
position: relative;
min-width: 50px;
}
.recipe-slot-empty {
background-color: #1a1a2e;
min-width: 50px;
min-height: 50px;
}
.recipe-quantity {
position: absolute;
bottom: 2px;
right: 2px;
background-color: #000;
color: #fff;
font-size: 12px;
padding: 1px 4px;
border-radius: 2px;
}
.recipe-item-name {
font-size: 10px;
color: #aaa;
margin-top: 3px;
text-align: center;
}
.recipe-plus {
font-size: 24px;
color: #888;
padding: 0 5px;
}
.recipe-arrow {
font-size: 28px;
color: #9edc60;
padding: 0 10px;
}
.recipe-output {
display: flex;
align-items: center;
}
.recipe-station {
font-size: 12px;
color: #9bddff;
margin-top: 5px;
font-style: italic;
}
/* Recipe List/Table */
.recipe-list {
background-color: #1a1a2e;
border: 2px solid #4a4a6a;
border-radius: 5px;
padding: 10px;
margin: 10px 0;
}
.recipe-list-title {
font-size: 18px;
font-weight: bold;
color: #ffd700;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px solid #4a4a6a;
}
.recipe-table {
width: 100%;
border-collapse: collapse;
}
.recipe-table-header th {
text-align: left;
padding: 8px;
color: #aaa;
border-bottom: 1px solid #4a4a6a;
}
.recipe-row td {
padding: 8px;
border-bottom: 1px solid #2a2a4e;
}
.recipe-cell-arrow {
color: #9edc60;
font-size: 20px;
text-align: center;
width: 40px;
}
.recipe-cell-station {
color: #9bddff;
}
.recipe-inline-item {
display: inline-flex;
align-items: center;
gap: 4px;
}
/* Inline recipe */
.recipe-inline {
display: inline-flex;
align-items: center;
gap: 4px;
background-color: #2a2a4e;
padding: 2px 6px;
border-radius: 3px;
}
-- Module:Recipe
-- Displays crafting recipes in a clean table format
-- Usage: {{#invoke:Recipe|list|title=Recipes|recipe1=Item1+Item2=Output}}
local p = {}
-- Helper to get args from either direct invoke or template
local function getArgs(frame)
local args = {}
local parent = frame:getParent()
if parent and parent.args then
for k, v in pairs(parent.args) do
args[k] = v
end
end
if frame.args then
for k, v in pairs(frame.args) do
args[k] = v
end
end
return args
end
-- Main display function for a single recipe (simple inline display)
function p.display(frame)
local args = getArgs(frame)
local spriteSize = args.spriteSize or "32"
-- Collect inputs (support up to 6 inputs)
local inputs = {}
for i = 1, 6 do
local item = args["input" .. i] or args["in" .. i]
local qty = args["input" .. i .. "qty"] or args["in" .. i .. "qty"] or "1"
if item and item ~= "" then
table.insert(inputs, {name = item, quantity = qty})
end
end
-- Output
local output = args.output or args.out or "Unknown"
local outputQty = args.outputqty or args.outqty or "1"
-- Station/workbench (optional)
local station = args.station or args.workbench or ""
-- Build HTML
local html = {}
table.insert(html, '<div class="recipe-container">')
-- Inputs section
table.insert(html, '<div class="recipe-inputs">')
for i, input in ipairs(inputs) do
local qtyDisplay = ""
if tonumber(input.quantity) > 1 then
qtyDisplay = string.format('<span class="recipe-quantity">%s</span>', input.quantity)
end
table.insert(html, string.format(
'<div class="recipe-slot">{{Sprite|%s|%s}}%s</div>',
input.name, spriteSize, qtyDisplay
))
if i < #inputs then
table.insert(html, '<span class="recipe-plus">+</span>')
end
end
table.insert(html, '</div>')
-- Arrow
table.insert(html, '<div class="recipe-arrow">→</div>')
-- Output section
local outQtyDisplay = ""
if tonumber(outputQty) > 1 then
outQtyDisplay = string.format('<span class="recipe-quantity">%s</span>', outputQty)
end
table.insert(html, '<div class="recipe-output">')
table.insert(html, string.format(
'<div class="recipe-slot">{{Sprite|%s|%s}}%s</div>',
output, spriteSize, outQtyDisplay
))
table.insert(html, '</div>')
table.insert(html, '</div>')
-- Station requirement (if specified)
if station ~= "" then
table.insert(html, string.format('<div class="recipe-station">Requires: {{Sprite|%s|20}} %s</div>', station, station))
end
return frame:preprocess(table.concat(html, '\n'))
end
-- Display a list of multiple recipes in a styled table
function p.list(frame)
local args = getArgs(frame)
local title = args.title or "Recipes"
local spriteSize = args.spriteSize or "24"
-- First pass: parse all recipes and check if any have stations
local recipes = {}
local hasAnyStation = false
local i = 1
while args["recipe" .. i] or args["r" .. i] do
local recipeStr = args["recipe" .. i] or args["r" .. i]
local inputPart, outputPart = recipeStr:match("^(.+)=(.+)$")
if inputPart and outputPart then
local station = ""
local output = outputPart
if outputPart:find("@") then
output, station = outputPart:match("^(.+)@(.+)$")
if station and station ~= "" then
hasAnyStation = true
station = station:match("^%s*(.-)%s*$")
end
end
output = output:match("^%s*(.-)%s*$")
local inputItems = {}
for item in inputPart:gmatch("[^+]+") do
item = item:match("^%s*(.-)%s*$")
if item ~= "" then
local qty, name = item:match("^(%d+)x(.+)$")
if qty then
table.insert(inputItems, {name = name:match("^%s*(.-)%s*$"), quantity = qty})
else
table.insert(inputItems, {name = item, quantity = "1"})
end
end
end
local outQty, outName = output:match("^(%d+)x(.+)$")
if not outQty then
outQty = "1"
outName = output
else
outName = outName:match("^%s*(.-)%s*$")
end
table.insert(recipes, {
inputs = inputItems,
output = outName,
outputQty = outQty,
station = station or ""
})
end
i = i + 1
end
-- Build HTML
local html = {}
table.insert(html, '<div class="recipe-list">')
-- Title
if title ~= "" then
table.insert(html, string.format('<div class="recipe-list-title">%s</div>', title))
end
-- Table with wikitable class for consistent styling
table.insert(html, '<table class="wikitable sortable recipe-table">')
-- Header row
table.insert(html, '<tr>')
table.insert(html, '<th>Item</th>')
if hasAnyStation then
table.insert(html, '<th>Station</th>')
end
table.insert(html, '<th>Materials</th>')
table.insert(html, '</tr>')
-- Render each recipe
for _, recipe in ipairs(recipes) do
table.insert(html, '<tr>')
-- Item (output) cell
local outQtyStr = ""
if tonumber(recipe.outputQty) > 1 then
outQtyStr = recipe.outputQty .. " × "
end
table.insert(html, string.format(
'<td class="recipe-cell-item"><span class="recipe-item-inline">{{Sprite|%s|%s}} [[%s]]</span></td>',
recipe.output, spriteSize, recipe.output
))
-- Station cell (only if any recipe has a station)
if hasAnyStation then
if recipe.station ~= "" then
table.insert(html, string.format(
'<td class="recipe-cell-station"><span class="recipe-item-inline">{{Sprite|%s|%s}} [[%s]]</span></td>',
recipe.station, spriteSize, recipe.station
))
else
table.insert(html, '<td class="recipe-cell-station">None</td>')
end
end
-- Materials cell
table.insert(html, '<td class="recipe-cell-materials">')
for j, inp in ipairs(recipe.inputs) do
local qtyStr = "1"
if tonumber(inp.quantity) > 1 then
qtyStr = inp.quantity
end
-- Alternate row colors for materials
local rowClass = (j % 2 == 0) and "recipe-material-even" or "recipe-material-odd"
table.insert(html, string.format(
'<div class="%s"><span class="recipe-item-inline">%s × {{Sprite|%s|%s}} [[%s]]</span></div>',
rowClass, qtyStr, inp.name, spriteSize, inp.name
))
end
table.insert(html, '</td>')
table.insert(html, '</tr>')
end
table.insert(html, '</table>')
table.insert(html, '</div>')
return frame:preprocess(table.concat(html, '\n'))
end
-- Simple inline recipe (for use within text)
function p.inline(frame)
local args = getArgs(frame)
local spriteSize = args.spriteSize or "16"
local input1 = args[1] or args.input1 or ""
local input2 = args[2] or args.input2 or ""
local output = args[3] or args.output or ""
local html = string.format(
'<span class="recipe-inline">{{Sprite|%s|%s}} + {{Sprite|%s|%s}} → {{Sprite|%s|%s}}</span>',
input1, spriteSize, input2, spriteSize, output, spriteSize
)
return frame:preprocess(html)
end
return p