Module:ItemData/nav

From The Deadlock Wiki
Revision as of 19:34, 19 March 2025 by Monster Domosed (talk | contribs) (fixed /en subpage being added to links)
Jump to navigation Jump to search

Overview

Functions for creating navigation boxes/lists for items, grouped by a slot/category and souls. Supports filtering for Street Brawl items.

Functions

get_item_nav_bulletpoints

Gets a list of items that are each sent to the Template:ItemIcon template, separated by bullet points.

Filters down to a slot/specific category, and within a range of souls. Can optionally filter for Street Brawl items.

Parameters

  • slot - Slot/category that the items should be, should be Weapon, Armor, or Tech
  • min_souls - Minimum souls that the items should have
  • max_souls - Maximum souls that the items should have (Note: the command does not include items equal to this value, so in order to include them it should be written as cost + 1)
  • debug_mode - (OPTIONAL) - if set to 'true', the wikitext is unprocessed, allowing for it to be read more clearly. Also used for showcasing the documentation examples more clearly.
  • filter - (OPTIONAL) - Filters items based on Street Brawl status. Options: exclude_street_brawl (show only regular items), street_brawl_only (show only Street Brawl items), or unset (show all)

Examples

With debug_mode on (for illustration purposes) {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000|debug_mode=true}}

{{ItemIcon|Battle Vest}} • {{ItemIcon|Bullet Lifesteal}} • {{ItemIcon|Debuff Reducer}} • {{ItemIcon|Enchanter's Emblem}} • {{ItemIcon|Enduring Speed}} • {{ItemIcon|Guardian Ward}} • {{ItemIcon|Healbane}} • {{ItemIcon|Healing Booster}} • {{ItemIcon|Reactive Barrier}} • {{ItemIcon|Restorative Locket}} • {{ItemIcon|Return Fire}} • {{ItemIcon|Spirit Lifesteal}} • {{ItemIcon|Spirit Shielding}} • {{ItemIcon|Trophy Collector}} • {{ItemIcon|Weapon Shielding}}


With debug_mode off {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000}}

Battle Vest Bullet Lifesteal Debuff Reducer Enchanter's Emblem Enduring Speed Guardian Ward Healbane Healing Booster Reactive Barrier Restorative Locket Return Fire Spirit Lifesteal Spirit Shielding Trophy Collector Weapon Shielding

To include the 3000 items {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3001}}

Battle Vest Bullet Lifesteal Debuff Reducer Enchanter's Emblem Enduring Speed Guardian Ward Healbane Healing Booster Reactive Barrier Restorative Locket Return Fire Spirit Lifesteal Spirit Shielding Trophy Collector Weapon Shielding

get_item_nav_cards

Gets a list of items that are each sent to the Template:ItemBox template, separated by space.

Filters down to a specific slot/category, and within a range of souls. Can optionally filter for Street Brawl items.

Parameters

Same as get_item_nav_bulletpoints

Examples

With debug_mode on (for illustration purposes) {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000|debug_mode=true}}

