Module:Add Mini Cards

From The Obey Me Wiki
Jump to: navigation, search

Description: Used to add mini card links/images within tables - desktop version


local cardList = {}

function cardList.add(frame)
    -- iterate input into array
    local contact = {}
    for i = 1, 110 do
        contact[i] = frame:getParent().args[i]
    end
    
    local cardName = ""
    -- formats card name
    for i = 1, table.getn(contact) do
        cardName = contact[i]
        if string.find(cardName, "\n\n") then
            cardName = string.gsub(cardName, "\n\n", "")
        else
            cardName = string.gsub(cardName, "\n", "")
        end

        if string.find(cardName, "%(Pride%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" ..
                        string.sub(cardName, 1, string.find(cardName, "%(Pride%)") - 2) .. "]] [[File:Pride.png|10px]]"
        elseif string.find(cardName, "%(Greed%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" ..
                        string.sub(cardName, 1, string.find(cardName, "%(Greed%)") - 2) .. "]] [[File:Greed.png|10px]]"
        elseif string.find(cardName, "%(Envy%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" .. string.sub(cardName, 1, string.find(cardName, "%(Envy%)") - 2) .. "]] [[File:Envy.png|10px]]"
        elseif string.find(cardName, "%(Wrath%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" ..
                        string.sub(cardName, 1, string.find(cardName, "%(Wrath%)") - 2) .. "]] [[File:Wrath.png|10px]]"
        elseif string.find(cardName, "%(Lust%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" .. string.sub(cardName, 1, string.find(cardName, "%(Lust%)") - 2) .. "]] [[File:Lust.png|10px]]"
        elseif string.find(cardName, "%(Gluttony%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" ..
                        string.sub(cardName, 1, string.find(cardName, "%(Gluttony%)") - 2) ..
                            "]] [[File:Gluttony.png|10px]]"
        elseif string.find(cardName, "%(Sloth%)") then
            contact[i] =
                "[[" ..
                cardName ..
                    "|" ..
                        string.sub(cardName, 1, string.find(cardName, "%(Sloth%)") - 2) .. "]] [[File:Sloth.png|10px]]"
        else
            
            contact[i] = "[[" .. cardName .. "]]"
        end
    end

    -- starts the table
    local html = '<div class="flex-container">\n'
	local imageName = ''
    -- starting from first element of the array
    for card = 1, table.getn(contact), 10 do
        -- opens a new row
        html = html .. "\n"

        -- iterates between 1~10
        for count = 0, 9 do
        	imageName = string.gsub(string.gsub(frame:getParent().args[card + count], ":", " -"), "?", " -")
            html =
                html ..
                "<div class=\"mini-cardflex\"><span class=\"desktop-ver\"><small>[[File:" ..
                    string.gsub(imageName, "\n", "") ..
                        "_Mini.png|center|92px|class=cardimage|link=" .. string.gsub(frame:getParent().args[card + count], "\n", "") .. "]]</small></span>\n<span class=\"mobile-ver\"><small>[[File:" ..
                    string.gsub(imageName, "\n", "") ..
                        "_Mini.png|center|82px|class=cardimage|link=" .. string.gsub(frame:getParent().args[card + count], "\n", "") .. "]]</small></span>\n<small>" .. contact[card + count] .. "</small></div>\n"

            if card + count + 1 > table.getn(contact) then
                break
            end
        end

        -- completes one row of card
        html = html .. "\n"
    end
    return html .. "</div>"
end
return cardList

--[[File:{{{1}}}.png|center|class="cardlistimage"|link={{{1}}}]]
Cookies help us deliver our services. By using our services, you agree to our use of cookies.