Module:Sandbox/LVLGive feedback
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sandbox/LVL/doc
-- This module is a direct copy of Module:ItemData/nav, but modified to display
-- UNRELEASED (disabled) items instead of released (enabled) ones.
-- It specifically filters for items that have a Name property.
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')
--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
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, or Tech'
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
local this_cost = tonumber(item_data["Cost"])
local this_slot = item_data["Slot"]
-- ##################################################################
-- ## CRITICAL FILTERING LOGIC IS HERE: ##
-- ## 1. item_data["Name"] ~= nil : Ignores test/placeholder items. ##
-- ## 2. item_data["IsDisabled"] == true : Shows ONLY unreleased. ##
-- ##################################################################
if item_data["Name"] ~= nil and item_data["IsDisabled"] == true and this_cost ~= nil and this_slot ~= nil then
if slot == this_slot and this_cost >= min_souls and this_cost < max_souls then
-- The item_key is the internal name, e.g., "upgrade_ablative_coat"
-- The item_data["Name"] is the display name, e.g., "Ablative Coat"
-- Your ItemBox template uses the display name for the image and link, which is correct.
local display_name = item_data["Name"]
-- Your module uses item_key for translation, but ItemBox uses the Name. We will stick to Name.
local item_name_english = display_name
local lang_code = lang_module.get_lang_code()
local item_name_local = lang_module.get_string(item_key, lang_code) -- Localized name
local item_template
if template == "ItemBox" then
if lang_code == "en" then
-- For English pages, item_name is enough. ItemBox will handle the rest.
item_template = "{{ItemBox|item_name=" .. item_name_english .. "}}"
else
-- For non-English pages, provide localized name and link subpage
local link = item_name_english .. "/" .. lang_code
item_template = "{{ItemBox|item_name=" .. item_name_english .. "|item_loc=" .. item_name_local .. "|link=" .. link .. "}}"
end
else
return "Invalid template type for this module"
end
table.insert(items, item_template)
end
end
end
-- Order list alphabetically
table.sort(items)
return table.concat(items, sep)
end
-- This is a private function now, called by the public function below.
local function get_item_nav_cards(slot, min_souls, max_souls, debug_mode)
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
-- This is the public function that the template will call.
function p.generate_subgroup(frame)
local slot = frame.args[1]
if slot == nil then return "'slot' parameter is required" end
local debug_mode = frame.args['debug_mode']
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()
local group_index = 1
for i, souls in ipairs(prices) do
local min_souls = souls
if min_souls ~= 0 then
local max_souls = prices[i+1]
if max_souls == nil then
max_souls = min_souls * 10 --essentially have no upper bound
end
local list = get_item_nav_cards(slot, min_souls, max_souls, debug_mode)
-- Only add the group if there are actually items in it
if 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
if group_index == 1 then
return ""
end
return frame:expandTemplate{title=template_title, args=template_args}
end
return p