Welcome to Wargaming.net Wiki!
Variants
Navigation

Module:ShipList

Revision as of 21:47, 7 July 2026 by Jack (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Documentation for this module may be created at Module:ShipList/doc

local p = {}
local voc = require('Module:Vocabulary')

-- Ships excluded from all rendered ship lists (nation pages, class pages,
-- tech-tree footer, and WoWs_ShipsList). Keyed by internal ship code.
local blacklist = {
	
}

function p.render(frame)
    local args = frame.args 
    local list = args.list or ""
    if list == "" then return "" end
    
    local mode = args.mode or "text"
    local filter = args.filter or ""
    local size = args.size or ""
    local g_size = tonumber(args.size) or 235
 
    local doubloons_icon = frame:preprocess('{{Doubloons}}')
    
    local ships = mw.text.split(list, ";")
    local result = {}

    for _, code in ipairs(ships) do
        code = mw.text.trim(code)
        if code ~= "" and not blacklist[code] then
            local is_prem = tonumber(frame:preprocess('{{#invoke:WoWs_GD|get|Прем|' .. code .. '}}'))
            local skip = false
            if filter == "0" and is_prem > 0 then skip = true end
            if filter == "1" and is_prem == 0 then skip = true end
            
            local ship_mark = frame:callParserFunction('#shipchars', code, 'mark')
            local name = frame:callParserFunction('#shipstr', ship_mark)
            if mw.ustring.find(name, "[%<%[]") then skip = true end -- Ignore old ships
            
            if not skip then
                
                local raw_level = frame:callParserFunction('#shipattr', 'level', code)
                
                local level = voc.tier({args = {raw_level}}) 
                local doubloons = (is_prem > 0) and (" " .. doubloons_icon) or ""

                if mode == "icons" then
                    local icon_size = (size ~= "") and size or "214"
                    table.insert(result, '<div class="tleft" style="clear:none;">[[File:Ship_' .. code .. '.png|' .. icon_size .. 'px|link=Ship:' .. name .. ']]<br/><center><span style="color:#AD7A07;"><b>' .. level .. '</b></span>&nbsp;[[Ship:' .. name .. '|' .. name .. ']]' .. doubloons .. '</center></div>')
                
                elseif mode == "gallery" then
                    local thumb_w = g_size - 5
                    local thumb_h = math.floor(thumb_w * 0.625)
                    local class = frame:callParserFunction('#shipattr', 'class', code):lower()
                    table.insert(result, '<li class="gallerybox" style="width: ' .. g_size .. 'px"><div style="width: ' .. g_size .. 'px"><div class="thumb" style="width: ' .. thumb_w .. 'px; height:' .. thumb_h .. 'px;"><div style="margin:13px auto;">[[File:' .. name .. '_wows_main.jpg|' .. thumb_w .. 'px]]</div></div><div class="gallerytext"><center><span class="b-tech-nav_icon b-tech-nav_icon__' .. class .. '"></span><span style="color:#AD7A07;"><b>' .. level .. '</b></span>&nbsp;[[Ship:' .. name .. '|' .. name .. ']]' .. doubloons .. '</center></div></div></li>')

				else -- default / text
                    local bullet = (size ~= "") and size or "•"
                    local prefix = (#result > 0) and (bullet .. "&nbsp;") or ""
                    table.insert(result, '<span>' .. prefix .. '<b>' .. level .. '</b>&nbsp;[[Ship:' .. name .. '|' .. name .. ']]' .. doubloons .. '</span> ')
                end
            end
        end
    end

    local final_output = table.concat(result)
    return (mode == "gallery") and ('<ul class="gallery">' .. final_output .. '</ul>') or final_output
end

function p.render_footer(frame)
    local args = frame.args
    local mode = args.mode or "nation"
    local val = args.value or ""
    if val == "" then return "" end

    local res = {'{| class="t-tech t-tech-ok"'}


    local raw_list = (mode == "nation") 
    	and voc.ship_class({args = {"", "list"}})
    	or voc.nation({args = {"", "list"}})
    local items = mw.text.split(raw_list, ";")
    
    for _, item in ipairs(items) do
        item = mw.text.trim(item)
        if item ~= "" then
            local query = (mode == "nation") 
                and ('nation=' .. val .. ';class=' .. item)
                or ('nation=' .. item .. ';class=' .. val)
            
            local ship_raw = frame:callParserFunction('#shiplist', 'ships', query, 'level')
            
            if ship_raw ~= "" and ship_raw ~= nil then
                local ships = p.render(frame:newChild{args = {
                    list = ship_raw,
                    mode = "text"
                }})
                
				if ships ~= "" and not ships:find("N/A") then
				    local header = (mode == "nation") 
				    	and voc.ship_class({args = {item, "bm"}})
				    	or voc.nation({args = {item, "bi"}})
                    table.insert(res, '|-\n|' .. header .. '\n|' .. ships)
                end
            end
        end
    end
    table.insert(res, '|}')
    return table.concat(res, '\n')
end

function p.renderClassPage(frame)
    local parent_args = frame:getParent().args
    local cur_class = parent_args.class or frame.args.class or ""
    
    -- Получаем список наций через Vocabulary напрямую
    local raw_nations = voc.nation({args = {"", "list"}})
    local nations_list = mw.text.split(raw_nations, ";")
    
    local output = {}
    
    for _, nat in ipairs(nations_list) do
        nat = mw.text.trim(nat)
        if nat ~= "" then
            -- Запрашиваем корабли ОДИН раз
            local ship_list = frame:callParserFunction('#shiplist', 'ships', 'nation=' .. nat .. ';class=' .. cur_class, 'level')
            
            if ship_list ~= "" then
                -- Получаем название нации из Vocabulary напрямую
                local nation_name = voc.nation({args = {nat, "bi"}})
                
                -- Рендерим иконки, вызывая p.render внутри Lua
                local icons = p.render(frame:newChild{args = {
                    list = ship_list,
                    mode = "icons",
                    size = "214"
                }})
                
                table.insert(output, '<div class="wot-frame-1"><h2>' .. nation_name .. '</h2>' .. icons .. '</div>')
            end
        end
    end
    
    return table.concat(output)
end

function p.renderNationPage(frame)
    -- Получаем параметры: либо из вызова, либо из родительского шаблона
    local parent_args = frame:getParent().args
    local cur_nation = parent_args.nation or frame.args.nation or ""
    
    if cur_nation == "" then return "" end

    -- 1. Получаем список всех классов (типов) кораблей через Vocabulary
    local raw_classes = voc.tier({args = {"", "list"}})
    local raw_list = voc.ship_class({args = {"", "list"}})
    local class_list = mw.text.split(raw_list, ";")
    
    local output = {}
    
    for _, class_code in ipairs(class_list) do
        class_code = mw.text.trim(class_code)
        if class_code ~= "" then
            -- 2. Запрашиваем корабли конкретной нации и конкретного класса
            local ship_list = frame:callParserFunction('#shiplist', 'ships', 'nation=' .. cur_nation .. ';class=' .. class_code, 'level')
            
            if ship_list ~= "" then
                -- 3. Получаем заголовок класса (иконка + название)
                local class_header = voc.ship_class({args = {class_code, "bm"}})
                
                -- 4. Рендерим иконки, используя уже готовую функцию p.render
                local icons = p.render(frame:newChild{args = {
                    list = ship_list,
                    mode = "icons",
                    size = "214"
                }})
                
                table.insert(output, '<div class="wot-frame-1"><h2>' .. class_header .. '</h2>' .. icons .. '</div>')
            end
        end
    end
    
    return table.concat(output)
end

return p