Module:Item Navbox: Difference between revisions

Jump to navigation Jump to search
Undo revision 92006 by Kai (talk)
Tag: Undo
No edit summary
Line 89: Line 89:
end
end


-- Generates the full HTML item navbox recursively and efficiently
-- Generates the Navbox using standard MediaWiki template structure
function p.generate_full_navbox(frame)
function p.generate_full_navbox(frame)
     local debug_mode = type(frame) == "table" and frame.args and frame.args["debug_mode"] or nil
     local debug_mode = type(frame) == "table" and frame.args and frame.args["debug_mode"] or nil


     local html = {}
     local wikitext = {}
table.insert(html, '<div class="itemnav-header"> [[Items]] <div class="item-nav-search-container"></div></div>\n')
   
     table.insert(html, '<div class="itemnav-container"><templatestyles src="User:Kai/mp/itemnavbox/styles.css"/>\n')
    -- Insert standard stylesheet call
 
    table.insert(wikitext, '<templatestyles src="User:Kai/mp/itemnavbox/styles.css"/>\n')
     -- Maps Headers to Slots and distinct CSS Classes
   
    -- Start building the {{Navbox}} call
    table.insert(wikitext, '{{Navbox')
   
    -- 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",   slot = "Weapon", css = "itemnav-weapon" },
         { header = "Weapon", slot = "Weapon" },
         { header = "Vitality", slot = "Armor",  css = "itemnav-vitality" },
         { header = "Vitality", slot = "Armor" },
         { header = "Spirit",   slot = "Tech",  css = "itemnav-tech" }
         { header = "Spirit", slot = "Tech" }
     }
     }


    -- Maps tier boundaries and formatting
     local tiers = {
     local tiers = {
         { label = "{{Souls|800}}", min = 0, max = 801 },
         { label = "{{Souls|800}}", min = 0, max = 801 },
Line 110: Line 119:
         { 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}}}}]]", min = 6401, max = 99999, extra_css = "itemnav-legendary " }
         { label = '<span class="itemnav-legendary">[[Street Brawl|{{Legendary|{{#invoke:Lang|get_string|Citadel_ItemDraft_Legendary}}}}]]</span>', min = 6401, max = 99999 }
     }
     }


     for _, cat in ipairs(categories) do
    -- Loop through categories and build Navbox subgroups
         table.insert(html, '\n<div class="itemnav-type-header">\'\'\'' .. cat.header .. '\'\'\'</div>\n')
     for i, cat in ipairs(categories) do
         table.insert(html, '<div class="itemnav-type-container">\n')
         table.insert(wikitext, '| group' .. i .. ' = ' .. cat.header)
 
         table.insert(wikitext, '| list' .. i .. '  = {{Navbox|child')
         for _, tier in ipairs(tiers) do
       
             local css_class = "itemnav-soul " .. (tier.extra_css or "") .. cat.css
         for j, tier in ipairs(tiers) do
             local items_wikitext = get_item_icons(cat.slot, tier.min, tier.max, nil)
             table.insert(wikitext, '  | group' .. j .. ' = ' .. tier.label)
 
           
             table.insert(html, '\n<div class="imsodonenamingclasses">\n')
             local items_string = get_item_icons(cat.slot, tier.min, tier.max, nil)
             table.insert(html, '<div class="' .. css_class .. '">' .. tier.label .. '</div><!--\n')
             -- Wrap the items in our flex container for layout
            table.insert(html, '--><div class="itemnav-cost-type-container">' .. items_wikitext .. '</div>\n')
             table.insert(wikitext, ' | list' .. j .. ' = <div class="itemnav-cost-type-container">' .. items_string .. '</div>')
            table.insert(html, '</div>\n')
         end
         end
 
       
         table.insert(html, '\n</div>\n')
         table.insert(wikitext, '}}') -- Close subgroup navbox
     end
     end


     table.insert(html, '\n</div>')
     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(html), debug_mode)
     return process_debug_mode(table.concat(wikitext, '\n'), debug_mode)
end
end


return p
return p