Module:HeroData: Difference between revisions

added write_ground_dash_buckets function
Undo revision 52296 by Monster Domosed (talk) accidentally removed get_hero_tag function
Tag: Undo
Line 782: Line 782:
}
}


-- Outputs a wikitable of heroes grouped by GroundDashDuration using {{HeroIcon|hero_name}}
-- Function to call hero tags based on name
-- {{#invoke:HeroData|write_ground_dash_buckets}}
p.get_hero_tag = function (frame)
p.write_ground_dash_buckets = function(frame)
     local name = frame.args[1]
     local buckets = {
    local number = tonumber(frame.args[2])
        [0.62] = {},
        [0.68] = {},
        [0.70] = {},
    }


     local get_dash = function(hero)
     -- Validate input
         return hero.GroundDashDuration
    if not name then
            or (hero.Weapon and hero.Weapon.GroundDashDuration)
         return "Error: Missing name input."
            or (hero.Weapon and hero.Weapon.AltFire and hero.Weapon.AltFire.GroundDashDuration)
     end
     end


     -- Collect heroes
     if number ~= 1 and number ~= 2 and number ~= 3 then
    for hero_key, hero_data in pairs(heroes_data) do
        return string.format("Error: Invalid number '%s'. Must be 1, 2, or 3.", tostring(frame.args[2]))
        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
     local tagname = TAG_NAME_MAP[name]
     for _, list in pairs(buckets) do
     if not tagname then
         table.sort(list)
         return string.format("Error: Unknown name '%s'.", name)
     end
     end


     -- Determine max rows dynamically
     -- Build localization key
     local max_rows = 0
     local key = string.format("Citadel_%s_HeroTag_%d", tagname, number)
    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"}
     -- Call Lang.get_string
    local current_frame = frame or mw.getCurrentFrame()
     local result = lang_module.get_string(key)
 
     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 result or ("[Missing string for key: " .. key .. "]")
    return table.concat(output, "\n")
end
end


return p
return p