Module:Item infobox

From The Cycle: Frontier Wiki

This module creates the infobox for an item page. Takes any item as input Usage:

{{#invoke:Item infobox|main|Sample Container}}

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( "[[File:" .. p.data["inGameName"] .. ".png|200px]]" )
         :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 ( "[[File:" .. p.data["rarity"] .. "Rarity.svg|18px|link=Rarity]] [[Rarity|" .. p.data["rarity"] .."]]")
         :done()
         :done()
         :tag( "tr" )
         :tag( "th" )
         :wikitext ( "Spawn Locations" )
         :done()
         :tag( "td" )
         :addClass ( "plainlinks" )
         :wikitext ( mw.text.nowiki( "[" ) .. "[https://tools.thecyclefrontier.wiki/map?map=1&item="..encodedName.." BS]" ..mw.text.nowiki( "] [" ) .."[https://tools.thecyclefrontier.wiki/map?map=2&item="..encodedName.." CF]".. mw.text.nowiki( "] [" ) .. "[https://tools.thecyclefrontier.wiki/map?map=3&item="..encodedName.." TI]" .. mw.text.nowiki( "]" ))
         :done()
         :done()
         :tag( "tr" )
         :tag( "th" )
         :wikitext ( "Weight" )
         :done()
         :tag( "td" )
         :wikitext ( p.data["weight"] .. " [[File:UI-WeightIcon.png|25x25px]]" )
         :done()
         :done()
         :tag( "tr" )
         :tag( "th" )
         :wikitext ( "K-Marks" )
         :done()
         :tag( "td" )
         :wikitext ( p.data["sellValue"] .. " [[File:KMarks.png|25x25px]]" )        
         :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"]) .. " [[File:KMarks.png|25x25px]]" )   
         :done()
         :done()
         :tag( "tr" )
         :tag( "th" )
         :wikitext ( "Faction Reputation" )
         :done()
         :tag( "td" )
         :wikitext ( p.data["factionRep"] .. " [[File:Reputation.png|25x25px]]" )        
         :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"]) .. " [[File:Reputation.png|25x25px]]" ) 
         :allDone()  
     return tostring( infobox )
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.