Module:Crafting: Difference between revisions
From Vintage Story Wiki
mNo edit summary |
mNo edit summary |
||
(19 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local i18n = langVars.processLang(lang) | local i18n = langVars.processLang(lang) | ||
function p. | function p.link( str ) | ||
local | local link = '' | ||
local image | local image, name = str | ||
local split = {} | local split = {} | ||
if | |||
split = | -- Checks for localized 'Any' and links to appropriate page | ||
if str:match(i18n.any .. '%s(.*)') then | |||
split = str:match(i18n.any .. '%s(.*)') | |||
name, image = langVars.link(split) | |||
link = i18n.any .. ' [[' .. name .. '| ' .. split .. ']]' | |||
end | end | ||
if | if link == '' then | ||
name, image = langVars.link(str) | |||
link = '[[' .. name .. '| ' .. str .. ']]' | |||
image = name | |||
end | end | ||
return | return name, image, link | ||
end | end | ||
Line 28: | Line 32: | ||
-- Inserts the item name at the key of the same name to avoid duplicates | -- Inserts the item name at the key of the same name to avoid duplicates | ||
local | local items = {} | ||
local | local ingredients = {} | ||
local hCells = '' | |||
for i,v in pairs(cells) do | for i,v in pairs(cells) do | ||
local name, link, image | |||
if _G.args[v] and i ~= 10 then | if _G.args[v] and i ~= 10 then | ||
name, image, link = p.link(_G.args[v]) | |||
items[name] = link | |||
elseif i == 10 then | |||
name, image, link = p.link(_G.args[v]) | |||
end | end | ||
local str = frame:expandTemplate{title = 'Item cell', args = {i, image, name, _G.args[v .. '_alt']} } | |||
hCells = hCells .. str | |||
end | end | ||
for i,v in pairs(items) do | |||
for i,v in pairs( | |||
table.insert(ingredients, v) | table.insert(ingredients, v) | ||
end | end | ||
ingredients = table.concat(ingredients, ' +<br>') | ingredients = table.concat(ingredients, ' +<br>') | ||
Line 54: | Line 62: | ||
if args.header then | if args.header then | ||
header = '<table class="wikitable mw-collapsible"> <tr><th style="width:200px"><b>Ingredients</b></th> <th><b>Crafting recipe</b></th>' .. notes .. '</tr>' | header = '<table class="wikitable mw-collapsible"> <tr><th style="width:200px"><b>Ingredients</b></th> <th><b>Crafting recipe</b></th>' .. notes .. '</tr>' | ||
end | end | ||
Latest revision as of 04:48, 23 August 2022
Documentation for this module may be created at Module:Crafting/doc
local p = {}
local lang = mw.getContentLanguage():getCode()
local langVars = require( 'Module:LangVars' )
local i18n = langVars.processLang(lang)
function p.link( str )
local link = ''
local image, name = str
local split = {}
-- Checks for localized 'Any' and links to appropriate page
if str:match(i18n.any .. '%s(.*)') then
split = str:match(i18n.any .. '%s(.*)')
name, image = langVars.link(split)
link = i18n.any .. ' [[' .. name .. '| ' .. split .. ']]'
end
if link == '' then
name, image = langVars.link(str)
link = '[[' .. name .. '| ' .. str .. ']]'
image = name
end
return name, image, link
end
function p.main(f)
args = require( 'Module:ProcessArgs' ).merge( true )
local frame = mw.getCurrentFrame()
local cells = {'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3', 'out'}
-- Inserts the item name at the key of the same name to avoid duplicates
local items = {}
local ingredients = {}
local hCells = ''
for i,v in pairs(cells) do
local name, link, image
if _G.args[v] and i ~= 10 then
name, image, link = p.link(_G.args[v])
items[name] = link
elseif i == 10 then
name, image, link = p.link(_G.args[v])
end
local str = frame:expandTemplate{title = 'Item cell', args = {i, image, name, _G.args[v .. '_alt']} }
hCells = hCells .. str
end
for i,v in pairs(items) do
table.insert(ingredients, v)
end
ingredients = table.concat(ingredients, ' +<br>')
local background = '<td><div style="position:relative; width:170px; height:240px; background: rgb(91,76,62); background: linear-gradient(to bottom, rgba(91,76,62,1) 0px, rgba(91,76,62,0) 15px, rgba(56,43,30,0) calc(100% - 15px), rgba(56,43,30,1) 100%), linear-gradient(to left, rgba(91,76,62,1) 0px, rgba(69,52,36,1) 15px, #403529 50%, rgba(69,52,36,1) calc(100% - 15px), rgba(56,43,30,1) 100%); margin:auto;">'
local notes = ''
if args.notes then
notes = '<th style="width:400px"><b>Notes</b></th>'
end
local header = ''
if args.header then
header = '<table class="wikitable mw-collapsible"> <tr><th style="width:200px"><b>Ingredients</b></th> <th><b>Crafting recipe</b></th>' .. notes .. '</tr>'
end
local body = header .. '<tr style="text-align:center;"><td>' .. ingredients .. '</td>' .. background .. hCells .. '</td>'
if notes ~= '' then
body = body .. '<td style="text-align:left;">' .. args.notes .. '</td>'
end
body = body .. '</tr>'
if args.footer then
body = body .. '</table>'
end
return body
end
return p