FANDOM


-- Written by TJcool007
 
local p = {}
 
local defaultMsg = {
      [0] = 'Undetermined'--,
      --[1] = 'Undetermined',
      --[2] = 'Undetermined',
      --[3] = 'Undetermined'
} 
 
local function _getLookupTable( stars, isDreamworld )
    local lookupTable = {
        [0] = {'Module:Difficulty level CCSS/Reality', 'Module:Difficulty level CCSS/Dreamworld'}--,
        --[1] = {'Module:Difficulty 1/Reality', 'Module:Difficulty 1/Dreamworld'},
        --[2] = {'Module:Difficulty 2/Reality', 'Module:Difficulty 2/Dreamworld'},
        --[3] = {'Module:Difficulty 3/Reality', 'Module:Difficulty 3/Dreamworld'},
    }
    local world = 1
    if isDreamworld then
        world = 2
    end
 
    return lookupTable[stars][world]
end
 
local function _lookupDifficulty( levelName, stars )
	if levelName and not (levelName == '') then
 
    	-- Load data corresponding to level number and world
    	local level = levelName:match('^Level (%d+) %(CCSS%)')
    	if level then 
            local data = mw.loadData( _getLookupTable(stars or 0, levelName:match('/Dreamworld')) )
 
            -- Get difficulty for the level
            return data[tonumber(level)]
        end
    end
    return false
end
 
local function _isSplitDifficulty( levelName )
 
	local myDifficulty = _lookupDifficulty(levelName, 0)
 
	if myDifficulty and not (type( myDifficulty ) == 'string') then
		return true
	end
	return false
end
 
local function _getDifficulty( levelName, stars, version )
	if not levelName or levelName == '' then return false end
 
	-- Setup
	local level = levelName:match('^Level (%d+)')
	if not level then return false end
	local data = mw.loadData( _getLookupTable(stars or 0, levelName:match('/Dreamworld')) )
 
	-- Get difficulty for the level
	local myDifficulty = data[tonumber(level)]
	if not myDifficulty then return false end
 
	-- Parse difficulty
	if type( myDifficulty ) == 'string' then
	    if myDifficulty == '' then myDifficulty = defaultMsg[stars] end
		return myDifficulty
	elseif version == 'Web' then
		return myDifficulty[1]
	elseif version == 'Mobile' then
		return myDifficulty[2]
	else
		return mw.getCurrentFrame():preprocess('{{Web|' .. myDifficulty[1] .. '}}\n\n{{Mobile|' .. myDifficulty[2] .. '}}')
	end
end
 
 
function p.getLevel( frame )
	local a = frame.args
	local levelName = mw.title.getCurrentTitle().text
	local version = a[2] -- Mobile/Web -- can be absent or invalid
 
    if a[1] and not (a[1] == '') then levelName = a[1] end
 
    return _getDifficulty(levelName, 0, version) or a.default or defaultMsg[0]
end
 
function p.getDifficulty( frame )
	local a = frame.args
	local levelName = mw.title.getCurrentTitle().text
	local stars = 0
	local version = a[3] -- Mobile/Web -- can be absent or invalid
 
    if a[1] and not (a[1] == '') then stars = tonumber(a[1]) end
	if a[2] and not (a[2] == '') then levelName = a[2] end
    return _getDifficulty(levelName, stars, version) or a.default or defaultMsg[stars]
end
 
function p.isSplitDifficulty( frame )
	local a = frame.args
	local levelName = mw.title.getCurrentTitle().text
 
    if a[1] and not (a[1] == '') then levelName = a[1] end
 
    return _isSplitDifficulty(levelName)
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.