Module:HeroData: Difference between revisions

tag names
Tags: Mobile edit Mobile web edit Advanced mobile edit
added write_ground_dash_buckets function
Line 782: Line 782:
}
}


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


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


     if number ~= 1 and number ~= 2 and number ~= 3 then
     -- Collect heroes
        return string.format("Error: Invalid number '%s'. Must be 1, 2, or 3.", tostring(frame.args[2]))
    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


     local tagname = TAG_NAME_MAP[name]
     -- Sort alphabetically
     if not tagname then
     for _, list in pairs(buckets) do
         return string.format("Error: Unknown name '%s'.", name)
         table.sort(list)
     end
     end


     -- Build localization key
     -- Determine max rows dynamically
     local key = string.format("Citadel_%s_HeroTag_%d", tagname, number)
     local max_rows = 0
    for _, list in pairs(buckets) do
        if #list > max_rows then max_rows = #list end
    end


     -- Call Lang.get_string
     local output = {"{| class='wikitable'", "! Bucket 1 !! Bucket 2 !! Bucket 3"}
     local result = lang_module.get_string(key)
    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


     return result or ("[Missing string for key: " .. key .. "]")
     table.insert(output, "|}")
    return table.concat(output, "\n")
end
end


return p
return p