Module:Item infobox

local p = {} --p stands for package

p.loadedData = mw.loadJsonData( "Module:Item infobox/itemData.json" )

local args = mw.getCurrentFrame.args

for k, v in pairs(p.loadedData) do   if args[1] == v["inGameName"] then p.data = p.loadedData[k] break end end

function p.main( frame ) local infobox = mw.html.create( "div" )

-- generate a string for the tags an item has, since it can has multiple we iterate and build a string. Could not figure out how to use table.concat. Might have been a metatable? local tagOutput = '' for _, value in ipairs(p.data["tags"]) do        tagOutput = tagOutput .. string.gsub(value, "Loot.Category.", "") .. ", "    end tagOutput = tagOutput:sub(1, -3) encodedName = mw.uri.encode(p.data["inGameName"]) infobox :addClass( "infobox" ) :addClass( "floatright" ) :tag( "div" ) :addClass( "infobox-title" ) :wikitext( p.data["inGameName"] ) :done :tag( "div" ) :addClass( "infobox-image" ) :wikitext( "" ) :done :tag( "table" ) :tag( "tr" ) :tag( "th" ) :wikitext ( "Type" ) :done :tag( "td" ) :wikitext ( tagOutput ) :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "Rarity" ) :done :tag( "td" ) :wikitext ( " " .. p.data["rarity"] .."") :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "Spawn Locations" ) :done :tag( "td" ) :addClass ( "plainlinks" ) :wikitext ( mw.text.nowiki( "[" ) .. "BS" ..mw.text.nowiki( "] [" ) .."CF".. mw.text.nowiki( "] [" ) .. "TI" .. mw.text.nowiki( "]" )) :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "Weight" ) :done :tag( "td" ) :wikitext ( p.data["weight"] .. " " ) :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "K-Marks" ) :done :tag( "td" ) :wikitext ( p.data["sellValue"] .. " " ) :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "K-Marks / Weight" ) :done :tag( "td" ) -- Round a number (thanks https://stackoverflow.com/a/18313481 ) :wikitext ( math.floor( (p.data["sellValue"]+0.5) / p.data["weight"]) .. " " ) :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "Faction Reputation" ) :done :tag( "td" ) :wikitext ( p.data["factionRep"] .. " " ) :done :done :tag( "tr" ) :tag( "th" ) :wikitext ( "Faction Rep / Weight" ) :done :tag( "td" ) -- Round a number (thanks https://stackoverflow.com/a/18313481 ) :wikitext ( math.floor( (p.data["factionRep"]+0.5) / p.data["weight"]) .. " " ) :allDone return tostring( infobox ) end

return p