FANDOM


--[[Module:Switch imported from Wikipedia]]
 
s = {};
 
function s.diffswitch(frame)
    local diffindex = tonumber(frame.args.difficulty or frame.args[1])
    local difflist = {"Very Simple", "Simple", "Moderate", "Difficult",
        "Very Difficult", "Painful"}
    local diffresult = difflist[diffindex]
    if diffresult == nil then 
        return "Undetermined" else return diffresult
    end
end
 
 
function s.structure(frame)
    local rawSI = frame.args.structure or frame.args[1]
    local structureindex = tonumber(rawSI)
    local structurelist = {
        [0] = "Short Single Tiles",
        [1] = "Primarily Single Tiles",
        [2] = "Primarily Holding Tiles",
        [3] = "Singles with some Doubles",
        [4] = "Holdings with some Doubles",
        [5] = "Primarily Double Tiles",
        [6] = "Moderate Mix of Singles and Holdings",
        [7] = "Blended Mix of Singles and Holdings",
        [8] = "Dynamic Mix of Singles and Holdings",
        }
    local structureresult = structurelist[typeindex]
    if structureresult == nil then 
        return "Unknown" 
    elseif string.gmatch(rawSI,z) then
        return structureresult.." (400+ Consecutive)"
        elseif string.gmatch(rawSI,y) then
        return structureresult.." (200+ Consecutive)"
        elseif string.gmatch(rawSI,x) then
        return structureresult.." (120+ Consecutive)"
        else return structureresult
    end
end
 
 
function s.switch( frame )
    local list = frame.args[1] or frame.args.list;
    local case = frame.args[2] or frame.args.case;
    local default = frame.args[3] or frame.args.default;
    options = frame.args[4] or frame.args.options;
    local result;
 
    list = mw.loadData( 'Module:' .. list );
 
if options == "1" then --reverse table if "options" is equal to 1 (yes)
    revlist = {}
 
        for i,v in ipairs(list) do
        revlist[v] = i
    end
    list = revlist
end
 
 
    if case ~= nil then
        if tonumber( case ) ~= nil then
            case = tonumber( case );
        end
 
        result = list[ case ];
    else
        return frame:expandTemplate{ title="FormattingError", args = {"No selection specified"} };
    end
 
    if result == nil then
        if default ~= nil then
            return default;
        else
            result = list[ '#default' ];
            if result == nil then 
                return frame:expandTemplate{ title="FormattingError", args= {"Selection not found"} };
            end
        end
    end
 
    return result;
end
 
function s.numswitch(frame)
 
local num = frame.args[1]
--If it is a number, return the padded number (003).
--If not (a purchaseable stage), return the converted number.
if tonumber(num) == nil then
    if frame.args[2] == "noroman" then 
        return nil
    else local numlist = mw.loadData('Module:Switch/Numlist')
    num = numlist[num]
    end
else while string.len(num) <3 do --Padding the number to 3-digit for nonpurchaseables
    num = "0"..num
    end
end
return num;
end
 
return s;