Module:CharList: Difference between revisions

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


    -- Compose a table out of the string.
        for path_iter=1, 4, 1 do
    chars = split(chars, 'SEP3', true)
            local path = char_list[base][path_iter]
    table.remove(chars, 1)
             for job_iter=1, 3, 1 do
    for k,v in ipairs(chars) do
                local job = path[job_iter]
        chars[k] = split(v, 'SEP2', true)
                 local out_table = jobs[job_iter]
        for k2, v2 in ipairs(chars[k]) do
                 if job == nil and jobs[1][path_iter] ~= nil then
             chars[k][k2] = split(v2, 'SEP1', true);
                     job = jobs[1][path_iter]
            if #chars[k][k2] == 1 then
                end
                 local base = chars[k][k2][1]
                if job ~= nil then
                -- Sort by base names.
                     table.insert(out_table, job)
                 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)


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


    -- Shift the new table's indexes up after getting rid of the base name.
                local icon_with_link = '[[File:' .. icon_str .. icon_link_char_name .. '.png' .. link .. ']]'
    for k, v in pairs(named_list) do
                 local img = tree:tag('div'):addClass('char-banner-tree-image'):attr('data-class-name', path_name):wikitext(icon_with_link)
        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


                -- Create a table of characters with placeholders, marked as not released.
                 if unreleased then
                 if string.match(name, placeholder) then
                     img:attr('data-unreleased', 'true')
                     table.insert(not_exist, name_replace);
                 end
                 end
             end
             end
        end


            -- Shifting.
         char_banner:node(tree)
            named_list[k][i-1] = named_list[k][i]
         out = not_exist
            i = i + 1
         end
         named_list[k][#named_list[k]] = nil
        -- Remove link placeholders.
     end
     end
   
 
     -- Output point
     local styles = frame:preprocess('{{#css:MediaWiki:Character-Banner.css}}')
     local char_list = {
     local header = frame:expandTemplate{
         base_order, named_list, not_exist
         title = 'CharHeader',
        args = {
            'Elsword',
            'Elsword',
            'tone-8'
        }
     }
     }


     if args.dump then return dump(char_list) end
     local select_banner = mw.html.create('p'):addClass('character-banner-select tone-8 border-color')
    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 char_list
     return styles .. tostring(char_outer)


end
end


return p
return p

Revision as of 11:52, 24 December 2022

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

require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local get_char_list = require('Module:CharList').main

-- Main process
function p.main(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 out = ''
    local char, file_name, link, nopath, nopathnojob, entry, image_arg, icon_str;
    for char_iter=1, #char_order, 1 do
        local base, jobs = char_order[char_iter], {{}, {}, {}}
        local tree = mw.html.create('div'):addClass('char-banner-tree'):attr('data-base', base:gsub('/', ''))

        for path_iter=1, 4, 1 do
            local path = char_list[base][path_iter]
            for job_iter=1, 3, 1 do
                local job = path[job_iter]
                local out_table = jobs[job_iter]
                if job == nil and jobs[1][path_iter] ~= nil then
                    job = jobs[1][path_iter]
                end
                if job ~= nil then
                    table.insert(out_table, job)
                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
                    icon_str = ''
                    file_name = 'Dunno'
                    link = '|link=#!'
                end

                local icon_with_link = '[[File:' .. icon_str .. icon_link_char_name .. '.png' .. link .. ']]'
                local img = tree:tag('div'):addClass('char-banner-tree-image'):attr('data-class-name', path_name):wikitext(icon_with_link)

                if unreleased then
                    img:attr('data-unreleased', 'true')
                end
            end
        end

        char_banner:node(tree)
        out = not_exist
    end

    local styles = frame:preprocess('{{#css:MediaWiki:Character-Banner.css}}')
    local header = frame:expandTemplate{
        title = 'CharHeader',
        args = {
            'Elsword',
            'Elsword',
            'tone-8'
        }
    }

    local select_banner = mw.html.create('p'):addClass('character-banner-select tone-8 border-color')
    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)

end

return p