FANDOM


local p = {}
 
function p.main(frame)
    local magic_girls = mw.loadData('Module:DKWingsmt/Magical_girls')
    local element_list = {'Light', 'Dark', 'Aqua', 'Flame', 'Forest'}
 
    local elements = {}
    for i, ele in ipairs(element_list) do
        elements[ele] = { length=0 }
    end
 
    -- Put all girls into slots, and calculate the maximum number of rows
    local row_num = 0
 
    for i, v in ipairs(magic_girls) do
        local girl = mw.loadData('Module:' .. v)
        local element = girl['base']['_element']
 
        local element_length = elements[element]['length'] + 1
        elements[element]['length'] = element_length
        elements[element][element_length] = girl
 
        if row_num < element_length then
            row_num = element_length
        end
    end
 
    local output = [=[
=== Overview ===
{| class="article-table" style="width: 100%"
|-
! style="text-align:center; width: ###20%" |
[[File:AttributeIcon Light.png|center|thumb|25x25px]]Light
! style="text-align:center; width: ###20%" |[[File:AttributeIcon Shadow.png|center|thumb|25x25px|none]]Dark
! style="text-align:center; width: ###20%" |[[File:AttributeIcon Water.png|center|thumb|25x25px|none]]Aqua
! style="text-align:center; width: ###20%" |[[File:AttributeIcon Fire.png|center|thumb|25x25px|none]]Flame
! style="text-align:center; width: ###20%" |[[File:AttributeIcon Plant.png|center|thumb|25x25px|none]]Forest
]=]
 
    local row_id = 1
    while true do
        local has_content = false
        local row_content = '|-\n'
 
        for i, ele in ipairs(element_list) do
            mw.log(ele, row_id)
            local girl = elements[ele][row_id]
            if girl ~= nil then
                has_content = true
                local name = girl['base']['_name']
                row_content = row_content .. 
                    '| style="text-align:center" |[[File:' .. name .. '.png|center|thumb|100x100px|link=' .. name .. ']][[' .. name .. ']]\n'
            else
                row_content = row_content .. '|\n'
            end
        end
 
        if not has_content then
            break
        end
        output = output .. row_content
        row_id = row_id + 1
    end
 
    return output .. '|}'
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.