Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Difficulties: Difference between revisions

From Obby Wiki
No edit summary
Tag: Reverted
Undo revision 531 by Wlft (talk)
Tag: Undo
Line 1: Line 1:
return {
local p = {}
    ['meta'] = {
        page_prefix = 'Difficulty/';
    };


    ['difficulties'] = {
local config = require('Module:Difficulties/config')
        ['effortless'] = {
            display = 'Effortless';
            color = '#A5A2A3';
            priority = 0;
        };


        ['very_easy'] = {
local function ucfirst(str)
            display = 'Very Easy';
    return str:sub(1,1):upper() .. str:sub(2)
            color = '#00FF00';
end
            priority = 0.3;
        };


        ['easy'] = {
function p.main(frame)
            display = 'Easy';
    local args = frame:getParent().args
            color = '#00FF00';
    local difficulties = config.difficulties
            priority = 1;
    local output = mw.html.create('table')
        };
    output:addClass('wikitable')
    output:addClass('center')
    output:addClass('full-width')
    output:attr('style', 'width:100%;')


        ['normal'] = {
    local header_row = output:tag('tr')
            display = 'Normal';
    header_row:tag('th'):wikitext('Icon')
            color = '#FFFF00';
    header_row:tag('th'):wikitext('Difficulty')
            priority = 1.9;
    header_row:tag('th'):wikitext('Stages')
        };
    header_row:tag('th'):wikitext('Completion %')
    header_row:tag('th'):wikitext('Rewards'):addClass('center')


        ['medium'] = {
    local difficulties_s = {}
            display = 'Medium';
            color = '#FFFF00';
            priority = 2;
        };


         ['average'] = {
    for k, v in pairs(difficulties) do
             display = 'Average';
         table.insert(difficulties_s, {
            color = '#000000';
             key = k,
             priority = 3;
             data = v
         };
         })
    end


         ['hard'] = {
    table.sort(difficulties_s, function(a,b)
            display = 'Hard';
         return a.data.priority < b.data.priority
            color = '#ff0000';
    end)
            priority = 4;
        };


        ['very_hard'] = {
            display = 'Very Hard';
            color = '#ff0000';
            priority = 4.1;
        };


         ['difficult'] = {
    for _, entry in pairs(difficulties_s) do
            display = 'Difficult';
         local i = entry.key
            color = '#000000';
        local v = entry.data
            priority = 5;
        };


         ['extreme'] = {
         local difficulty_param_name = mw.text.trim(i)
            display = 'Extreme';
        local enabled_param = args[ucfirst(difficulty_param_name)] or args[difficulty_param_name]
            color = '#000000';
            priority = 6;
        };


         ['challenging'] = {
         if enabled_param and mw.text.trim(enabled_param):lower() == 'true' then
            display = 'Challenging';
             entry.data.priority = tonumber(args[difficulty_param_name .. '_priority']) or entry.data.priority
             color = '#000000';
         end
            priority = 7;
    end
         };


         ['impossible'] = {
    table.sort(difficulties_s, function(a,b)
            display = 'Impossible';
         return a.data.priority < b.data.priority
            color = '#000000';
    end)
            priority = 8;
        };


         ['remorseless'] = {
    for _, entry in pairs(difficulties_s) do
            display = 'Remorseless';
         local i = entry.key
            color = '#000000';
        local v = entry.data
            priority = 9;
        };


         ['insane'] = {
         local difficulty_param_name = mw.text.trim(i)
            display = 'Insane';
        local enabled_param = args[ucfirst(difficulty_param_name)] or args[difficulty_param_name]
            color = '#000000';
            priority = 10;
        };


         ['terrifying'] = {
         if enabled_param and mw.text.trim(enabled_param):lower() == 'true' then
            display = 'Terrifying';
             local row = output:tag('tr')
             color = '#000000';
            priority = 11;
        };


        ['arduous'] = {
            local icon_cell = row:tag('td')
             display = 'Arduous';
             local color_hex = args[difficulty_param_name .. '_hex']
             color = '#000000';
             local icon_file = args[difficulty_param_name .. '_file_name']
             priority = 12;
             -- if v.file then
        };


        ['catastrophic'] = {
            if icon_file then
            display = 'Catastrophic';
                icon_cell:wikitext('[[File:' .. icon_file .. '|48px|alt=Difficulty ' .. v.display .. ']]'):attr('style', 'border-radius: 8px; overflow: hidden; display:inline-block;')
             color = '#000000';
             else
             priority = 13;
                icon_cell:tag('div')
        };
                    :attr('style', 'width: 48px; height: 48px; background-color: ' .. ((color_hex and '#'.. color_hex) or v.color) .. '; vertical-align: middle; border-radius: 8px;')
             end


        ['unbeatable'] = {
            local name_cell = row:tag('td')
             display = 'Unbeatable';
            local page_link = config.meta.page_prefix .. v.display
             color = '#000000';
            if not v.display then
             priority = 14;
                page_link = config.meta.page_prefix .. ucfirst(i)
         };
            end
     };
 
}
            -- name_cell:tag('a')
            name_cell:wikitext('[[' .. v.display .. ']]'):attr('style', 'color:'..v.color..';') -- maybe thats how this works
                -- :wikitext('[[' .. v.display .. ']]')
                -- :attr('href', mw.title.makeTitle('',page_link):fullUrl())
                -- :wikitext(v.display or ucfirst(i))
 
            local stage_cell = row:tag('td')
            local start_value = args[difficulty_param_name .. '_start']
            local end_value = args[difficulty_param_name .. '_end']
            local is_coming_soon = args[difficulty_param_name .. '_unreleased']
 
            if is_coming_soon then
                stage_cell:wikitext('\'\'Unreleased\'\'')
            else
                stage_cell:wikitext( (start_value or '??') .. ' - ' .. (end_value or '??'))
            end
 
            local completionp_cell = row:tag('td')
             local completionp_value = args[difficulty_param_name .. '_completion']
 
            completionp_cell:wikitext( (completionp_value or '??') .. '%')
 
            local rewards_cell = row:tag('td')
             local badge_param_name = difficulty_param_name .. '_badge'
             local badge_value = args[badge_param_name]
            if badge_value then
                -- badge_cell:tag('a')
                    -- :attr('href', 'https://roblox.com/badges' .. badge_value)
                    -- :attr('target', '_blank')
                    rewards_cell:wikitext('[[File:Icons Badge Small White.png|link=https://roblox.com/badges/' .. badge_value .. '/obbywikidifficultylink|alt=Badge|28px]]')
                    rewards_cell:attr('style', 'vertical-align: middle; margin-auto;')
                        -- :attr('src', mw.file.makeUrl('Icons Badge Small White.png'))
                        -- :attr('alt', 'Badge')
                        -- :attr('style', 'width: 20px; height: 20px; vertical-align: middle;')
            else
                rewards_cell:wikitext('\'\'None\'\'')
            end
         end
    end
 
     return tostring(output)
