FANDOM


-- Used by [Template:Variant]
-- <nowiki>
local p = {}
local title = string.lower(mw.title.getCurrentTitle().text)
 
local values = {
	['main-hand'] = 'mh',
	['mainhand'] = 'mh',
	['off-hand'] = 'oh',
	['offhand'] = 'oh',
	['superior'] = 'tier',
	['inferior'] = 'tier',
	['achto'] = 'tier',
	['attuned'] = 'tier',
	['enhanced'] = 'tier',
	['refined'] = 'tier',
	['augmented'] = 'augmented',
	['barrows dyed'] = 'dyed',
	['barrows'] = 'dyed',
	['shadow dyed'] = 'dyed',
	['shadow'] = 'dyed',
	['third-age dyed'] = 'dyed',
	['third-age'] = 'dyed',
	['third age dyed'] = 'dyed',
	['third age'] = 'dyed',
	['blood dyed'] = 'dyed',
	['blood'] = 'dyed',
	['red'] = 'dyed',
	['orange'] = 'dyed',
	['yellow'] = 'dyed',
	['green'] = 'dyed',
	['blue'] = 'dyed',
	['purple'] = 'dyed',
	['black'] = 'dyed',
	['white'] = 'dyed',
}
 
-- as above but specifically tt dyes for correct auto-parsing
local tt_dyes = {
	['barrows dyed'] = true,
	['barrows'] = true,
	['shadow dyed'] = true,
	['shadow'] = true,
	['third-age dyed'] = true,
	['third-age'] = true,
	['third age dyed'] = true,
	['third age'] = true,
	['blood dyed'] = true,
	['blood'] = true,
}
 
function p.main(frame)
	local args = frame:getParent().args
	local links = {}
	local misc = {}
   	local ret = {}
 	ret.mh = {}
 	ret.oh = {}
	ret.tier = {}
	ret.augmented = {}
	ret.dyed = {}
	for key,value in pairs(args) do
		local kind, item  = '', ''
		local kind_t
 
		-- numeric key => unnamed param
		if tonumber(key) then
			-- the value is the kind and the item is "kind PAGENAME"
			kind = string.lower(value)
		else
			-- else kind is key and item is value
			kind = string.lower(key)
			item = value
		end
 
		-- apparently linebreaks aren't actually trimmed by the parser (when they really should be)????
		item = mw.text.trim(item)
		kind = mw.text.trim(kind)
 
		if values[kind] then
			links[kind] = getLink(kind, item)
		else
			table.insert(misc, getLink(kind, item))
		end
	end
 
	-- put links into order
	for i,v in pairs(values) do
		if links[i] then
			table.insert(ret[v],links[i])
		end
	end
 
	local _ret = mw.html.create()
 
	if ret.mh[1] then
		_ret:tag('div')
			:addClass('seealso')
			:wikitext('For this item\'s main-hand variant, see ')
			:wikitext(ret.mh[1] .. '.')
		:done()
	end
 
	if ret.oh[1] then
		local _slot
		if title:find('off%-?hand') then
			_slot = 'main-hand'
		else
			_slot = 'off-hand'
		end
		_ret:tag('div')
			:addClass('seealso')
			:wikitext(string.format('For this item\'s %s variant, see ',_slot))
			:wikitext(ret.oh[1] .. '.')
		:done()
	end
 
	if ret.tier[1] then
		_ret:tag('div')
			:addClass('seealso')
			:wikitext('For other variants of this item, see ')
			:wikitext(table.concat(ret.tier,', ') .. '.')
		:done()
	end
 
	if ret.augmented[1] then
		local augtext
		if title:find('augmented') then
			augtext = 'For this item\'s standard variant, see '
		else
			augtext = 'For this item\'s augmented variant, see '
		end
		_ret:tag('div')
			:addClass('seealso')
			:wikitext(augtext)
			:wikitext(table.concat(ret.augmented) .. '.')
		:done()
	end
 
	if ret.dyed[1] then
		_ret:tag('div')
			:addClass('seealso')
			:wikitext('For this item\'s (un)dyed variants, see ')
			:wikitext(table.concat(ret.dyed,', ') .. '.')
		:done()
	end
 
	if misc[1] then
		_ret:tag('div')
			:addClass('seealso')
			:wikitext('For other variants of this item, see ')
			:wikitext(table.concat(misc,', ') .. '.')
		:done()
	end
 
	return _ret
end
 
function getLink(kind, item)
	title = title2 or title
	local strippedtitle = string.gsub(string.lower(title), '-', '')
	local strippedkind = string.gsub(kind, '-', '')
 
	if item == '' then
		if string.find(strippedtitle, strippedkind) ~= nil then
			item = string.gsub(strippedtitle, strippedkind, '')
			if tt_dyes[kind] then
				item = string.gsub(title, ' %(' .. strippedkind .. '%)', '')
			end
 
			if kind == 'off-hand' then
				kind = 'main-hand'
			elseif kind == 'superior' then
				kind = 'inferior'
			elseif tt_dyes[kind] then
				kind = 'undyed'
			else
				kind = 'non-'..kind
			end
		else
			if tt_dyes[kind] then
				item = string.gsub(title, '%(.*%)$', string.format('(%s)', kind))
			else
				item = kind..' '..title
			end
		end
	else
		if string.find(strippedtitle, strippedkind) ~= nil then
		    if tt_dyes[kind] then
			    kind = 'undyed'
			else
			    kind = 'non-'..kind
			end
		end
	end
 
	if kind:find('hand') or kind:find('augment') then
		return string.format('[[%s]]',item)
	else
	    if tt_dyes[kind] then
	        if kind ~= 'blood' and kind ~= 'blood dyed' then
	            if kind:find('third') then
	                kind = 'Third Age'
	            else
	                kind = string.upper(string.sub(kind,1,1))..string.lower(string.sub(kind,2,-1))
	            end
	        end
        end
 
	    return string.format('[[%s|%s]]',item,kind)
	end
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.