Module:HeroData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Undo revision 52296 by Monster Domosed (talk) accidentally removed get_hero_tag function Tag: Undo |
added write_ground_dash_buckets function |
||
| Line 808: | Line 808: | ||
return result or ("[Missing string for key: " .. key .. "]") | return result or ("[Missing string for key: " .. key .. "]") | ||
end | |||
-- Outputs a wikitable of heroes grouped by GroundDashDuration using {{HeroIcon|hero_name}} | |||
-- {{#invoke:HeroData|write_ground_dash_buckets}} | |||
p.write_ground_dash_buckets = function(frame) | |||
local buckets = { | |||
[0.62] = {}, | |||
[0.68] = {}, | |||
[0.70] = {}, | |||
} | |||
local get_dash = function(hero) | |||
return hero.GroundDashDuration | |||
or (hero.Weapon and hero.Weapon.GroundDashDuration) | |||
or (hero.Weapon and hero.Weapon.AltFire and hero.Weapon.AltFire.GroundDashDuration) | |||
end | |||
-- Collect heroes | |||
for hero_key, hero_data in pairs(heroes_data) do | |||
if not hero_data.InDevelopment and not hero_data.IsDisabled then | |||
local dash = get_dash(hero_data) | |||
if dash and buckets[dash] then | |||
table.insert(buckets[dash], hero_data.Name or hero_key) | |||
end | |||
end | |||
end | |||
-- Sort alphabetically | |||
for _, list in pairs(buckets) do | |||
table.sort(list) | |||
end | |||
-- Determine max rows dynamically | |||
local max_rows = 0 | |||
for _, list in pairs(buckets) do | |||
if #list > max_rows then max_rows = #list end | |||
end | |||
local output = {"{| class='wikitable'", "! Bucket 1 !! Bucket 2 !! Bucket 3"} | |||
local current_frame = frame or mw.getCurrentFrame() | |||
for i = 1, max_rows do | |||
local row = {} | |||
for _, bucket in ipairs({0.62, 0.68, 0.70}) do | |||
local hero_name = buckets[bucket][i] | |||
table.insert(row, hero_name and current_frame:expandTemplate{title = "HeroIcon", args = {hero_name}} or "") | |||
end | |||
table.insert(output, "|-\n| " .. table.concat(row, " || ")) | |||
end | |||
table.insert(output, "|}") | |||
return table.concat(output, "\n") | |||
end | end | ||
return p | return p | ||