Editing Module:Infobox item

Jump to navigation Jump to search
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 15: Line 15:
local tostring = tostring
local tostring = tostring
local type = type
local type = type
-- Status Effect Icon Map
local STATUS_EFFECT_ICON_MAP = {
    StatusEffectDisarmed = {img='Status_Disarm.png',        link='Disarm',  color='Red'},
    StatusEffectEMP      = {img='Status_Silence.png',      link='Silence',  color='Purple'},
    StatusEffectInvisible= {img='Invisible.png',            link='Invisible',color='Green'},
    StatusEffectStun    = {img='Status_Stun.png',          link='Stun',    color='NoColor'},
    StatusEffectSlow    = {img='Status_Movement_Slow.png', link='Slow',    color='Purple'},
}


-- Pre-computed constants
-- Pre-computed constants
Line 41: Line 32:
-- Item name override mapping (old name -> new name)
-- Item name override mapping (old name -> new name)
local ITEM_NAME_OVERRIDES = {
local ITEM_NAME_OVERRIDES = {
     ["debuff remover"] = "Dispel Magic",
     ["Backstabber"] = "Stalker",
    ["backstabber"] = "Stalker",
}
}


Line 75: Line 65:


local function resolve_item_name(name)
local function resolve_item_name(name)
     -- Check if there's an override for this name (case-insensitive)
     -- Check if there's an override for this name
     local lowercase_name = name:lower()
     return ITEM_NAME_OVERRIDES[name] or name
    local override = ITEM_NAME_OVERRIDES[lowercase_name]
    if override then
        return override
    end
   
    -- If no override, try to find the item in data and return its proper Name
    -- First try direct key lookup
    if data[name] and not data[name].IsDisabled then
        return data[name].Name or name
    end
   
    -- Then try case-insensitive search by Name field
    local lowercase_search = name:lower()
    for _, v in pairs(data) do
        if v.Name and v.Name:lower() == lowercase_search and not v.IsDisabled then
            return v.Name
        end
    end
   
    -- Fallback to original name
    return name
end
end


Line 236: Line 205:
     if label == "" then return val_str end
     if label == "" then return val_str end


     -- Resolve link priority: Override > JSON Stat Link > Attribute Map Link
     -- Resolve link priority: Override > Attribute Map Link > JSON Stat Link
     local link_target = link_override
     local link_target = link_override
     if not link_target or link_target == "" then
     if not link_target or link_target == "" then
         link_target = stat_links[prop_key]
         link_target = attr_link
     end
     end
     if not link_target or link_target == "" then
     if not link_target or link_target == "" then
         link_target = attr_link
         link_target = stat_links[prop_key]
     end
     end


Line 306: Line 275:
         icon_str = format("{{Icon/%s|[[File:%s|%spx|link=%s]]}}", color, img, 18, link or "")
         icon_str = format("{{Icon/%s|[[File:%s|%spx|link=%s]]}}", color, img, 18, link or "")
     end
     end
    return {
        icon = icon_str,
        link = link
    }
end
--------------------------------------------------------------------------------
-- Status Effect Icon helper
--------------------------------------------------------------------------------
local function resolve_status_effect_icon(prop_key)
    local effect_config = STATUS_EFFECT_ICON_MAP[prop_key]
    if not effect_config then return nil end
    local color = effect_config.color or "NoColor"
    local img = effect_config.img or "GenericProperty.png"
    local link = effect_config.link
    -- Construct icon using the defined color template
    local icon_str = format(
        "{{Icon/%s|[[File:%s|18px|link=%s]]}}",
        color, img, link or ""
    )


     return {
     return {
Line 455: Line 400:


     return append_conditional(val_str, allow_conditional, usage_flags)
     return append_conditional(val_str, allow_conditional, usage_flags)
end
--------------------------------------------------------------------------------
-- Status Effect formatting helper
--------------------------------------------------------------------------------
local function format_status_effect(prop_key)
    local lang_str = format("[[{{#invoke:Lang|get_string|Citadel_%s}}]]", prop_key)
        .. " [[{{#invoke:Lang|get_string|Citadel_StatusEffect}}]]"
   
    -- Get icon for this status effect
    local icon_style = resolve_status_effect_icon(prop_key)
    if icon_style and icon_style.icon then
        return icon_style.icon .. " " .. lang_str
    end
   
    return lang_str
end
end


Line 538: Line 466:
     if item.StreetBrawl == true then
     if item.StreetBrawl == true then
         insert(lines, "| street_brawl = true")
         insert(lines, "| street_brawl = true")
    end
   
    -- Pass through nocat arg to the Infobox item template if provided
    local nocat = frame.args.nocat
    if nocat and nocat ~= "" then
        insert(lines, "| nocat = " .. nocat)
     end
     end


Line 609: Line 531:
         main_formatter = function(obj)
         main_formatter = function(obj)
             if obj.Key:match("^StatusEffect") then
             if obj.Key:match("^StatusEffect") then
                 return format_status_effect(obj.Key)
                 return format(STATUS_FMT, obj.Key)
             end
             end
             return format_value_enhanced(
             return format_value_enhanced(
Line 617: Line 539:
         end
         end
         alt_formatter = function(obj)
         alt_formatter = function(obj)
            if obj.Key:match("^StatusEffect") then
                return format_status_effect(obj.Key)
            end
             return format_value_enhanced(
             return format_value_enhanced(
                 resolved_name, obj.Key, obj.Value, obj.Type,
                 resolved_name, obj.Key, obj.Value, obj.Type,
Line 629: Line 548:
         main_formatter = function(obj)
         main_formatter = function(obj)
             if obj.Key:match("^StatusEffect") then
             if obj.Key:match("^StatusEffect") then
                 return format_status_effect(obj.Key)
                 return format(STATUS_FMT, obj.Key)
             end
             end
             return format_value(
             return format_value(
Line 637: Line 556:
         end
         end
         alt_formatter = function(obj)
         alt_formatter = function(obj)
            if obj.Key:match("^StatusEffect") then
                return format_status_effect(obj.Key)
            end
             return format_value(
             return format_value(
                 obj.Key, obj.Value, obj.Type, obj.LocTokenOverride,
                 obj.Key, obj.Value, obj.Type, obj.LocTokenOverride,
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: