Module:HeroDataArrays: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Gammaton32 (talk | contribs) added more alt fire stats |
Gammaton32 (talk | contribs) 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) | 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 _, | local t = buildTable(frame, rows, def, def.options) | ||
local | if t ~= "" then | ||
table.insert(output, t) | |||
end | end | ||
end | end | ||
return | 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) | |||
table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end) | |||
local tableDefs = { | local tableDefs = { | ||
{ | |||
title | 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 _, | local t = buildTable(frame, rows, def, def.options) | ||
local | if t ~= "" then | ||
table.insert(output, t) | |||
end | end | ||
end | end | ||
return | return table.concat(output, "\n\n") | ||
end | end | ||