Module:HeroDataArrays: Difference between revisions

Jump to navigation Jump to search
added more alt fire stats
optimization (WIP)
Line 22: Line 22:
     end
     end
     return value
     return value
end
-- Generate tables from given properties
local function buildTable(frame, rows, tableDef, options)
    options = options or {}
    -- option to ignore heroes who don't have any of the given properties. true by default
    local filterZero = options.filterZero or true
    local filteredRows = {}
    for _, r in ipairs(rows) do
        local hasValue = not filterZero
        if filterZero then
            for _, col in ipairs(tableDef.columns) do
                if r[col.field] ~= 0 and r[col.field] ~= nil then
                    hasValue = true
                    break
                end
            end
        end
        if hasValue then
            table.insert(filteredRows, r)
        end
    end
    if #filteredRows == 0 then
        return ""
    end
    -- Build header
    local header = ""
    for _, col in ipairs(tableDef.columns) do
        header = header .. " !! " .. col.label
    end
    -- Start table
    local t = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n" ..
        "|+ " .. tableDef.title .. " \n" ..
        "! Hero" .. header .. " \n"
    -- Rows
    for _, r in ipairs(filteredRows) do
        local cells = ""
        for _, col in ipairs(tableDef.columns) do
            cells = cells .. " || " .. (r[col.field] or 0)
        end
        t = t ..
            "|- \n" ..
            "| style=\"text-align:left;\" | " ..
            frame:expandTemplate{ title = "PageRef", args = { r.name } } ..
            cells .. " \n"
    end
    t = t .. "|}"
    return t
end
end


Line 139: Line 198:
         })
         })
     end
     end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
    local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Damage \n"..
        "! Hero !! Damage per sec !! Reload Delay (s) !! Reload Time (s) !! Ammo !! Bullets per sec !! Bullet Damage !! Bullets Per Shot \n"
       
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.DPS.." || "..r.reloadDelay.." || "..r.reloadTime.."  || "..r.clipSize..
                " || "..r.roundsPerSecond.." || "..r.bulletDamage.." || "..r.bulletsPerShot.." \n"
    end
    z = z.."|}"
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local tableDefs = {
     local tableDefs = {
    {
            title  = "Hero Base Damage",
            columns = {
                { label = "Damage per sec", field = "DPS"  },
                { label = "Reload Delay (s)", field = "reloadDelay"  },
                { label = "Reload Time (s)", field = "reloadTime"  },
                { label = "Ammo", field = "clipSize"  },
                { label = "Bullets per sec", field = "roundsPerSecond"  },
                { label = "Bullet Damage", field = "bulletDamage"  },
                { label = "Bullets Per Shot", field = "bulletsPerShot"  },
            }
        },
     {
     {
             title  = "Hero Base Alt-Fire Damage",
             title  = "Hero Base Alt-Fire Damage",
Line 170: Line 225:
     }
     }


     local output = ""
     local output = {}
 
     for _, def in ipairs(tableDefs) do
     for _, tableDef in ipairs(tableDefs) do
         local t = buildTable(frame, rows, def, def.options)
         local filteredRows = {}
        if t ~= "" then
        for _, r in ipairs(rows) do
             table.insert(output, t)
            local hasValue = false
            for _, col in ipairs(tableDef.columns) do
                if r[col.field] ~= 0 then
                    hasValue = true
                    break
                end
             end
            if hasValue then
                table.insert(filteredRows, r)
            end
        end
 
        if #filteredRows > 0 then
            local header = ""
            for _, col in ipairs(tableDef.columns) do
                header = header.." !! "..col.label
            end
 
            local t = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
                "|+ "..tableDef.title.." \n"..
                "! Hero"..header.." \n"
 
            for _, r in ipairs(filteredRows) do
                local cells = ""
                for _, col in ipairs(tableDef.columns) do
                    cells = cells.." || "..r[col.field]
                end
                t = t..
                    "|- \n"..
                    "| style=\"text-align:left;\" | "..
                        frame:expandTemplate{title="PageRef", args={r.name}}..
                        cells.." \n"
            end
 
            t = t.."|}"
            if output ~= "" then
                output = output.."\n\n"
            end
            output = output..t
         end
         end
     end
     end


     return z .. "\n\n" .. output
     return table.concat(output, "\n\n")
end
end


p.heroBulletSpeedTable = function(frame)
p.heroBulletSpeedTable = function(frame)
     local heroBulletSpeedData = heroDataArray({"Name", "Weapon>BulletSpeed", "Weapon>AltFire>BulletSpeed"})
     local heroBulletSpeedData = heroDataArray({
   
        "Name",
        "Weapon>BulletSpeed",
        "Weapon>AltFire>BulletSpeed"
    })
 
     local rows = {}
     local rows = {}
     for name, data in pairs(heroBulletSpeedData) do
     for name, data in pairs(heroBulletSpeedData) do
Line 231: Line 251:
         })
         })
     end
     end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


    local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
     table.sort(rows, function(a, b)
        "|+ Base Bullet Velocity \n"..
        return a.name:lower() < b.name:lower()
        "! Hero !! m/s \n"
    end)
 
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.bulletSpeed.." \n"
    end
    z = z.."|}"
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local tableDefs = {
     local tableDefs = {
    {
        {
             title   = "Base Alt-Fire Bullet Velocity",
            title = "Base Bullet Velocity",
            columns = {
                { label = "m/s", field = "bulletSpeed" }
            }
        },
        {
             title = "Base Alt-Fire Bullet Velocity",
             columns = {
             columns = {
                 { label = "m/s", field = "altBulletSpeed" },
                 { label = "m/s", field = "altBulletSpeed" }
             }
             }
         }  
         }
     }
     }


     local output = ""
     local output = {}
 
     for _, def in ipairs(tableDefs) do
     for _, tableDef in ipairs(tableDefs) do
         local t = buildTable(frame, rows, def, def.options)
         local filteredRows = {}
        if t ~= "" then
        for _, r in ipairs(rows) do
             table.insert(output, t)
            local hasValue = false
            for _, col in ipairs(tableDef.columns) do
                if r[col.field] ~= 0 then
                    hasValue = true
                    break
                end
             end
            if hasValue then
                table.insert(filteredRows, r)
            end
        end
 
        if #filteredRows > 0 then
            local header = ""
            for _, col in ipairs(tableDef.columns) do
                header = header.." !! "..col.label
            end
 
            local t = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
                "|+ "..tableDef.title.." \n"..
                "! Hero"..header.." \n"
 
            for _, r in ipairs(filteredRows) do
                local cells = ""
                for _, col in ipairs(tableDef.columns) do
                    cells = cells.." || "..r[col.field]
                end
                t = t..
                    "|- \n"..
                    "| style=\"text-align:left;\" | "..
                        frame:expandTemplate{title="PageRef", args={r.name}}..
                        cells.." \n"
            end
 
            t = t.."|}"
            if output ~= "" then
                output = output.."\n\n"
            end
            output = output..t
         end
         end
     end
     end


     return z .. "\n\n" .. output
     return table.concat(output, "\n\n")
end
end