Module:HeroDataArrays: Difference between revisions

Jump to navigation Jump to search
No edit summary
added rounded decimals
Line 1: Line 1:
local p = {};
local p = {};
local util_module = require('Module:Utilities')
local util_module = require('Module:Utilities')
Line 7: Line 6:
-- Just get heroes that are playable
-- Just get heroes that are playable
for i, heroData in pairs(allHeroData) do
for i, heroData in pairs(allHeroData) do
if heroData["IsDisabled"] == false then
    if heroData["IsDisabled"] == false then
table.insert(inGameHeroData, heroData)
        table.insert(inGameHeroData, heroData)
end
    end
end
 
-- Helper function to round numeric values
local function roundValue(value)
    if type(value) == "number" then
        return util_module.round_to_sig_fig(value, 3)
    end
    return value
end
end


Line 17: Line 24:
-- subsequent keys.
-- subsequent keys.
local heroDataArray = function(args)
local heroDataArray = function(args)
local outData = {}
    local outData = {}
   
for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero
    for i, heroData in ipairs(inGameHeroData) do           -- Iterate over each hero
local out = {} -- First creating a table to hold data
        local out = {}                                     -- First creating a table to hold data
for j, key in pairs(args) do -- Iterate over each key:
        for j, key in pairs(args) do                       -- Iterate over each key:
if string.find(key, ">") ~= nil then -- If the key is actually a path of keys,
            if string.find(key, ">") ~= nil then           -- If the key is actually a path of keys,
local node = heroData           -- start with the biggest node heroData, and
                local node = heroData                       -- start with the biggest node heroData, and
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, splitting on ">",
                for k in string.gmatch(key, "([^>]+)") do   -- iterate over each key, splitting on ">",
if node[k] ~= nil then -- trying the key as a string e.g. "1",
                    if node[k] ~= nil then                 -- trying the key as a string e.g. "1",
node = node[k]
                        node = node[k]                    
else -- else using the key as numeric,
                    else                                   -- else using the key as numeric,
node = node[tonumber(k)]
                        node = node[tonumber(k)]
end -- drilling down the JSON node after node
                    end                                     -- drilling down the JSON node after node
end
                end
out[key] = node -- until outputting the final node
                out[key] = roundValue(node)                -- until outputting the final node (rounded)
else
            else
out[key] = heroData[key] -- or just grab the data if not a path
                out[key] = roundValue(heroData[key])        -- or just grab the data if not a path (rounded)
end
            end
end
        end
outData[heroData["Name"]] = out -- Save data in the big table of heroes
        outData[heroData["Name"]] = out                     -- Save data in the big table of heroes
end
    end
return(outData)
    return(outData)
end
end


p.heroHealthTable = function(frame)
p.heroHealthTable = function(frame)
-- Pull data
    -- Pull data
heroHealthData = heroDataArray({"Name", "MaxHealth", "LevelScaling>MaxHealth"})
    heroHealthData = heroDataArray({"Name", "MaxHealth", "LevelScaling>MaxHealth"})


-- Input table will be called a, output wikitable will be called z
    -- Input table will be called a, output wikitable will be called z
-- From a to z, haha get it
    -- From a to z, haha get it
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Hero Base Health Stats \n"..
        "|+ Hero Base Health Stats \n"..
"! Hero !! Starting !! Added per PI !! At Max PI \n"
        "! Hero !! Starting !! Added per PI !! At Max PI \n"


-- Iterate over heroes adding a new row to the wikitable for each
    -- Iterate over heroes adding a new row to the wikitable for each
