Module:Item

local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame, {	valueFunc = function (key, value)		if key == 2 or key == 3 or key == 4 or key == 5 == locations then			return value		elseif key == 3 and key == summary then			return value		elseif value then			value = mw.text.trim(value)			return value		else			return value		end		return nil	end }) return p._main(args) end

function p._main(args) local item = args[1] or nil local itemname = args[1] or '???' local rarity = args["rarity"] or nil local sell = args["sell"] or nil local drop = args["drop"] or nil local lost = args["lost"] or nil local locations = args["locations"] or nil local sprite = args["sprite"] or nil local rowspan = args["rowspan"] or nil --Custom rowspan for each param# local locspan = args["locspan"] or nil --Custom colspan for Locations local param2 = args[2] or nil local param3 = args[3] or nil local param4 = args[4] or nil local param5 = args[5] or nil

local row = mw.html.create --Create base for all rows local img = mw.html.create --Create node for the item sprite local name = mw.html.create --Create node for the item name local attrrow = mw.html.create --Create base attributes row local paramcell = mw.html.create --Create node for optional parameters local locrow = mw.html.create --Create node for locations row

local lspan = 2 --lspan Is the overall colspan for the locations row. Default Is 2 and Increases for each param# cell

--Manual rowspan if rowspan then --If custom rowspawn parameter local pspan = rowspan --pspan Is the overall rowspan of each param# cell end --Removes ` In Item name ( I should just use the IS module ) if item then if string.match(item, "`") then item = string.gsub(item, "`", "") end end --Sprite cell if item and mw.getCurrentFrame:callParserFunction("filepath", "" .. item .. ".png") ~= "" and not sprite then --If file exists and no custom sprite img :tag('td'):wikitext(''):css('text-align', 'center') :done elseif sprite then --If custom sprite, use that img :tag('td'):wikitext(''):css('text-align', 'center') :done else --If there's no sprite img :tag('td'):wikitext(''):css('text-align', 'center') :done end

if string.len(itemname) >= 10 and string.len(itemname) < 18 then --Nowrap for long ( but not too long ) Item names name :tag('td'):attr('id', itemname):wikitext(itemname):css('white-space', 'nowrap') :done else name :tag('td'):attr('id', itemname):wikitext(itemname) :done end

--Adding an attribute creates a new row, so any of the free cells need to span down to It	if rarity or sell or drop or lost then --If there's an attribute paramspan = 2 --Rowspan of each param[#] cell if rowspan then pspan = rowspan + paramspan else pspan = paramspan end

--Attributes local attribs = {} --Array of attributes --Attributes, If any, get added

--Rarity if rarity then table.insert(attribs, 'Rarity: '..rarity) end

--Sellability if sell and sell ~= 'no' then table.insert(attribs, 'Sell Price: '..sell) elseif sell and sell == 'no' then table.insert(attribs, 'Cannot be sold.') end

--Dropability if drop == 'no' then table.insert(attribs, 'Cannot be dropped.') end

--Losability if lost == 'no' then table.insert(attribs, 'Cannot be lost.') end

--Putting attributes together --Attributes other than the first --Will have ( a line break ) before them for k = 2, #attribs do --For k(ey) ( starting at 2 ) In attribs ( the table ) attribs[k] = ' '..attribs[k] --attribs[k] Is the current Item of the array end

attribs = table.concat(attribs, "")

attrrow :tag('tr') --Attributes row :tag('td'):css('white-space', 'nowrap'):attr('colspan', '2'):wikitext(' '..attribs..' ') --Attributes cell

else --If no attributes, no rowspan for free cells paramspan = 0 end

if param2 and param3 ~= 'summary' then paramcell :tag('td'):wikitext(param2):attr('rowspan', pspan) :done lspan = 3

elseif param2 and param3 == 'summary' then paramcell :tag('td'):wikitext(param2):attr('rowspan', pspan):attr('colspan', '2') :done lspan = 4 end

if param3 and param3 ~= 'summary' then paramcell :tag('td'):wikitext(param3):attr('rowspan', pspan) :done lspan = 4 elseif param3 == 'summary' then lspan = 5 end

if param4 then paramcell :tag('td'):wikitext(param4):attr('rowspan', pspan) :done lspan = 6 end

if param5 then paramcell :tag('td'):wikitext(param5):attr('rowspan', pspan) :done lspan = 7 end

if locspan then --If custom location colspan parameter lspan = locspan end

if locations and string.find(locations, 'collaps') then --If there's collapsible content In locations locrow :tag('tr') :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', lspan):css('width','100%') :done elseif locations then locrow :tag('tr') :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', lspan) :done end

row:tag('tr') :node(img) --Item sprite cell :node(name) --Item name cell :node(paramcell) --Free space cells :node(attrrow) --Base attributes row :done :node(locrow) --Locations row :done

return tostring(row)

end

return p