Module:Crafting: Difference between revisions

From Vintage Story Wiki
mNo edit summary
mNo edit summary
Line 5: Line 5:
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
local cells = {'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3', 'out'}
local cells = {'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3', 'out'}
local ingredients = ''
local inputItems = {}
local inputItems = {}
for s in pairs(cells) do
for s in pairs(cells) do
ingredients = ingredients .. s
if _G.args[s] then
if _G.args[s] then
table.insert(inputItems, '[[' .. _G.args[s] .. ']]')
table.insert(inputItems, '[[' .. _G.args[s] .. ']]')
end
end
end
end
local ingredients = table.concat(inputItems)
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 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;">'

Revision as of 22:11, 22 August 2022

Documentation for this module may be created at Module:Crafting/doc

local p = {}

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'}
	
	local ingredients = ''
	
	local inputItems = {}
	for s in pairs(cells) do
		ingredients = ingredients .. s
		if _G.args[s] then
			table.insert(inputItems, '[[' .. _G.args[s] .. ']]')
		end
	end
		
	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 hCells = ''
	for i,v in pairs(cells) do
		local str = frame:expandTemplate{title = 'Item cell', args = {i, _G.args[v], _G.args[v .. '_alt']} }
		hCells = hCells .. str
	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