FANDOM


--WARFRAME Wiki Sorted Void Drop Table By Rewards 
--http://warframe.wikia.com/
--Written by User:NoBrainz
 
local p = {}
 
local VoidData = mw.loadData( 'Module:Void/data' )
local script = require( "Module:Icon" )
 
-- iterator sorted by keys
local function skpairs(t)
    local keys = {}
    for k in pairs(t) do keys[#keys + 1] = k end
    table.sort(keys)
 
    local i = 0
    local iterator = function()
        i = i + 1
        local key = keys[i]
        if key then
            return key, t[key]
        else
            return nil
        end
    end
    return iterator
end
 
local function titleCase(head, tail)
    return string.upper(head) .. string.lower(tail)
end
 
local function tableCount(t)
    local count = 0
    for _ in pairs(t) do count = count + 1 end
    return count
end
 
function p.byReward(frame)
    local platform = frame and frame.args[1] or "PC"
 
    local data = {}
 
    -- collect data
    for _,v in pairs(VoidData[platform]) do
        local tower = v[1]
        local mission = v[2]
        local item = v[3]
        local part = v[4] == "" and v[3] or v[4]
        if(item ~= "No" and part ~= "Prime Drops") then
            local itemTable = data[item] or {}
            local partTable = itemTable[part] or {}
            local location = tower .. " " .. mission
 
            table.insert(partTable, location)
 
            itemTable[part] = partTable
            data[item] = itemTable
        end
    end
 
    local rewards = {}
 
    -- generate sorted table
    for item, parts in skpairs(data) do
 
        local str = '{|class="bigmodtable" style="line-height:13px;"\n'
            .. '|-\n'
            .. '|rowspan="' .. tableCount(parts) .. '" width="40%"|'
 
        local image = script._Prime(item, nil, "200x100")
        str = str .. image .. "<br/>"
 
        local caseItem = string.gsub(item, "(%a)([%w_']*)", titleCase)
        str = str .. "[[" .. caseItem
        if(item ~= "FORMA") then
            str = str.. " Prime"
        end
        str = str .. "]]\n"
 
        table.sort(parts)
        local partRows = {}
        for part, locations in skpairs(parts) do
            table.sort(locations)
            local row = "|" .. string.gsub(string.gsub(part, "(%a)([%w_']*)", titleCase), "Helmet", "Neuroptics") .. "\n"
                .. "|width=\"30%\"|" .. table.concat(locations, "<br/>")
 
            table.insert(partRows,row)
        end
        str = str .. table.concat(partRows, "\n|-\n")
        table.insert(rewards, str .. "\n|}\n")
    end
 
    return table.concat(rewards, "\n")
end
 
return p