Module:HeroDataArrays: Difference between revisions

LVL (talk | contribs)
Make dash speed table sort alphabetically
LVL (talk | contribs)
Reload table alphabetical sort
Line 340: Line 340:
     local heroReloadData = heroDataArray({"Name", "ReloadTime"})
     local heroReloadData = heroDataArray({"Name", "ReloadTime"})


     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    -- 1. collect rows
        "|+ Hero Base Reload Time Stats \n"..
    local rows = {}
        "! Hero !! Reload Time (s) \n"
    for name, data in pairs(heroReloadData) do
        table.insert(rows, {
            name      = name,
            reloadTime = tonumber(data.ReloadTime) or 0
        })
    end
 
    -- 2. alphabetical by hero name
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
 
    -- 3. build table
     local z = '{| class="wikitable sortable mw-collapsible" style="text-align:center"\n' ..
              '|+ Hero Base Reload Time Stats\n' ..
              '! Hero !! Reload Time (s)\n'


     for i,a in pairs(heroReloadData) do
     for _, r in ipairs(rows) do
    local reloadTime = a["ReloadTime"] or 0
         z = z ..
         z = z..
             '|-\n' ..
             "|- \n"..
             '| style="text-align:left;" | ' ..
             "| style=\"text-align:left;\" | "..
            frame:expandTemplate{title = 'PageRef', args = {r.name}} ..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
            ' || ' .. r.reloadTime .. '\n'
                " || "..reloadTime.." \n"
     end
     end
     z = z.."|}"
     return z .. '|}'
    return z
end
end