Module:HeroData: Difference between revisionsGive feedback
Gammaton32 (talk | contribs) tag names Tags: Mobile edit Mobile web edit Advanced mobile edit |
added write_ground_dash_buckets function |
||
| Line 782: | Line 782: | ||
} | } | ||
-- | -- Outputs a wikitable of heroes grouped by GroundDashDuration using {{HeroIcon|hero_name}} | ||
p. | -- {{#invoke:HeroData|write_ground_dash_buckets}} | ||
local | p.write_ground_dash_buckets = function(frame) | ||
local buckets = { | |||
[0.62] = {}, | |||
[0.68] = {}, | |||
[0.70] = {}, | |||
} | |||
local get_dash = function(hero) | |||
return hero.GroundDashDuration | |||
return | or (hero.Weapon and hero.Weapon.GroundDashDuration) | ||
or (hero.Weapon and hero.Weapon.AltFire and hero.Weapon.AltFire.GroundDashDuration) | |||
end | end | ||
if | -- 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 | end | ||
-- Sort alphabetically | |||
for _, list in pairs(buckets) do | |||
table.sort(list) | |||
end | end | ||
-- | -- Determine max rows dynamically | ||
local | 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 | 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 | ||