WARFRAME Wiki

Read about the future of the Fandom platform and the WARFRAME wiki! Any feedback would be appreciated! User blog:Cephalon Scientia/2022 Fandom Community Connect. - 06:11, 6 June 2022 (UTC)

READ MORE

WARFRAME Wiki
Advertisement
WARFRAME Wiki

Submodule for generating weapon navigation box at bottom of weapon articles. See Template:WeaponNav for the template that invokes this module.

Documentation

Package items

Other items

buildWeaponNav(frame) (function)
Builds a weapon navigation box.
Parameter: frame Frame object (table)
Returns: Resultant wikitext of navbox (string)

Created with Docbunto

See Also

Code


---	Submodule for generating weapon navigation box at bottom of weapon articles.
--	See [[Template:WeaponNav]] for the template that invokes this module.
--	
--	@module			weapons/nav
--	@alias			p
--	@attribution	[[User:Gigamicro|Gigamicro]]
--	@attribution	[[User:FINNER|FINNER]]
--	@attribution	[[User:Cephalon Scientia|Cephalon Scientia]]
--	@require	[[Module:Table]]
--	@require	[[Module:Tooltips]]
--	@require	[[Module:Weapons/data]]
--	@release	stable
--	<nowiki>

local Table = require([[Module:Table]])
local Tooltips = require [[Module:Tooltips]] 
local WeaponData = require([[Module:Weapons/data]])

---	Builds a wikitable row.
--	@function		row
--	@param			{string} cat Weapon category/class name
--	@param			{table} weaps
--	@return			{string} Resultant wikitext of wikitable row
local row = function(cat, weaps)
	local str = {}
	for name, weap in Table.skpairs(weaps) do
		table.insert(str, Tooltips.full{{
			'Weapons',
			name,
			weap.Link,
			name = weap.Name,
			icon = ('[[File:%s|128px|link=%s|class=icon]]'):format(weap.Image, weap.Link or ''),
			overridden = true,
		}})
	end
	local self = mw.html.create('tr')
	if cat =='--' then
		self:tag('td')
			:attr('colspan', '2')
			:css('font-size', 'small')
			:css('font-weight', 'normal')
			:css('text-align', 'center')
			:wikitext(table.concat(str, '  • '))
	else
		self:tag('td')
				:addClass('navboxgroup')
				:wikitext(cat)
			:done()
			:tag('td')
				:css('font-size', 'small')
				:css('font-weight', 'normal')
				:css('text-align', 'left')
				:wikitext(table.concat(str, '  • '))
	end
	return self:allDone()
end

---	Builds wikitable of weapons in a particular weapon slot (e.g. primary weapons).
--	@function		makeTable
--	@param			{table} data Weapon data
--	@return			{string} Resultant wikitext of wikitable
local function makeTable(data)
	local subTable = mw.html.create('table')
		:addClass('Wikitable')
		:css('width', '100%')
		:css('font-size', 'small')
		
	local datum = {}
	for _, weaponEntry in pairs(data) do
		local header = weaponEntry['Class'] or 'Unknown Class'
		local section = weaponEntry['Trigger'] or header
		if header == section then
			header = 'Melee'
			section = '[[:Category:'..section..'|'..section..']]'
		end

		if datum[header] == nil then
			datum[header] = {}
		end
		if datum[header][section] == nil then
			datum[header][section] = {}
		end

		datum[header][section][weaponEntry.Name] = weaponEntry
	end

	for header, sections in Table.skpairs(datum) do
		subTable:tag('tr')
			:tag('th')
				:addClass('navboxhead')
				:attr('colspan', '2')
				:wikitext('[[:Category:'..header..'|'..header..']]')
			:done()
		:done()
		for section, weaps in Table.skpairs(sections) do
			subTable:node(row(section, weaps))
		end
	end
	
	return subTable
end

---	Filters table.
--	@function		filterData
--	@param			{string} t Table data
--	@return			{table} New table that only contains weapon entries with _IgnoreEntry == false
local function filterData(t)
	local nt = {}
	for k, v in pairs(t) do
		if not v._IgnoreEntry then
			nt[k] = v
		end
	end
	return nt
end

return {
---	Builds a weapon navigation box.
--	@function		buildWeaponNav
--	@param			{table} frame Frame object
--	@return			{string} Resultant wikitext of navbox
buildWeaponNav = function(frame)
	return tostring(mw.html.create('table')
		:addClass('navbox mw-collapsible mobile-hidden')
		:tag('tr')
			:tag('th')
				:css('text-align', 'center')
				:wikitext('[[Weapons]] • [[Damage]] • [[Weapon Comparison'
					..(mw.title.getCurrentTitle().nsText=='Conclave' and '/Conclave' or '')
					..'|Compare All]] • [[Weapon Cosmetics|Cosmetics]]')
			:done()
		:done()
		:tag('tr')
			:tag('th')
				:css('padding', '0')
				:tag('div')
					:addClass('tabber-borderless')
					:wikitext(frame:extensionTag('Tabber', tostring(mw.html.create()
						:wikitext('|-|Primary= '):node(makeTable(WeaponData.Primary))
						:wikitext('|-|Secondary= '):node(makeTable(WeaponData.Secondary))
						:wikitext('|-|Melee= '):node(makeTable(WeaponData.Melee))
						:wikitext('|-|Archwing= '):node(makeTable(WeaponData.Archwing))
						:wikitext('|-|Robotic= '):node(makeTable(filterData(WeaponData.Robotic)))
						:wikitext('|-|Modular= '):node(makeTable(filterData(WeaponData.Modular)))
						:wikitext('|-|Railjack= '):node(makeTable(filterData(WeaponData.Railjack)))
					)))
	:allDone())
end
}
Advertisement