{{ItemBox|item_name=Battle Vest}} {{ItemBox|item_name=Bullet Lifesteal}} {{ItemBox|item_name=Debuff Reducer}} {{ItemBox|item_name=Enchanter's Emblem}} {{ItemBox|item_name=Enduring Speed}} {{ItemBox|item_name=Guardian Ward}} {{ItemBox|item_name=Healbane}} {{ItemBox|item_name=Healing Booster}} {{ItemBox|item_name=Reactive Barrier}} {{ItemBox|item_name=Restorative Locket}} {{ItemBox|item_name=Return Fire}} {{ItemBox|item_name=Spirit Lifesteal}} {{ItemBox|item_name=Spirit Shielding}} {{ItemBox|item_name=Trophy Collector}} {{ItemBox|item_name=Weapon Shielding}}


With debug_mode off {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000}}

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

<div class="itembox itembox-tier-Item Not Found. itembox-icon-v3 itembox-wear-v3 itembox-texture-v2 " style="font-size:10px;">

[[File:{{{1}}}.png|160px|link=]]
Imbue

{{{1}}}

Active

write_item_slot_subgroup

Writes a sub group for the navbox on Template:Item Navbox and Template:Infobox ShopItems. The sub group contains all items in each price range from "ItemPricePerTier" in Data:GenericData.json. Street Brawl items are automatically separated into their own row at the end.

Parameters

  • slot - Slot/category to create the subgroup for, ie Weapon, Armor, or Tech
  • type - The subfunction to call that determines the list formatting style. Options are 'get_item_nav_bulletpoints' or 'get_item_nav_cards'
  • debug_mode - (OPTIONAL) - if set to 'true', the wikitext is unprocessed, allowing for it to be read more clearly. Also used for showcasing the documentation examples more clearly.
  • street_brawl_label - (OPTIONAL) - Custom label text for the Street Brawl row. Defaults to "Street Brawl"

Examples

With debug_mode on (for illustration purposes) {{#invoke:ItemData/nav|write_item_slot_subgroup|Weapon|get_item_nav_bulletpoints|debug_mode=true}}


With debug_mode off {{#invoke:ItemData/nav|write_item_slot_subgroup|Weapon|get_item_nav_bulletpoints}}

Recall that it creates subgroup parameters for the mentioned templates.

generate_active_items_table

Creates table of localized released active items. Used in Template:Active Items

Example

{{#invoke:ItemData/nav|generate_active_items_table}}

Script error: The function "generate_active_items_table" does not exist.


local p = {}
local items_data = mw.loadJsonData("Data:ItemData.json")
local lang_module = require('Module:Lang')
local generic_module = require('Module:GenericData')
local util_module = require('Module:Utilities')

local function get_language_from_subpage()
    -- Get the current page title
    local page_title = mw.title.getCurrentTitle().text
    
    -- Check if the page is a subpage (e.g., "Items/ru")
    local subpage_lang = page_title:match("/(%a%a)$") -- Match two-letter language code at the end of the subpage
    
    -- If a language code is found, return it; otherwise, default to English ("en")
    return subpage_lang or "en"
end

--With debug_mode on, it outputs unprocessed wikitext
--With debug_mode off/unspecified, it processes the wikitext
local function process_debug_mode(wikitext, debug_mode)
	if debug_mode == 'true' then
		return wikitext
	elseif debug_mode == 'false' or debug_mode == nil then
		return mw.getCurrentFrame():preprocess(wikitext)
	else
		return "debug_mode must be 'true' or 'false'"
	end
end

--Writes list of items of a certain slot within the min and max soul bounds
-- Each item is wrapped and separated. For example of wrapping/separator, see
-- get_item_nav_bulletpoints. 'sep' should not be combined with 'right_wrap', 
-- as the trailing separator should also be removed from the string
local function write_wrapped_item_list(slot, min_souls, max_souls, template, sep)
    if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then
        return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)'
    end
    
    local min_souls = tonumber(min_souls)
    local max_souls = tonumber(max_souls)
    if min_souls == nil or max_souls == nil then return 'Min/Max souls must be numerical' end
    
    -- Retrieve all items that fit the bounds
    local items = {}
    for item_key, item_data in pairs(items_data) do
        -- future proofing; Disabled will be renamed to IsDisabled soon
        local this_cost = tonumber(item_data["Cost"])
        local this_slot = item_data["Slot"]
        if item_data["Name"] ~= nil and item_data["IsDisabled"] == false and this_cost ~= nil and this_slot ~= nil then
            if slot == this_slot and this_cost >= min_souls and this_cost < max_souls then
                local item_name_english = lang_module.get_string(item_key, "en") -- Get the English name
                local lang_code = get_language_from_subpage() -- Get the language code from the subpage
                local item_name_local = lang_module.get_string(item_key, lang_code) -- Get the localized name
                
                -- Construct the template based on the type
                local item_template
                if template == "ItemIcon" then
                    if lang_code == "en" then
                        -- For English pages, do not include lang or localized name
                        item_template = "{{ItemIcon|" .. item_name_english .. "}}"
                    else
                        -- For non-English pages, include lang and localized name
                        item_template = "{{ItemIcon|" .. item_name_english .. "|lang=" .. lang_code .. "|" .. item_name_local .. "}}"
                    end
                elseif template == "ItemBox" then
                    if lang_code == "en" then
                        -- For English pages, do not include item_loc or link
                        item_template = "{{ItemBox|item_name=" .. item_name_english .. "}}"
                    else
                        -- For non-English pages, include item_loc and link
                        local link = item_name_english .. "/" .. lang_code -- Add subpage for non-English languages
                        item_template = "{{ItemBox|item_name=" .. item_name_english .. "|item_loc=" .. item_name_local .. "|link=" .. link .. "}}"
                    end
                else
                    return "Invalid template type"
                end
                table.insert(items, item_template)
            end
        end
    end
    
    -- Order list alphabetically
    table.sort(items) -- O(nlogn)
    
    -- Add each item to output
    -- Each item is already wrapped in the template, so no need for additional wrapping
    local ret = table.concat(items, sep)
    
    return ret
end

-- for [[Template:Item Navbox]]
function p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode)
    -- Handle the case where it's called via #invoke (i.e., from wikitext)
    if type(slot) == "table" and slot.args then
        local frame = slot
        slot = frame.args[1]
        min_souls = frame.args[2]
        max_souls = frame.args[3]
        debug_mode = frame.args["debug_mode"]
    end
	
    local sep = ' &bull; '
	
    local item_list = write_wrapped_item_list(slot, min_souls, max_souls, "ItemIcon", sep)
	
    return process_debug_mode(item_list, debug_mode)
end

-- for [[Template:Infobox ShopItems]]
function p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode)
    -- Handle the case where it's called via #invoke (i.e., from wikitext)
    if type(slot) == "table" and slot.args then
        local frame = slot
        slot = frame.args[1]
        min_souls = frame.args[2]
        max_souls = frame.args[3]
        debug_mode = frame.args["debug_mode"]
    end
	
    local sep = ' '
	
    local item_list = write_wrapped_item_list(slot, min_souls, max_souls, "ItemBox", sep)
	
    return process_debug_mode(item_list, debug_mode)
end

function p.write_item_slot_subgroup(frame)
	local slot = frame.args[1]
	local type = frame.args[2]
	local debug_mode = frame.args['debug_mode']
	if slot == nil then return "'slot' parameter is required" end
	
	-- Define base args
	local template_title = "Navbox subgroup"
	local template_args = {
		["groupstyle"] = "background-color:" .. util_module.get_slot_color(slot) .. ";width:10%;min-width:70px;border-radius: 8px 0 0 8px",
		["grouppadding"] = "5px",
		["listpadding"] = "0 0.25rem",
	}
	
	local soul_style = "font-size: 12px; text-shadow: 1px 1px rgba(0, 0, 0, 0.3);"
	local prices = generic_module.get_item_price_per_tier()
	for i, souls in ipairs(prices) do
		--Determine lower bound for soul
		min_souls = souls
		
		--Skip 0 to i1 as no items cost less than 500
		if min_souls ~= 0 then 
			
			-- Determine upper bound
			max_souls = prices[i+1]
			if max_souls == nil then 
				max_souls = min_souls * 10 --essentially have no upper bound
			end
			
			--Create the subgroup
			template_args["group" .. (i-1)] = frame:expandTemplate{title="Souls", args={[1] = min_souls, ["Shadow"] = soul_style}}
			local list
			if type=='get_item_nav_cards' then
				list = p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode)
			elseif type=='get_item_nav_bulletpoints' then
				list = p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode)
			else
				return "'type' should be get_item_nav_cards or get_item_nav_bulletpoints"
			end
			template_args["list" .. (i-1)] =  list
		end
	end
	
	return frame:expandTemplate{title=template_title, args=template_args}
end

return p