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 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] 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 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 attrrow1 = mw.html.create -- Create base attributes row local attrrow2 = mw.html.create -- Create main attributes row local name = mw.html.create --Create node for the item name local paramcell = mw.html.create -- Create node for optional parameters local locrow = mw.html.create --Create node for locations row

locspan = 2 --Colspan of the Locations row. Default Is 2 and Increases for each param[#] cell paramspan = 1 --Default rowspan of each param[#] cell; for when one of the attribute parameters Is used

if rarity or sell or drop or lost then --Basically "If there's an attribute" paramspan = 2 attrrow1 :tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) --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 end

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

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

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

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

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

if locations and string.find(locations, 'collaps') then --If there's collapsible content In locations locrow :tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', locspan):css('width','100%') :done elseif locations then locrow :tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) :tag('td'):wikitext('Locations\n\n', locations):attr('colspan', locspan) :done end

if string.len(itemname) >= 12 then name :tag('td'):wikitext(itemname):css('white-space', 'nowrap') :done else name :tag('td'):wikitext(itemname) :done end

row:tag('tr'):css( 'background-color', '#'..mw.getCurrentFrame:expandTemplate { title = 'TableColor/cell'} ) --IS and Item row :tag('td'):wikitext(mw.getCurrentFrame:expandTemplate { title = 'IS', args={ item } }):css('text-align', 'center') --IS cell :done --finish td     :node(name) --Item name cell :node(paramcell) :node(attrrow1) --base attributes row :done :node(locrow) :done

return tostring(row)

end

return p

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