Module:Attribute ID: Difference between revisions

From ARMS Institute, the ARMS Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
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",
     ["NULL"] = "None",
     ["None"] = "None",
     ["NONE"] = "None",
}
}


Line 20: Line 20:


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


return p
return p

Revision as of 17:13, 16 April 2018

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",
    ["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(arg1, key) then
output = attribute:gsub(key,value)
if output == "None" then
pageName = "Null"
else
pageName = output
end
            local formattedImage

            if args[3] == "text" then
                formattedImage = string.format('[[File:Attrib-%s.png|%s|link=%s|%s]]', output, args[2] or '20px', pageName, args['text'] or pageName)
                local 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|%s]]', output, args[2] or '36px', pageName, args['text'] or pageName)
                return formattedImage
            end
        end
    end
end
end

return p