Module:Attribute ID: Difference between revisions

From ARMS Institute, the ARMS Wiki
Jump to navigation Jump to search
No edit summary
m (Reverted edits by Wpvandelicer (talk) to last revision by IncredibleMeh)
Tag: Rollback
 
(13 intermediate revisions by 4 users not shown)
Line 3: Line 3:
local p = {}
local p = {}
local attributedict = {
local attributedict = {
     ["Fire"] = "Fire",
     ["FIRE"] = "Fire",
     ["Electric"] = "Electric",
     ["ELECTRIC"] = "Electric",
     ["Wind"] = "Wind",
     ["WIND"] = "Wind",
     ["Stun"] = "Stun",
     ["STUN"] = "Stun",
     ["Explosion"] = "Explosion",
     ["EXPLOSION"] = "Explosion",
     ["Ice"] = "Ice",
     ["ICE"] = "Ice",
     ["Blind"] = "Blind",
     ["BLIND"] = "Blind",
     ["Null"] = "None",
    ["POISON"] = "Poison",
     ["None"] = "None",
     ["NULL"] = "None",
     ["NONE"] = "None",
}
}


Line 20: Line 21:


function p._main(args)
function p._main(args)
     local arg1 = cap(args[1])
     if args[1] then
    for key, value in pairs(attributedict) do
        local attribute = string.upper(args[1])
        if string.match(arg1, key) then
        local pageName
            local formattedImage
        for key, value in pairs(attributedict) do
            if args[3] then
            if string.match(attribute, key) then
                formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s|%s]]', arg1, args[2] or '20px', arg1, args['text'] or arg1)
                output = attribute:gsub(key,value)
                local formattedLink = string.format('[[%s|%s]]', args['link'] or cap(args[3]), args['text'] or cap(args[3]))
                if output == "None" then
                return string.format('<span style="white-space: nowrap;">%s %s</span>', formattedImage, formattedLink)
                    pageName = "Null"
            else
                else
                formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s|%s]]', arg1, args[2] or '36px', arg1, args['text'] or arg1)
                    pageName = output
                return formattedImage
                end
                local formattedImage
                local formattedLink
                if args[2] == "text" then
                    formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s]]', output, '20px', pageName)
                    formattedLink = string.format('[[%s|%s]]', args['link'] or pageName)
                    return string.format('<span style="white-space: nowrap;">%s %s</span>', formattedImage, formattedLink)
                else
                    if args[3] == "text" then
                        formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s]]', output, args[2] or '20px', pageName)
                        formattedLink = string.format('[[%s|%s]]', args['link'] or pageName, args[text] or pageName)
                        return string.format('<span style="white-space: nowrap;">%s %s</span>', formattedImage, formattedLink)
                    else
                        formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s]]', output, args[2] or 'x36px', pageName)
                        return formattedImage
                    end
                end
             end
             end
        else
            return error("Attribute does not exist", 0)
         end
         end
     end
     end

Latest revision as of 13:22, 24 August 2023

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

local cap = require( 'Module:Capitalize' ).main
local getArgs = require( 'Module:Arguments' ).main
local p = {}
local attributedict = {
    ["FIRE"] = "Fire",
    ["ELECTRIC"] = "Electric",
    ["WIND"] = "Wind",
    ["STUN"] = "Stun",
    ["EXPLOSION"] = "Explosion",
    ["ICE"] = "Ice",
    ["BLIND"] = "Blind",
    ["POISON"] = "Poison",
    ["NULL"] = "None",
    ["NONE"] = "None",
}

function p.main()
    local args = getArgs()
        return p._main(args)
end

function p._main(args)
    if args[1] then
        local attribute = string.upper(args[1])
        local pageName
        for key, value in pairs(attributedict) do
            if string.match(attribute, key) then
                output = attribute:gsub(key,value)
                if output == "None" then
                    pageName = "Null"
                else
                    pageName = output
                end
                local formattedImage
                local formattedLink
                if args[2] == "text" then
                    formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s]]', output, '20px', pageName)
                    formattedLink = string.format('[[%s|%s]]', args['link'] or pageName)
                    return string.format('<span style="white-space: nowrap;">%s %s</span>', formattedImage, formattedLink)
                else
                    if args[3] == "text" then
                        formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s]]', output, args[2] or '20px', pageName)
                        formattedLink = string.format('[[%s|%s]]', args['link'] or pageName, args[text] or pageName)
                        return string.format('<span style="white-space: nowrap;">%s %s</span>', formattedImage, formattedLink)
                    else
                        formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s]]', output, args[2] or 'x36px', pageName)
                        return formattedImage
                    end
                end
            end
        end
    end
end

return p