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 attrrow1 = mw.html.create -- Create base attributes row local attrrow2 = mw.html.create -- Create main 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) >= 12 and string.len(itemname) < 18 then --Nowrap for long ( but not too long ) Item names name :tag('td'):wikitext(mw.getCurrentFrame:expandTemplate{ title = 'Anchor', args={ itemname } }):css('white-space', 'nowrap') :done else name :tag('td'):wikitext(mw.getCurrentFrame:expandTemplate{ title = 'Anchor', args={ 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

attrrow1 :tag('tr'):css( 'background-color', '#D6E1EF' ) --Base attributes row :tag('td'):css('white-space', 'nowrap'):css('line-height', '1.2em'):attr('colspan', '2') -- Base attributes cell :tag('table') --Attributes table :node(attrrow2) --Attributes if rarity then -- Rarity attrrow2 :tag('tr') :tag('td'):wikitext(' Rarity: ', rarity ,' ') :done :done end

if sell and sell ~= 'no' then -- Sellability attrrow2 :tag('tr') :tag('td'):wikitext(' Sell Price: ', sell ,' ') :done :done elseif sell and sell == 'no' then attrrow2 :tag('td'):wikitext(' Cannot be sold. ') :done :done end

if drop == 'no' then -- Dropability attrrow2 :tag('tr') :tag('td'):wikitext(' Cannot be dropped. ') :done :done end

if lost == 'no' then -- Losability attrrow2 :tag('tr') :tag('td'):wikitext(' Cannot be lost. ') :done :done end 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, '{{collapse') then --If collapse template Is In locations locrow :tag('tr'):css( 'background-color', '#D6E1EF' ) :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', lspan):css('width','100%') :done elseif locations then locrow :tag('tr'):css( 'background-color', '#D6E1EF' ) :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', lspan) :done end

row:tag('tr'):css( 'background-color', '#D6E1EF' ) :node(img) --Item sprite cell :node(name) --Item name cell :node(paramcell) --Free space cells :node(attrrow1) --Base attributes row :done :node(locrow) --Locations row :done

return tostring(row)

end

return p

-- Copy and paste for the console <:) print(p.main)