Module:ItemData/nav: Difference between revisionsGive feedback
Filtered out items with no cost in the active items table. |
Updated to have a filter for street brawl items. |
||
| Line 21: | Line 21: | ||
-- get_item_nav_bulletpoints. 'sep' should not be combined with 'right_wrap', | -- get_item_nav_bulletpoints. 'sep' should not be combined with 'right_wrap', | ||
-- as the trailing separator should also be removed from the string | -- as the trailing separator should also be removed from the string | ||
local function write_wrapped_item_list(slot, min_souls, max_souls, template, sep) | -- filter_mode parameter: nil/"all", "exclude_street_brawl", or "street_brawl_only" | ||
local function write_wrapped_item_list(slot, min_souls, max_souls, template, sep, filter_mode) | |||
if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then | if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then | ||
return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)' | return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)' | ||
| Line 30: | Line 31: | ||
if min_souls == nil or max_souls == nil then return 'Min/Max souls must be numerical' end | if min_souls == nil or max_souls == nil then return 'Min/Max souls must be numerical' end | ||
-- Retrieve all items that fit the bounds | -- Normalize filter_mode to handle unset parameter | ||
filter_mode = filter_mode or "all" | |||
-- Retrieve all items that fit the bounds and filter criteria | |||
local items = {} | local items = {} | ||
for item_key, item_data in pairs(items_data) do | for item_key, item_data in pairs(items_data) do | ||
| Line 36: | Line 40: | ||
local this_cost = tonumber(item_data["Cost"]) | local this_cost = tonumber(item_data["Cost"]) | ||
local this_slot = item_data["Slot"] | 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 | |||
-- Filter logic for Street Brawl items | |||
local is_street_brawl = item_data["StreetBrawl"] == true | |||
local should_include = true | |||
if filter_mode == "street_brawl_only" and not is_street_brawl then | |||
should_include = false | |||
elseif filter_mode == "exclude_street_brawl" and is_street_brawl then | |||
should_include = false | |||
end | |||
if should_include and 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 | 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 item_name_english = lang_module.get_string(item_key, "en") -- Get the English name | ||
| Line 80: | Line 95: | ||
-- for [[Template:Item Navbox]] | -- for [[Template:Item Navbox]] | ||
function p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode) | -- Supports filter parameter via frame.args["filter"] | ||
function p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode, filter_mode) | |||
-- Handle the case where it's called via #invoke (i.e., from wikitext) | -- Handle the case where it's called via #invoke (i.e., from wikitext) | ||
if type(slot) == "table" and slot.args then | if type(slot) == "table" and slot.args then | ||
| Line 88: | Line 104: | ||
max_souls = frame.args[3] | max_souls = frame.args[3] | ||
debug_mode = frame.args["debug_mode"] | debug_mode = frame.args["debug_mode"] | ||
filter_mode = frame.args["filter"] | |||
end | end | ||
local sep = ' • ' | local sep = ' • ' | ||
local item_list = write_wrapped_item_list(slot, min_souls, max_souls, "ItemIcon", sep) | local item_list = write_wrapped_item_list(slot, min_souls, max_souls, "ItemIcon", sep, filter_mode) | ||
return process_debug_mode(item_list, debug_mode) | return process_debug_mode(item_list, debug_mode) | ||
| Line 98: | Line 115: | ||
-- for [[Template:Infobox ShopItems]] | -- for [[Template:Infobox ShopItems]] | ||
function p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode) | -- Supports filter parameter via frame.args["filter"] | ||
function p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode, filter_mode) | |||
-- Handle the case where it's called via #invoke (i.e., from wikitext) | -- Handle the case where it's called via #invoke (i.e., from wikitext) | ||
if type(slot) == "table" and slot.args then | if type(slot) == "table" and slot.args then | ||
| Line 106: | Line 124: | ||
max_souls = frame.args[3] | max_souls = frame.args[3] | ||
debug_mode = frame.args["debug_mode"] | debug_mode = frame.args["debug_mode"] | ||
filter_mode = frame.args["filter"] | |||
end | end | ||
local sep = ' ' | local sep = ' ' | ||
local item_list = write_wrapped_item_list(slot, min_souls, max_souls, "ItemBox", sep) | local item_list = write_wrapped_item_list(slot, min_souls, max_souls, "ItemBox", sep, filter_mode) | ||
return process_debug_mode(item_list, debug_mode) | return process_debug_mode(item_list, debug_mode) | ||
end | end | ||
-- for [[Template:Item Navbox]] subgroup rows | |||
-- Writes price tiers and appends Street Brawl section if items exist | |||
function p.write_item_slot_subgroup(frame) | function p.write_item_slot_subgroup(frame) | ||
local slot = frame.args[1] | local slot = frame.args[1] | ||
local type = frame.args[2] | local type = frame.args[2] | ||
local debug_mode = frame.args['debug_mode'] | local debug_mode = frame.args['debug_mode'] | ||
local street_brawl_label = frame.args['street_brawl_label'] or "Street Brawl" | |||
if slot == nil then return "'slot' parameter is required" end | if slot == nil then return "'slot' parameter is required" end | ||
| Line 131: | Line 154: | ||
local soul_style = "font-size: 12px; text-shadow: 1px 1px rgba(0, 0, 0, 0.3);" | 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() | local prices = generic_module.get_item_price_per_tier() | ||
local group_index = 1 | |||
for i, souls in ipairs(prices) do | for i, souls in ipairs(prices) do | ||
min_souls = souls | min_souls = souls | ||
--Skip 0 to i1 as no items cost less than 500 | --Skip 0 to i1 as no items cost less than 500 | ||
if min_souls ~= 0 then | if min_souls ~= 0 then | ||
-- Determine upper bound for soul tier | |||
-- Determine upper bound | |||
max_souls = prices[i+1] | max_souls = prices[i+1] | ||
if max_souls == nil then | if max_souls == nil then | ||
max_souls = min_souls * 10 | max_souls = min_souls * 10 | ||
end | end | ||
-- | -- Generate list for this price tier, excluding Street Brawl items | ||
local list | local list | ||
if type=='get_item_nav_cards' then | if type=='get_item_nav_cards' then | ||
list = p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode) | list = p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode, "exclude_street_brawl") | ||
elseif type=='get_item_nav_bulletpoints' then | elseif type=='get_item_nav_bulletpoints' then | ||
list = p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode) | list = p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode, "exclude_street_brawl") | ||
else | else | ||
return "'type' should be get_item_nav_cards or get_item_nav_bulletpoints" | return "'type' should be get_item_nav_cards or get_item_nav_bulletpoints" | ||
end | end | ||
template_args["list" .. | |||
-- Only add the group if there are items in this tier | |||
if list and list ~= "" then | |||
template_args["group" .. group_index] = frame:expandTemplate{title="Souls", args={[1] = min_souls, ["Shadow"] = soul_style}} | |||
template_args["list" .. group_index] = list | |||
group_index = group_index + 1 | |||
end | |||
end | end | ||
end | |||
-- Add Street Brawl section at the bottom of the slot | |||
local sb_min = 0 | |||
local sb_max = 999999 | |||
local sb_list | |||
if type=='get_item_nav_cards' then | |||
sb_list = p.get_item_nav_cards(slot, sb_min, sb_max, debug_mode, "street_brawl_only") | |||
elseif type=='get_item_nav_bulletpoints' then | |||
sb_list = p.get_item_nav_bulletpoints(slot, sb_min, sb_max, debug_mode, "street_brawl_only") | |||
end | |||
-- Only add Street Brawl group if there are items for this slot | |||
if sb_list and sb_list ~= "" then | |||
-- Style the link to match other tier headers with white text inside the link to prevent visited link color | |||
local sb_link_text = "[[Street Brawl{{if_lang}}|<span style=\"color:#FFFFFF; font-family:'Retail Demo', sans-serif; text-wrap: nowrap; text-shadow: 0px 0px 2px #2c312e, 1.3px 1.3px rgba(0, 0, 0, 0.2);\"><b>" .. street_brawl_label .. "</b></span>]]" | |||
template_args["group" .. group_index] = frame:preprocess(sb_link_text) | |||
template_args["list" .. group_index] = sb_list | |||
end | end | ||