Editing Module:Item NavboxGive feedback
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 1: | Line 1: | ||
local p = {} | local p = {} | ||
local items_data = mw.loadJsonData("Data:ItemData.json") | local items_data = mw.loadJsonData("Data:ItemData.json") | ||
local lang_module = require('Module:Lang') | local lang_module = require('Module:Lang') | ||
| Line 30: | Line 29: | ||
end | end | ||
-- Directly fetches and formats | -- Directly fetches and formats Item text for the navbox (Icons removed) | ||
local function | local function get_item_text(slot, min_souls, max_souls, filter_mode) | ||
if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then return '' end | if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then return '' end | ||
| Line 58: | Line 57: | ||
local item_template | local item_template | ||
-- Output as a standard wikilink instead of an icon template | |||
if lang_code == "en" then | if lang_code == "en" then | ||
item_template = " | item_template = "[[" .. item_name_english .. "]]" | ||
else | else | ||
item_template = " | item_template = "[[" .. item_name_english .. "|" .. item_name_local .. "]]" | ||
end | end | ||
| Line 89: | Line 89: | ||
return table.concat(items, '') | return table.concat(items, '') | ||
end | end | ||
-- Generates the Navbox using standard MediaWiki template structure | |||
function p.generate_full_navbox(frame) | |||
local debug_mode = type(frame) == "table" and frame.args and frame.args["debug_mode"] or nil | |||
local wikitext = {} | |||
-- | -- Insert standard stylesheet call | ||
table.insert(wikitext, '<templatestyles src="User:Kai/mp/itemnavbox/styles.css"/>\n') | |||
-- Start building the {{Navbox}} call | |||
table.insert(wikitext, '{{Navbox') | |||
table. | -- IMPORTANT: Change "Template:ItemNavbox" below to the actual name of your template page | ||
-- so that the v/d/e (view/discuss/edit) links in the top left work properly. | |||
table.insert(wikitext, '| name = Template:ItemNavbox') | |||
-- | -- Title including your custom search container element floated to the right | ||
table.insert(wikitext, '| title = [[Items]] <div class="item-nav-search-container" style="display:inline-block; float:right;"></div>') | |||
local categories = { | local categories = { | ||
{ header = "Weapon", | { header = "Weapon", slot = "Weapon" }, | ||
{ header = "Vitality", slot = "Armor | { header = "Vitality", slot = "Armor" }, | ||
{ header = "Spirit", | { header = "Spirit", slot = "Tech" } | ||
} | } | ||
local tiers = { | local tiers = { | ||
{ label = "{{Souls|800}}", min = 0, max = 801 }, | { label = "{{Souls|800}}", min = 0, max = 801 }, | ||
| Line 177: | Line 120: | ||
{ label = "{{Souls|3200}}", min = 1601, max = 3201 }, | { label = "{{Souls|3200}}", min = 1601, max = 3201 }, | ||
{ label = "{{Souls|6400}}", min = 3201, max = 6401 }, | { label = "{{Souls|6400}}", min = 3201, max = 6401 }, | ||
{ label = "[[Street Brawl|{{Legendary|{{#invoke:Lang|get_string|Citadel_ItemDraft_Legendary}}}}]] | { label = '<span class="itemnav-legendary">[[Street Brawl|{{Legendary|{{#invoke:Lang|get_string|Citadel_ItemDraft_Legendary}}}}]]</span>', min = 6401, max = 99999 } | ||
} | } | ||
for | -- Loop through categories and build Navbox subgroups | ||
table.insert( | for i, cat in ipairs(categories) do | ||
table.insert( | table.insert(wikitext, '| group' .. i .. ' = ' .. cat.header) | ||
table.insert(wikitext, '| list' .. i .. ' = {{Navbox|child') | |||
for | |||
for j, tier in ipairs(tiers) do | |||
local | table.insert(wikitext, ' | group' .. j .. ' = ' .. tier.label) | ||
local items_string = get_item_text(cat.slot, tier.min, tier.max, nil) | |||
table.insert( | -- Wrap the items in our flex container for layout | ||
table.insert(wikitext, ' | list' .. j .. ' = <div class="itemnav-cost-type-container">' .. items_string .. '</div>') | |||
end | end | ||
table.insert( | table.insert(wikitext, '}}') -- Close subgroup navbox | ||
end | end | ||
table.insert( | table.insert(wikitext, '}}') -- Close parent navbox | ||
-- Only ONE preprocess call for the entire structure | -- Only ONE preprocess call for the entire structure | ||
return process_debug_mode(table.concat( | return process_debug_mode(table.concat(wikitext, '\n'), debug_mode) | ||
end | end | ||
return p | return p | ||