for i,a in pairs(heroHealthData) do
    for i,a in pairs(heroHealthData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["MaxHealth"].." || +"..a["LevelScaling>MaxHealth"].." || "..
                " || "..a["MaxHealth"].." || +"..a["LevelScaling>MaxHealth"].." || "..
tostring(tonumber(a["MaxHealth"])+tonumber(a["LevelScaling>MaxHealth"])*14).." \n"
                tostring(roundValue(tonumber(a["MaxHealth"])+tonumber(a["LevelScaling>MaxHealth"])*14)).." \n"
end
    end
   
-- Cap it off
    -- Cap it off
z = z.."|}"
    z = z.."|}"
   
return z
    return z
end
end


p.heroRegenTable = function(frame)
p.heroRegenTable = function(frame)
heroRegenData = heroDataArray({"Name", "BaseHealthRegen"})
    heroRegenData = heroDataArray({"Name", "BaseHealthRegen"})
   
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Hero Base Health Regen \n"..
        "|+ Hero Base Health Regen \n"..
"! Hero !! HP/s \n"
        "! Hero !! HP/s \n"


for i,a in pairs(heroRegenData) do
    for i,a in pairs(heroRegenData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["BaseHealthRegen"].." \n"
                " || "..a["BaseHealthRegen"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


p.heroDpsTable = function(frame)
p.heroDpsTable = function(frame)
heroDpsData = heroDataArray({"Name","ReloadSingle","ReloadDelay","ReloadTime",
    heroDpsData = heroDataArray({"Name","ReloadSingle","ReloadDelay","ReloadTime",
"ClipSize","RoundsPerSecond","BulletDamage","BulletsPerShot"})
        "ClipSize","RoundsPerSecond","BulletDamage","BulletsPerShot"})
    
    
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Hero Base Damage \n"..
        "|+ Hero Base Damage \n"..
"! Hero !! Reload Delay (s) !! Reload Time (s) !! Ammo !! Bullets per sec !! Bullet Damage !! Bullets Per Shot \n"
        "! Hero !! Reload Delay (s) !! Reload Time (s) !! Ammo !! Bullets per sec !! Bullet Damage !! Bullets Per Shot \n"
       
for i,a in pairs(heroDpsData) do
    for i,a in pairs(heroDpsData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["ReloadDelay"].." || "..a["ReloadTime"].."  || "..a["ClipSize"]..
                " || "..a["ReloadDelay"].." || "..a["ReloadTime"].."  || "..a["ClipSize"]..
" || "..a["RoundsPerSecond"].." || "..a["BulletDamage"].." || "..a["BulletsPerShot"].." \n"
                " || "..a["RoundsPerSecond"].." || "..a["BulletDamage"].." || "..a["BulletsPerShot"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


p.heroBulletSpeedTable = function(frame)
p.heroBulletSpeedTable = function(frame)
heroBulletSpeedData = heroDataArray({"Name", "BulletSpeed"})
    heroBulletSpeedData = heroDataArray({"Name", "BulletSpeed"})
   
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Base Bullet Velocity \n"..
        "|+ Base Bullet Velocity \n"..
"! Hero !! m/s \n"
        "! Hero !! m/s \n"


for i,a in pairs(heroBulletSpeedData) do
    for i,a in pairs(heroBulletSpeedData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["BulletSpeed"].." \n"
                " || "..a["BulletSpeed"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


p.heroClipSizeTable = function(frame)
p.heroClipSizeTable = function(frame)
heroClipSizeData = heroDataArray({"Name", "ClipSize"})
    heroClipSizeData = heroDataArray({"Name", "ClipSize"})
   
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Base Ammo Count \n"..
        "|+ Base Ammo Count \n"..
"! Hero !! Ammo \n"
        "! Hero !! Ammo \n"


for i,a in pairs(heroClipSizeData) do
    for i,a in pairs(heroClipSizeData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["ClipSize"].." \n"
                " || "..a["ClipSize"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


p.heroMoveSpeedTable = function(frame)
p.heroMoveSpeedTable = function(frame)
heroMoveSpeedData = heroDataArray({"Name", "MoveSpeed"})
    heroMoveSpeedData = heroDataArray({"Name", "MoveSpeed"})
   
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Base Movement Speed \n"..
        "|+ Base Movement Speed \n"..
"! Hero !! m/s \n"
        "! Hero !! m/s \n"


for i,a in pairs(heroMoveSpeedData) do
    for i,a in pairs(heroMoveSpeedData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["MoveSpeed"].." \n"
                " || "..a["MoveSpeed"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


p.heroRoundsPerSecondTable = function(frame)
p.heroRoundsPerSecondTable = function(frame)
heroRoundsPerSecondData = heroDataArray({"Name", "MoveSpeed"})
    heroRoundsPerSecondData = heroDataArray({"Name", "RoundsPerSecond"})
   
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Base Fire Rate \n"..
        "|+ Base Fire Rate \n"..
"! Hero !! Rounds/s \n"
        "! Hero !! Rounds/s \n"


for i,a in pairs(heroRoundsPerSecondData) do
    for i,a in pairs(heroRoundsPerSecondData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["RoundsPerSecond"].." \n"
                " || "..a["RoundsPerSecond"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


p.heroFalloffRangeTable = function(frame)
p.heroFalloffRangeTable = function(frame)
heroFalloffRangeData = heroDataArray({"Name", "FalloffStartRange", "FalloffEndRange"})
    heroFalloffRangeData = heroDataArray({"Name", "FalloffStartRange", "FalloffEndRange"})
   
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Base Falloff Range \n"..
        "|+ Base Falloff Range \n"..
"! Hero !! Minimum Range (m) !! Maximum Range (m)  \n"
        "! Hero !! Minimum Range (m) !! Maximum Range (m)  \n"


for i,a in pairs(heroFalloffRangeData) do
    for i,a in pairs(heroFalloffRangeData) do
z = z..
        z = z..
"|- \n"..
            "|- \n"..
"| style=\"text-align:left;\" | "..
            "| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["FalloffStartRange"].." || "..a["FalloffEndRange"].." \n"
                " || "..a["FalloffStartRange"].." || "..a["FalloffEndRange"].." \n"
end
    end
z = z.."|}"
    z = z.."|}"
return z
    return z
end
end


return p
return p