Module:Difficulty

From Helldivers Wiki
Jump to navigation Jump to search
Template-info.svg Documentation

This module implements {{Difficulty}}

Usage from Lua Modules

To use this module from other Lua modules, first load the module.

local difficulty = require('Module:Lua banner')

You can then generate a side box using the _main function.

difficulty._main(args)

The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{difficulty}} template documentation.

local getArgs = require("Module:Arguments").getArgs
local yesno = require("Module:Yesno")

local p = {}

local p = {}

local switch = function(diff, noText, noIcon)
    local diff = tostring(diff) or "default"
    case = {
        ["1"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Trivial_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Trivial]]</span>"
            end
            return out
        end,
        ["2"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Easy_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Easy]]</span>"
            end
            return out
        end,
        ["3"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Medium_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Medium]]</span>"
            end
            return out
        end,
        ["4"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Challenging_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Challenging]]</span>"
            end
            return out
        end,
        ["5"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Hard_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Hard]]</span>"
            end
            return out
        end,
        ["6"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Extreme_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Extreme]]</span>"
            end
            return out
        end,
        ["7"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Suicide_Mission_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Suicide Mission]]</span>"
            end
            return out
        end,
        ["8"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Impossible_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Impossible]]</span>"
            end
            return out
        end,
        ["9"] =
        function()
            local out = ""
            if not noIcon then
                out = out .. "[[File:Helldive_Difficulty_Icon.png|x15px]]"
            end
            if not noText then
                return out .. "<span>[[Difficulty|Helldive]]</span>"
            end
            return out
        end,
        default = function()
            return "Invalid difficulty number"
        end
    }

    if case[diff] then
        return case[diff]()
    else
        return case["default"]()
    end
end

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

function p._main(args)
    return switch(args[1], yesno(args["noText"] or false), yesno(args["noIcon"] or false))
end

return p