Module:Patch Formatter: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
auto active items
 
(2 intermediate revisions by one other user not shown)
(No difference)

Latest revision as of 19:39, 30 July 2026

Documentation for this module may be created at Module:Patch Formatter/doc

local p = {}
local items_data = mw.loadJsonData("Data:ItemData.json")
local heroes_data = mw.loadJsonData('Data:HeroData.json')
local heroes_data_release = require('Module:HeroData/release')


function p.get_all_released_item_names(frame)
    local item_names = {}
    
    -- Collect all the names of the items
    for item_key, item_data in pairs(items_data) do
        if item_data["Name"] and item_data["IsDisabled"] == false then
            table.insert(item_names, item_data["Name"])
        end
    end
    
    -- Sort alphabetically
    table.sort(item_names)
    
    -- Merge with commas
    return table.concat(item_names, ", ")
end

-- Function to get the list of all released heroes
function p.get_released_heroes_list()
    local released_heroes = {}
    
    for hero_key, hero_data in pairs(heroes_data) do
        if heroes_data_release.get_hero_release_status(hero_key) == "Released" then
            table.insert(released_heroes, hero_data['Name'])
        end
    end
    
    -- Sort hero names alphabetically
    table.sort(released_heroes)
    
    -- Combine into a comma-separated string
    return table.concat(released_heroes, ", ")
end

-- Function to get all abilities of released heroes
function p.get_all_released_abilities_list()
    local abilities = {}
    
    for hero_key, hero_data in pairs(heroes_data) do
        -- Check if the hero is released
        if heroes_data_release.get_hero_release_status(hero_key) == "Released" then
            -- Check if the hero has BoundAbilities
            if hero_data['BoundAbilities'] then
                for _, ability_data in pairs(hero_data['BoundAbilities']) do
                    if ability_data['Name'] then
                        table.insert(abilities, ability_data['Name'])
                    end
                end
            end
        end
    end
    
    -- Remove duplicate abilities
    local unique_abilities = {}
    for _, ability in ipairs(abilities) do
        unique_abilities[ability] = true
    end
    
    -- Collect unique abilities back into a table
    local result = {}
    for ability, _ in pairs(unique_abilities) do
        table.insert(result, ability)
    end
    
    -- Sort alphabetically
    table.sort(result)
    
    -- Join with commas
    return table.concat(result, ", ")
end

-- Function to get all released items with Activation not equal to Passive
function p.get_active_released_items(frame)
    local active_items = {}
    
    for item_key, item_data in pairs(items_data) do
        -- Check if item is released and not passive
        if item_data["Name"] and item_data["IsDisabled"] == false 
           and item_data["Activation"] and item_data["Activation"] ~= "Passive" then
            table.insert(active_items, item_data["Name"])
        end
    end
    
    -- Sort alphabetically
    table.sort(active_items)
    
    -- Merge with commas
    return table.concat(active_items, ", ")
end

function p.generate_active_items_table(frame)
    local active_items = {}
    
    -- 1. Collect active items
    for item_key, item_data in pairs(items_data) do
        if item_data["Name"] and 
           item_data["IsDisabled"] == false and 
           item_data["Activation"] and 
           item_data["Activation"] ~= "Passive" then
            
            table.insert(active_items, {
                name = item_data["Name"],
                key = item_key,
                slot = item_data["Slot"] or "Weapon",
                has_active_desc = item_data["ActiveDescription"] ~= nil
            })
        end
    end
    
    -- 2. Sort by name
    table.sort(active_items, function(a, b) return a.name < b.name end)
    
    -- 3. Generate wiki markup
    local wikitext = [=[
{| class="wikitable sortable" style="width:100%"
|+{{#invoke:Dictionary|translate|Active Items}}
! colspan="2" | {{#invoke:Lang|get_string|Citadel_HeroBuilds_CategoryNameLabel}}
! {{#invoke:Lang|get_string|Citadel_UserFeedback_TypeLabel}}
! {{Souls|{{#invoke:Dictionary|translate|Cost}}}}
! {{#invoke:Lang|get_string|Citadel_Mod_Tooltip_Active}}
! {{#invoke:Lang|get_string|AbilityCooldown_label}}
]=]
    
    -- 4. Add rows for each item
    for _, item in ipairs(active_items) do
        -- Determine background color and item type
        local bg_color, item_type
        if item.slot == "Armor" then
            bg_color = "#86C921"
            item_type = "Armor"
        elseif item.slot == "Tech" then
            bg_color = "#DE9CFF"
            item_type = "Tech"
        else
            bg_color = "#FCAC4D"
            item_type = "Weapon"
        end
        
        wikitext = wikitext .. "\n" .. string.format([=[
|-
! style="background-color:%s" | [[File:%s.png|64x64px]]
! [[%s{{If_lang}}|{{#invoke:Lang|get_string|%s}}]]
| style="text-align:center;font-weight:bold" | {{ItemType|%s|{{#invoke:Lang|get_string|CitadelCategory%s}}}}
| style="text-align:center;font-size:15px" | {{Souls|{{#invoke:ItemData|get_cost|%s}}}}
| {{#invoke:Utilities|process_variables|%s_active_desc|%s}}{{#invoke:Utilities|process_variables|%s_desc|%s}}{{#invoke:Utilities|process_variables|%s_active|%s}}
| style="text-align:center;font-size:16px" | {{#invoke:ItemData|get_prop|%s|AbilityCooldown}}s
]=],
            bg_color, 
            item.name, 
            item.name, item.key,
            item_type, item_type,
            item.name,
            item.key, item.name, item.key, item.name, item.key, item.name,
            item.name)
    end
    
    wikitext = wikitext .. "\n|}"
    
    return frame:preprocess(wikitext)
end

return p