Module:CharList: Difference between revisions

1,023 bytes removed ,  24 December 2022
Undo revision 839175 by Ritsu (talk)
No edit summary
Tag: Reverted
(Undo revision 839175 by Ritsu (talk))
Tag: Undo
 
Line 1: Line 1:
require('Module:CommonFunctions')
require('Module:CommonFunctions');
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}
local get_char_list = require('Module:CharList').main


-- Main process
-- Main process
function p.main(frame)
function p.main(frame, lang)
     local args = getArgs(frame);
     local args = getArgs(frame)
    local char_outer = mw.html.create('div'):addClass('character-banner-outer')
    local char_banner = mw.html.create('div'):addClass('character-banner-wrap border-color tone-2')
    local char_list = get_char_list(frame, args.lang)
    local lang = '';
    if args.lang then lang = '/' .. args.lang end
    local char_order = char_list[1]
    local not_exist = char_list[3]
    local char_list = char_list[2]


     local char_tree = mw.html.create('div'):addClass('char-banner-tree'):attr('data-base', args[1])
     local named_list = {}
     local out = ''
     local not_exist = {}
     local char, file_name, link, nopath, nopathnojob, entry, image_arg, icon_str;
     lang = lang or args.lang
     for char_iter=1, #char_order, 1 do
     if lang then lang = '/' .. lang else lang = '' end
        local base, jobs = char_order[char_iter], {{}, {}, {}}
    local chars = frame:preprocess('{{:MediaWiki:NavSidebar' .. lang  .. '/Character}}')
        local tree = mw.html.create('div'):addClass('char-banner-tree'):attr('data-base', base:gsub('/', ''))
    -- Get rid of link wikitext.
    :gsub('%[%[', ''):gsub('%]%]', '')
    -- Replace star separators to distinct strings to make it easier.
    :gsub('%*%*%*', 'SEP1'):gsub('%*%*', 'SEP2'):gsub('%*', 'SEP3')
    local base_order = {}


        for path_iter=1, 4, 1 do
    -- Compose a table out of the string.
            local path = char_list[base][path_iter]
    chars = split(chars, 'SEP3', true)
             for job_iter=1, 3, 1 do
    table.remove(chars, 1)
                 local job = path[job_iter]
    for k,v in ipairs(chars) do
                 local out_table = jobs[job_iter]
        chars[k] = split(v, 'SEP2', true)
                 if job == nil and jobs[1][path_iter] ~= nil then
        for k2, v2 in ipairs(chars[k]) do
                     job = jobs[1][path_iter]
             chars[k][k2] = split(v2, 'SEP1', true);
                end
            if #chars[k][k2] == 1 then
                if job ~= nil then
                 local base = chars[k][k2][1]
                     table.insert(out_table, job)
                 -- Sort by base names.
                 if not string.find(base, '%#!') then
                    chars[k][1] = nil
                     named_list[base] = chars[k]
                    -- Save the order of iteration, because Lua doesn't remember it.
                     table.insert(base_order, trim(base));
                 end
                 end
             end
             end
           
         end
         end
       
    end
        for job_iter, job_name in ipairs(jobs) do
            for path_iter, path_name in ipairs(job_name) do
                local file_name = path_name:gsub(':', '');
                -- Foreign languages
                local icon_link_char_name = file_name;
                local normal_link_char_name = path_name;
                if string.find(file_name, '%|') then
                    icon_link_char_name = split(icon_link_char_name, '%|')[1]
                    normal_link_char_name = normal_link_char_name .. lang
                end
                local icon_str = 'Icon - '
                local link = '|link=' .. normal_link_char_name
                local unreleased = indexOf(normal_link_char_name, not_exist)


                if unreleased then
    local placeholder = '%#!%|'
                    icon_str = ''
                    file_name = 'Dunno'
                    link = '|link=#!'
                end


                local icon_with_link = '[[File:' .. icon_str .. icon_link_char_name .. '.png' .. link .. ']]'
    -- Shift the new table's indexes up after getting rid of the base name.
                 local img = tree:tag('div'):addClass('char-banner-tree-image'):attr('data-class-name', path_name):wikitext(icon_with_link)
    for k, v in pairs(named_list) do
        local i = 2
        while (i <= #named_list[k]) do
            -- Remove link placeholders.
            for k2, v2 in ipairs(named_list[k][i]) do
                 local name = trim(named_list[k][i][k2]:gsub('</div>', ''):gsub("<div id='nav'>", ''))
                local name_replace = name:gsub(placeholder, '');
                named_list[k][i][k2] = name_replace


                 if unreleased then
                -- Create a table of characters with placeholders, marked as not released.
                     img:attr('data-unreleased', 'true')
                 if string.match(name, placeholder) then
                     table.insert(not_exist, name_replace);
                 end
                 end
             end
             end
            -- Shifting.
            named_list[k][i-1] = named_list[k][i]
            i = i + 1
         end
         end
 
         named_list[k][#named_list[k]] = nil
         char_banner:node(tree)
         -- Remove link placeholders.
         out = not_exist
     end
     end
 
   
     local styles = frame:preprocess('{{#css:MediaWiki:Character-Banner.css}}')
     -- Output point
     local header = frame:expandTemplate{
     local char_list = {
         title = 'CharHeader',
         base_order, named_list, not_exist
        args = {
            'Elsword',
            'Elsword',
            'tone-8'
        }
     }
     }


     local select_banner = mw.html.create('p'):addClass('character-banner-select tone-8 border-color')
     if args.dump then return dump(char_list) end
    for k, v in ipairs(char_order) do
        if v == 'Lu/Ciel' then v = 'LuCiel (Lu)' end
        select_banner:wikitext('[[File: Icon - ' .. v .. '.png]]')
    end
 
    char_outer:wikitext(header):node(char_banner:node(select_banner))
      
      
     return styles .. tostring(char_outer)
     return char_list


end
end


return p
return p