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
Created page with "local p = {} local config = require('Module:Difficulties/config') function p.main(frame) local args = frame:getParent().args local difficulties = config.difficulties local output = mw.html.create('table') output:addClass() for i, v in pairs(difficulties) do local difficulty_param_name = mw.text.trim(i) local enabled_param = args[difficulty_param_name:ucfirst()] or args[difficulty_param_name] if enabled_param and mw.text.tri..."
 
No edit summary
Line 2: Line 2:


local config = require('Module:Difficulties/config')
local config = require('Module:Difficulties/config')
local function ucfirst(str)
    return (str:gsub('^%1', string.upper))
end


function p.main(frame)
function p.main(frame)
Line 11: Line 15:
     for i, v in pairs(difficulties) do
     for i, v in pairs(difficulties) do
         local difficulty_param_name = mw.text.trim(i)
         local difficulty_param_name = mw.text.trim(i)
         local enabled_param = args[difficulty_param_name:ucfirst()] or args[difficulty_param_name]
         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
         if enabled_param and mw.text.trim(enabled_param):lower() == 'true' then
Line 24: Line 28:
             local page_link = config.meta.page_prefix .. v.display
             local page_link = config.meta.page_prefix .. v.display
             if not v.display then
             if not v.display then
                 page_link = config.meta.page_prefix .. i:ucfirst()
                 page_link = config.meta.page_prefix .. ucfirst(i)
             end
             end


             name_cell:tag('a')
             name_cell:tag('a')
                 :attr('href', mw.title.makeTitle('','' .. page_link).fullUrl)
                 :attr('href', mw.title.makeTitle('','' .. page_link).fullUrl)
                 :wikitext(v.display or i:ucfirst())
                 :wikitext(v.display or ucfirst(i))


             -- local badge_cell = row:tag('td')
             -- local badge_cell = row:tag('td')

Revision as of 09:08, 7 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:gsub('^%1', string.upper))
end

function p.main(frame)
    local args = frame:getParent().args
    local difficulties = config.difficulties
    local output = mw.html.create('table')
    output:addClass()

    for i, v in pairs(difficulties) do
        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')
            -- if v.file then
            icon_cell:tag('div')
                :attr('style', 'width: 20px; height: 20px; background-color: ' .. v.color .. '; vertical-align: middle;')

            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')
                :attr('href', mw.title.makeTitle('','' .. page_link).fullUrl)
                :wikitext(v.display or ucfirst(i))

            -- local badge_cell = row:tag('td')
        end
    end

    return tostring(output)
end

return p