-- Written by TJcool007 -- Support for stars added by catinthedark local p = {} local defaultMsg = { [0] = 'Undetermined: start a discussion relating to difficulty in the comments section below!', [1] = 'Undetermined', [2] = 'Undetermined', [3] = 'Undetermined' } local function _getLookupTable( stars, isDreamworld ) local lookupTable = { [0] = {'Module:Сложность/Обычный', 'Module:Сложность/Мир грёз'}, [1] = {'Module:Сложность 1/Reality', 'Module:Сложность 1/Мир грёз'}, [2] = {'Module:Сложность 2/Reality', 'Module:Сложность 2/Мир грёз'}, [3] = {'Module:Сложность 3/Reality', 'Module:Сложность 3/Мир грёз'}, } 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+)') 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