Module:Crafts/ingredient
Jump to navigation
Jump to search
Internal sub-module pertaining to the set of {{crafts}}.
Normalizes an ingredients input and outputs it in a properly formatted way.
local item = require('Module:Item').go
local metals = {
['Copper/Tin'] = 1,
['Silver/Tungsten'] = 1,
['Gold/Platinum'] = 1,
['Iron/Lead'] = 1,
['Cobalt/Palladium'] = 1,
['Mythril/Orichalcum'] = 1,
['Adamantite/Titanium'] = 1,
['Tin/Copper'] = 2,
['Tungsten/Silver'] = 2,
['Platinum/Gold'] = 2,
['Lead/Iron'] = 2,
['Palladium/Cobalt'] = 2,
['Orichalcum/Mythril'] = 2,
['Titanium/Adamantite'] = 2,
}
local function split(name)
local item1a, item1b, item2a, item2b = name:match("^(%S+)%s*(.-)/(%S+)%s*(.-)$")
if item1a then
local x = metals[item1a..'/'..item2a]
if tostring(item1b) == '' and x then
item1b = item2b
end
if x == 2 then
return item2a..' '..item2b, item1a..' '..item1b
else
return item1a..' '..item1b, item2a..' '..item2b
end
else
return name
end
end
-- main return object
return {
go = function(frame)
local _input = mw.text.trim(frame.args[1])
local _basepage = mw.text.trim(frame.args[2])
local icons
local result = ''
for name, amount in _input:gmatch("(.-)¦(.-)¶") do
local li = ''
item1, item2 = split(name)
item1 = item1:sub(1, 2) == '#' and item1:sub(2) or item1
if item2 then
item2 = item2:sub(1, 2) == '#' and item2:sub(2) or item2
end
if item2 then
li = li .. item(frame, {item1, item1})
li = li .. " ''or'' "
li = li .. item(frame, {item2, item2})
else
li = li .. item(frame, {name, name})
end
result = result .. mw.text.tag('li', nil, li .. amount)
end
return mw.text.tag('ul', nil, result)
end
}