Module:AchievementsDetails: Difference between revisions

From WIDEVERSE Wiki
Jump to navigation Jump to search
m (remove 'ACHIEVEMENTS JSON' smw property setting since it's unused and only causes processing errors)
 
m (1 revision imported)
 
(No difference)

Latest revision as of 21:22, 4 November 2021

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

-- <pre>
-- {{Achievements details}}
--

local p = {}
local yesno = require( 'Module:Yesno' )
local onmain = require('Module:Mainonly').on_main()
    
function p.details( frame )
    local _args = frame:getParent().args
    local tbl = mw.html.create( 'table' )
        :addClass( 'achievementsdetails plainlinks' )
        -- @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 reqs = args.requirements or '* None'
    local items = args.items or '* None'
    local kills = args.kills or '* None'
    local checklist = items
    if items ~= '* None' then
    	checklist = '<div class="lighttable checklist">\n'..items..'</div>' --frame:expandTemplate{ title = 'Checklist', args = { items } }
    end
        
    tbl
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'achievementsdetails-header' )
                :wikitext( 'Requirements' )
                :done()
            :tag( 'td' )
                :addClass( 'achievementsdetails-info' )
                :addClass( 'qc-active' )
                :tag( 'i' )
                    :wikitext( 'Skill requirements are not boostable unless marked with a [B] for boostable.' )
                    :done()
                :newline():newline()
                :wikitext( reqs )
                :done()
            :done()
    tbl
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'achievementsdetails-header' )
                :wikitext( 'Items required' )
                :done()
            :tag( 'td' )
                :addClass( 'mw-collapsible mw-collapsed' )
                :addClass( 'achievementsdetails-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( checklist )
                :done()
            :done()
    
    if args.recommended ~= nil and yesno( args.recommended ) ~= false then
        tbl
            :tag( 'tr' )
                :tag( 'th' )
                    :addClass( 'achievementsdetails-header' )
                    :wikitext( 'Recommended' )
                    :done()
                :tag( 'td' )
                    :addClass( 'mw-collapsible mw-collapsed' )
                    :addClass( 'achievementsdetails-info' )
                    :newline():newline()
                    :wikitext( '<div class="lighttable checklist">\n'..args.recommended..'</div>') -- frame:expandTemplate{ title = 'Checklist', args = { args.recommended } } )
                    :done()
                :done()
    end
    
    if args.kills ~= nil and yesno( args.kills ) ~= false then
    tbl
        :tag( 'tr' )
            :tag( 'th' )
                :addClass( 'achievementsdetails-header' )
                :wikitext( 'Enemies to defeat' )
                :done()
            :tag( 'td' )
                :addClass( 'mw-collapsible mw-collapsed' )
                :addClass( 'achievementsdetails-info' )
                :newline():newline()
                :wikitext( kills )
                :done()
            :done()
    end

    return tostring( tbl ) .. smw(frame,_args)
end

function smw(frame,args)
	if not onmain then
		return ''
	end
	-- more to come
	local err = ''
	local haserr = false
	local info = ''
	
	-- Set other smw values
	local smw = {
		['Is members only'] = yesno(args.members,false),
		['Official length'] = args.length or nil,
	}
	local smwstat = mw.smw.set(smw)
	if not smwstat == true then
		err = smwstat.error
	end
	
	return tostring(info) .. tostring(err)
end

return p