Documentation for this module may be created at Module:Difficulty level/doc
-- 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:Difficulty level/Reality', 'Module:Difficulty level/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+)')
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 == 'Flash' then
return myDifficulty[1]
elseif version == 'HTML5' then
return myDifficulty[2]
else
return mw.getCurrentFrame():preprocess('{{Flash|' .. myDifficulty[1] .. '}}\n\n{{HTML5|' .. myDifficulty[2] .. '}}')
end
end
function p.getLevel( frame )
local a = frame.args
local levelName = mw.title.getCurrentTitle().text
local version = a[2] -- HTML5/Flash -- 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] -- HTML5/Flash -- 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
function p.difficultybgcolor(frame)
local name = frame.args[1]
local hbgcolor = 'Undetermined'
local a = frame.args
local version = a[3] -- HTML5/Flash -- can be absent or invalid
if _lookupDifficulty(name, 0) == "Very Easy" then
hbgcolor = {{ColorVE}}
elseif _lookupDifficulty(name, 0, version) == "Easy" then
hbgcolor = {{ColorE}}
elseif _lookupDifficulty(name, 0, version) == "Somewhat Easy" then
hbgcolor = {{ColorSE}}
elseif _lookupDifficulty(name, 0, version) == "Medium" then
hbgcolor = {{ColorM}}
elseif _lookupDifficulty(name, 0, version) == "Somewhat Hard" then
hbgcolor = {{ColorSH}}
elseif _lookupDifficulty(name, 0, version) == "Hard" then
hbgcolor = {{ColorH}}
elseif _lookupDifficulty(name, 0, version) == "Very Hard" then
hbgcolor = {{ColorVH}}
elseif _lookupDifficulty(name, 0, version) == "Extremely Hard" then
hbgcolor = {{ColorEH}}
elseif _lookupDifficulty(name, 0, version) == "Nearly Impossible" then
hbgcolor = {{ColorNI}}
elseif _lookupDifficulty(name, 0, version) == "Variable" then
hbgcolor = {{ColorV}}
elseif _lookupDifficulty(name, 0, version) == "Impossible" then
hbgcolor = {{ColorI}}
elseif _isSplitDifficulty(name, 0, version) then
hbgcolor = "Split"
end
return hbgcolor
end
return p
Community content is available under CC-BY-SA unless otherwise noted.