FANDOM


-- <nowiki>
-- [[Template:Statbox]]
--
 
local p = {}
 
local addcommas = require('Module:Addcommas')._add
 
local hiscoreSkills = {
    'overall',
    'attack',
    'defence',
    'strength',
    'constitution',
    'ranged',
    'prayer',
    'magic',
    'cooking',
    'woodcutting',
    'fletching',
    'fishing',
    'firemaking',
    'crafting',
    'smithing',
    'mining',
    'herblore',
    'agility',
    'thieving',
    'slayer',
    'farming',
    'runecrafting',
    'hunter',
    'construction',
    'summoning',
    'dungeoneering',
    'divination',
    'invention',
    'bounty hunter',
    'bounty hunter rogue',
    'dominion tower',
    'crucible',
    'castle wars',
    'ba attackers',
    'ba defenders',
    'ba collectors',
    'ba healers',
    'duel tournament',
    'mobilising armies',
    'conquest',
    'fist of guthix',
    'gg resource race',
    'gg athletics',
    'we2 armadyl lifetime contribution',
    'we2 bandos lifetime contribution',
    'we2 armadyl pvp kills',
    'we2 bandos pvp kills',
    'heist guard level',
    'heist robber level',
    'cfp 5 game average'
}
 
local types = {
    'rank',
    'level',
    'xp'
}
 
local hiscoreOrder = {
    'attack',
    'constitution',
    'mining',
    'strength',
    'agility',
    'smithing',
    'defence',
    'herblore',
    'fishing',
    'ranged',
    'thieving',
    'cooking',
    'prayer',
    'crafting',
    'firemaking',
    'magic',
    'fletching',
    'woodcutting',
    'runecrafting',
    'slayer',
    'farming',
    'construction',
    'hunter',
    'summoning',
    'dungeoneering',
    'divination',
    'invention'
}
 
function p._parseHiscoreData(csv)
    local data = {}
    local hiscoreLines = mw.text.split(csv, '%s+')
    local line, val
 
    for i = 1, #hiscoreLines do
        line = mw.text.split(hiscoreLines[i], ',')
        if i > #hiscoreSkills then break end
        data[hiscoreSkills[i]] = {}
 
        for j = 1, #types do
            val = line[j] == '-1' and '-' or
                line[j] ~= nil and addcommas(line[j]) or nil
 
            data[hiscoreSkills[i]][types[j]] = val
        end
    end
 
    return data
end
 
function p.main(frame)
    local args = frame:getParent().args
    local data = p._parseHiscoreData(args[1])
    local rowCount = 0
    local statstable = mw.html.create('table')
        :addClass('statbox')
    local statsrow
    local skill, skillData, text, spanText
 
    for i = 1, #hiscoreOrder do
        if rowCount % 3 == 0 then
            if not statsrow then
                statsrow =  statstable:tag('tr')
            else
                statsrow = statsrow:done():tag('tr')
            end
        end
 
        rowCount = rowCount + 1
 
        skill = hiscoreOrder[i]
        skillData = data[skill]
 
        text = '[[File:' .. skill .. '-icon.png|link=]]&nbsp;' .. skillData.level
 
        spanText = 'Rank: <span>' .. skillData.rank .. '</span><br />XP: <span>' ..
            skillData.xp .. '</span>'
 
        statsrow:tag('td')
            :wikitext(text)
            :tag('span')
                :addClass('xpbox')
                :wikitext(spanText)
                :done()
            :done()
    end
 
    -- close final tr tag
    statstable = statsrow:done()
 
    -- add overall row
    statstable:tag('tr')
        :tag('td')
            :attr('colspan', '3')
            :wikitext(data.overall.level)
            :tag('span')
                :addClass('xpbox')
                :wikitext(
                    'Rank: <span>' .. data.overall.rank .. '</span><br />XP: <span>' ..
                    data.overall.xp .. '</span>'
                )
                :done()
            :done()
        :done()
 
    return tostring(statstable)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.