Module:Crafts/row

local ingredient_format = require('Module:Crafts/ingredient').format local item_link = require('Module:Item').go

local result_cell = function(frame, result_info) local item, nolink, image, id, icons, amount, version = unpack(mw.text.split(result_info, '¦', true)) if version ~= '' then icons='n'	end local str = item_link(frame, {item, nolink=nolink, image=image, id=id, icons=icons, small='y'})..amount if version ~= '' then str = str..' ('..frame:expandTemplate{ title = 'version icons', args = {version} }..')' end return str end

local row = function(frame, row_info, page) if row_info == '' then return '' end local result_info, ingredients_info = unpack(mw.text.split(row_info, '«', true))

-- result cell local str = ' '..result_cell(frame, result_info) --ingredients cell str = str .. ' ' .. ingredient_format(frame, ingredients_info, page).. ' '

return str end

local group = function(frame)

-- 	local page = frame.args['page']

-- first row: result, ingredient list, craftstation(if needed) local tool_info, result_info, ingredients_info = frame.args['group_buffer_first']:match("^(.-)«(.-)«(.-)$")

-- result cell local str = result_cell(frame, result_info) -- ingredients cell str = str .. ' '..ingredient_format(frame, ingredients_info, page).. ' '	-- craft station if frame.args['nostation'] == '' then str = str .. '' ..frame:expandTemplate{title = 'crafts/tool', args = {tool_info}}..' ' end str = str .. ' '

-- other rows in this group:(only result and ingredient list cells.) for row_info in mw.text.gsplit(frame.args['group_buffer'], '»', true) do str = str .. row(frame, row_info, page) end return str end

-- main return object return {

-- serialize args serialize = function(frame) local args = {} for k, v in pairs(frame:getParent.args) do		args[k] = v	end args['tool'] = frame.args['tool'] args['link'] = nil args['id'] = nil args['icons'] = nil local str = '' for k, v in pairs( args ) do str = str .. '»' .. k .. '¦' .. mw.text.trim(v) end return str end,

-- restore crafts row using serialized args restore = function(frame) local args = {} for str in mw.text.gsplit(frame.args[1], '»', true) do		if str~='' then local k,v = unpack(mw.text.split(str, '¦', true)) args[k] = v		end end args['link'] = nil args['id'] = nil args['icons'] = nil return frame:expandTemplate{ title = 'crafts row', args = args } end,

-- format

format = function(frame) local str = '' if frame.args['new'] ~= '' then if frame.args['group_count'] ~= '' then str = ' '..group(frame)..' ' end frame:preprocess('') else frame:preprocess('') end return str end,

lastgroup = function(frame) -- empty table. if frame.args['group_count'] == '' then return ' ' else return group(frame) end end,

}