Module:Sandbox/User:Alchez

From WIDEVERSE Wiki
Revision as of 14:32, 23 June 2017 by en>Alchez (Created page with "-- <pre> -- {{Quest details}} -- local p = {} local yesno = require( 'Module:Yesno' ) function p.details( frame ) local _args = frame:getParent().args local tbl ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Sandbox/User:Alchez/doc

-- <pre>
-- {{Quest details}}
--

local p = {}
local yesno = require( 'Module:Yesno' )
    
function p.details( frame )
    local _args = frame:getParent().args
    local tbl = mw.html.create( 'table' )
        :addClass( 'questdetails' )
        -- @todo replace with CSS
        :attr( 'cellspacing',  '3' )
    local title = mw.uri.fullUrl( mw.title.getCurrentTitle().fullText, { action = 'edit' } )
    local unknown = 'Unknown <small>[' .. tostring( title ) .. ' edit]</small>'
    local args = {}
    
    for k, v in pairs(_args) do
        if v ~= '' then
            args[k] = v
        end
    end
        
    local icon = args.icon and '[[File:' .. args.icon .. '|right]]' or ''
    local start = args.start or unknown
    local members = yesno( args.members ) and '[[File:P2P icon.png|30px|link=]] Members only' or
        -- check it's actually set to something false-y
        yesno( args.members ) == false and '[[File:F2P icon.png|30px|link=]] Free to play' or unknown
    local difficulties = {
        none = 'None',
        tutorial = '[[File:Novice.svg|7px|Tutorial|link=]] Tutorial',
        novice = '[[File:Novice.svg|7px|Novice|link=]] Novice',
        intermediate = '[[File:Intermediate.svg|7px|Intermediate|link=]] Intermediate',
        experienced = '[[File:Experienced.svg|7px|Experienced|link=]] Experienced',
        master = '[[File:Master.svg|7px|Master|link=]] Master',
        grandmaster = '[[File:Grandmaster.svg|7px|Grandmaster|link=]] Grandmaster',
        special = '[[File:Special.svg|7px|Special|link=]] Special'
    }
    local difficulty = difficulties[mw.ustring.lower(args.difficulty or '')] or unknown
    local length = args.length or unknown
    local reqs = args.requirements or 'None'
    local items = args.items or '* None'
    local kills = args.kills or 'None'
        
        
    tbl
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Start point' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :wikitext( '[[File:Quest map icon.png|17px|link=]] ' .. icon .. start )
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Member requirement' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :wikitext( members)
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Official difficulty' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :wikitext( difficulty )
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Length' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :wikitext( length )
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Requirements' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :newline():newline()
                :wikitext( reqs )
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Items required' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :tag( 'i' )
                    :wikitext( 'Items from the [[tool belt]] are not listed unless they do not work or are not automatically added.' )
                    :done()
                :newline():newline()
                :wikitext( items )
                :done()
            :done()
    
    if args.recommended ~= nil and yesno( args.recommended ) ~= false then
        tbl
            :tag( 'tr' )
                :tag( 'th' )
                    :addClass( 'questdetails-header' )
                    :wikitext( 'Items recommended' )
                    :done()
                :tag( 'td' )
                    :addClass( 'questdetails-info' )
                    :newline():newline()
                    :wikitext( args.recommended )
                    :done()
                :done()
    end
    
    tbl
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'questdetails-header' )
                :wikitext( 'Enemies to defeat' )
                :done()
            :tag( 'td' )
                :addClass( 'questdetails-info' )
                :newline():newline()
                :wikitext( kills )
                :done()
            :done()

    return tostring( tbl )
end

return p