end
 
return p

Revision as of 04:32, 10 April 2025

Documentation for this module may be created at Module:Difficulties/doc

local p = {}

local config = require('Module:Difficulties/config')

local function ucfirst(str)
    return str:sub(1,1):upper() .. str:sub(2)
end

function p.main(frame)
    local args = frame:getParent().args
    local difficulties = config.difficulties
    local output = mw.html.create('table')
    output:addClass('wikitable')
    output:addClass('center')
    output:addClass('full-width')
    output:attr('style', 'width:100%;')

    local header_row = output:tag('tr')
    header_row:tag('th'):wikitext('Icon')
    header_row:tag('th'):wikitext('Difficulty')
    header_row:tag('th'):wikitext('Stages')
    header_row:tag('th'):wikitext('Completion %')
    header_row:tag('th'):wikitext('Rewards'):addClass('center')

    local difficulties_s = {}

    for k, v in pairs(difficulties) do
        table.insert(difficulties_s, {
            key = k,
            data = v
        })
    end

    table.sort(difficulties_s, function(a,b)
        return a.data.priority < b.data.priority
    end)


    for _, entry in pairs(difficulties_s) do
        local i = entry.key
        local v = entry.data

        local difficulty_param_name = mw.text.trim(i)
        local enabled_param = args[ucfirst(difficulty_param_name)] or args[difficulty_param_name]

        if enabled_param and mw.text.trim(enabled_param):lower() == 'true' then
            entry.data.priority = tonumber(args[difficulty_param_name .. '_priority']) or entry.data.priority
        end
    end

    table.sort(difficulties_s, function(a,b)
        return a.data.priority < b.data.priority
    end)

    for _, entry in pairs(difficulties_s) do
        local i = entry.key
        local v = entry.data

        local difficulty_param_name = mw.text.trim(i)
        local enabled_param = args[ucfirst(difficulty_param_name)] or args[difficulty_param_name]

        if enabled_param and mw.text.trim(enabled_param):lower() == 'true' then
            local row = output:tag('tr')

            local icon_cell = row:tag('td')
            local color_hex = args[difficulty_param_name .. '_hex']
            local icon_file = args[difficulty_param_name .. '_file_name']
            -- if v.file then

            if icon_file then
                icon_cell:wikitext('[[File:' .. icon_file .. '|48px|alt=Difficulty ' .. v.display .. ']]'):attr('style', 'border-radius: 8px; overflow: hidden; display:inline-block;')
            else
                icon_cell:tag('div')
                    :attr('style', 'width: 48px; height: 48px; background-color: ' .. ((color_hex and '#'.. color_hex) or v.color) .. '; vertical-align: middle; border-radius: 8px;')
            end

            local name_cell = row:tag('td')
            local page_link = config.meta.page_prefix .. v.display
            if not v.display then
                page_link = config.meta.page_prefix .. ucfirst(i)
            end

            -- name_cell:tag('a')
            name_cell:wikitext('[[' .. v.display .. ']]'):attr('style', 'color:'..v.color..';') -- maybe thats how this works
                -- :wikitext('[[' .. v.display .. ']]')
                -- :attr('href', mw.title.makeTitle('',page_link):fullUrl())
                -- :wikitext(v.display or ucfirst(i))

            local stage_cell = row:tag('td')
            local start_value = args[difficulty_param_name .. '_start']
            local end_value = args[difficulty_param_name .. '_end']
            local is_coming_soon = args[difficulty_param_name .. '_unreleased']

            if is_coming_soon then
                stage_cell:wikitext('\'\'Unreleased\'\'')
            else
                stage_cell:wikitext( (start_value or '??') .. ' - ' .. (end_value or '??'))
            end

            local completionp_cell = row:tag('td')
            local completionp_value = args[difficulty_param_name .. '_completion']

            completionp_cell:wikitext( (completionp_value or '??') .. '%')

            local rewards_cell = row:tag('td')
            local badge_param_name = difficulty_param_name .. '_badge'
            local badge_value = args[badge_param_name]
            if badge_value then
                -- badge_cell:tag('a')
                    -- :attr('href', 'https://roblox.com/badges' .. badge_value)
                    -- :attr('target', '_blank')
                    rewards_cell:wikitext('[[File:Icons Badge Small White.png|link=https://roblox.com/badges/' .. badge_value .. '/obbywikidifficultylink|alt=Badge|28px]]')
                    rewards_cell:attr('style', 'vertical-align: middle; margin-auto;')
                        -- :attr('src', mw.file.makeUrl('Icons Badge Small White.png'))
                        -- :attr('alt', 'Badge')
                        -- :attr('style', 'width: 20px; height: 20px; vertical-align: middle;')
            else
                rewards_cell:wikitext('\'\'None\'\'')
            end
        end
    end

    return tostring(output)
end

return p