FANDOM


-- <nowiki>
local p = {}
local matnames = mw.loadData('Module:Disassemble/mats')
local perknames = mw.loadData('Module:Perks/data')
local perkmats = mw.loadData('Module:Perks/materials')
local yn = require('Module:Yesno')
 
function plink(mat)
	if mat then
		local matplain = string.lower(mat)
				:gsub('components?', '')
				:gsub('parts?', '')
		mat = matplain
		mw.text.trim(mat)
 
		mat = matnames[mat]
		if mat then
			local class = ''
			if mat:find('parts') then
				class = 'gizmo-interface-parts'
			end
			return string.format('[[File:%s.png|link=%s]]', mat, mat), class, matplain
		end
	end
 
	return ''
end
 
function perklink(perk)
	local working = mw.text.split(perk, '%[')
	local a = working[1]
	local b = working[2] or ''
	local c
	if b == '' then
		working = mw.text.split(a, '%(')
		a = working[1]
		c = working[2] or ''
	else
		working = mw.text.split(b, '%(')
		b = working[1] or ''
		c = working[2] or ''
	end
 
	b = b:gsub('%]','')
		:gsub('-', '–')
	c = c:gsub('%)', '')
 
 
	local name, rankmin, rankmax
	local rankstr = ''
	local comment = ''
 
	if a then
		a = mw.text.trim(a:lower())
		name = perknames[a].name
		rankstr = ' ' .. mw.text.trim(b)
		if c ~= '' then
			comment = string.format(' (%s)', mw.text.trim(c))
		end
	else
		return nil
	end
 
 
	local span = mw.html.create('span')
	span:css({
		background = '#09222F',
		['border-radius'] = '111px',
		width = '35px',
		height = '35px',
		['line-height'] = '30px',
		['text-align'] = 'center',
		display = 'inline-table',
		})
		:wikitext(string.format('[[File:%s.png|25x25px|link=%s]]', name, name))
	return string.format('\n* %s [[%s|%s]]%s%s', tostring(span), name, name:gsub('%(perk%)', ''), rankstr, comment), a
 
 
end
 
function otherperks(mats, perks, gizmos)
	local allperks = {}
	local fperks = {}
	local ret = {}
	for m,n in pairs(mats) do
		if perkmats[m] then
			for p,t in pairs(perkmats[m].perks) do
				if t[n][1] > 0 and t[n][2] > 0 then
					allperks[p] = true
				end
			end
		end
	end
 
	--detect gizmos
	local appgizmos = {
		weapon = true,
		armour = true,
		tool = true
		}
	local p2
	for p,_ in pairs(perks) do
		p2 = perknames[p]
		for i,v in pairs(appgizmos) do
			appgizmos[i] = v and p2[i]
		end
	end
 
	-- overrides
	for i,v in pairs(gizmos) do
		appgizmos[i] = v
	end
 
	-- test for issues
	if not appgizmos.weapon and not appgizmos.armour and not appgizmos.tool then
		--table.insert(ret, "\n:* '''Error: perks selected can't be in the same gizmo. Defaulting to showing all'''")
		appgizmos = {
			weapon = true,
			armour = true,
			tool = true,
			}
	end
 
 
 
	--filter allperks
	for p,_ in pairs(allperks) do
		p2 = perknames[p]
		for i,v in pairs(appgizmos) do
			if v and p2[i] then
				fperks[p] = p2.name
				break
			end
		end
	end
 
 
	-- make string
	for p,n in pairs(fperks) do
		if not perks[p] then
			table.insert(ret, string.format('\n:* [[%s|%s]]',n,n:gsub(' %(perk%)','')))
		end
	end
 
	return ret
end
 
 
 
function p.main(frame)
	local args = frame:getParent().args
 
	local ret = {}
	local matnums = {}
	local mati
	for i=1,5,1 do
		mati = 'mat' .. i
		ret[mati] = { plink(args[mati] or args[i]) }
		if ret[mati][1] ~= '' then
			matnums[ret[mati][3]] = (matnums[ret[mati][3]] or 0) + 1
		end
	end
 
	local perks = mw.text.split(args.perks, '%s*,%s*')
	local perkl = {}
	local perkplain = {}
	local pl, pplain
	for i,v in ipairs(perks) do
		pl, pplain = perklink(v)
		if pl then
			table.insert(perkl, pl)
			perkplain[pplain] = true
		end
	end
 
	ret.perks = table.concat(perkl, '')
 
	local gizmos = {
		weapon = yn(args.weapon),
		armour = yn(args.armour),
		tool = yn(args.tool),
		}
 
	if not yn(args.otherperks or 'yes') then
		ret.other = ''
	else
		ret.other = table.concat(otherperks(matnums, perkplain, gizmos), '')
	end
 
	return p._main(ret)
end
 
function p._main(args)
	local ret = mw.html.create('tr')
 
	ret:tag('td')
			:tag('table')
				:addClass('gizmo-interface')
				:tag('tr')
					:tag('td')
					:done()
					:tag('td')
						:addClass(args.mat1[2])
						:wikitext(args.mat1[1])
					:done()
					:tag('td')
					:done()
				:done()
				:tag('tr')
					:tag('td')
						:addClass(args.mat2[2])
						:wikitext(args.mat2[1])
					:done()
					:tag('td')
						:addClass(args.mat3[2])
						:wikitext(args.mat3[1])
					:done()
					:tag('td')
						:addClass(args.mat4[2])
						:wikitext(args.mat4[1])
					:done()
				:done()
				:tag('tr')
					:tag('td')
					:done()
					:tag('td')
						:addClass(args.mat5[2])
						:wikitext(args.mat5[1])
					:done()
					:tag('td')
					:done()
				:done()
			:done()
		:done()
	if args.other ~= '' then
		ret:tag('td')
			:wikitext(args.perks)
			:wikitext('\n')
			:tag('div')
				:addClass('mw-collapsible mw-collapsed')
				:attr({
						['data-expandtext'] = 'show',
						['data-collapsetext'] = 'hide',
					})
				:wikitext('\n* Other possible perks:\n')
				:tag('div')
					:addClass('mw-collapsible-content')
					:wikitext(args.other)
				:done()
			:done()
		:done()
	else
		ret:tag('td')
			:wikitext(args.perks)
		:done()
	end
 
	return ret
end
 
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.