WARFRAME Wiki
Advertisement
WARFRAME Wiki

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

--	<nowiki>
local Table = require([[Module:Table]])

local function override(arg)
	return arg and arg..'[[Category:InfoboxOverride]]'
end

return {
buildInfobox = function(frame)
	local args = frame.args;
	local name = mw.text.decode(args['Name']);
	local resourceData = mw.loadData([[Module:Resources/data]]).Resources[name];
	assert(resourceData ~= nil, 'buildInfobox(frame): "'..name..'" does not exist in [[Module:Resources/data]]')
	local dropData = mw.loadData([[Module:DropTables/data]]);
	
	local htmlmt = getmetatable(mw.html.create())
	local htmlindex = htmlmt.__index

	htmlindex.group = function(self, collapse)
		return self:tag('group'):attr('collapse', collapse or 'open')
	end

	htmlindex.header = function(self, header)
		return self:tag('header'):wikitext(header):done()
	end

	htmlindex.row = function(self, source, label, default)
		return self:tag('data'):attr('source', source)
			:tag('label'):wikitext(label):done()
			:tag('default'):wikitext(default):done()
		:done()
	end
	
	htmlindex.caption = function(self, source, default)
		return self:tag('data'):attr('source', source)
			:tag('default'):wikitext(default and '<div style="text-align: center; font-size: 12px"><b>'..default..'</b></div>'):done()
		:done()
	end

	local infobox = mw.html.create('infobox')
		:tag('title')
			:tag('default')
				:tag('b'):wikitext(name..'[[Category:Resources]]'):done()
			:done()
		:done()
		:tag('image'):attr('source', 'Image')
			:tag('default'):wikitext((resourceData.ContainerImage ~= nil and 
					('<gallery>%s|Pickup\n%s|Deposit</gallery>'):format(resourceData.Image, resourceData.ContainerImage) or 
					resourceData.Image) or 'Panel.png'):done()
		:done()
		:group()
			:caption('Tradable', resourceData.Tradable == true and "'''{{text|green|TRADABLE}}'''" or "'''{{text|red|UNTRADABLE}}'''")
		:done()
		
		:group():header('Description')
			:tag('data'):attr('source', 'Description')
				:tag('default')
					:tag('div'):css('text-align', 'center')
						:tag('b'):wikitext(resourceData.Description):done()
					:done()
				:done()
			:done()
		:done()

		:group():header('Statistics')
			:row('Type', 'Type', (resourceData.Type ~= 'Resource') and resourceData.Type..'[[Category:'..resourceData.Type..' Resources]]' or resourceData.Type)
			:row('Rarity', 'Rarity', resourceData.Rarity and resourceData.Rarity..'[[Category:'..resourceData.Rarity..' Resources]]' or '')
			:row('Helminth', '[[Helminth#Secretions|Helminth Secretions]]', resourceData.HelminthCategory and resourceData.HelminthCategory..' ('..resourceData.HelminthCost..')[[Category:Helminth Resources]]' or '')
			:row('SellPrice', 'Sell Price', '[[File:Credits64.png|x20px|link=Credits]] '..(resourceData.SellPrice and resourceData.SellPrice or 'Cannot Sell'))
			:row('Introduced', 'Introduced', resourceData.Introduced and '{{ver|'..resourceData.Introduced..'}}[[Category:Update '..resourceData.Introduced:sub(1, (string.find(resourceData.Introduced, '%.') or 0) - 1)..']]')
			:row('InternalName', 'Internal Name', resourceData.InternalName and '<code>'..resourceData.InternalName..'</code>' or '')
		:done()
		
	local rotStr, tierStr
	local enemies, enemyStr = {}, {'\'\'\'Enemies:\'\'\''}
	local missions, missionStr = {}, {'\'\'\'Missions:\'\'\''}
	local syndicates, syndicateStr = {}, {'\'\'\'Syndicates:\'\'\''}
	
	for _, syndicate in ipairs(dropData.Syndicates) do
		for _, mod in ipairs(syndicate.Offerings) do
			if mod[1] == name then
				table.insert(syndicates, {Name = syndicate.Name, Cost = mod[3]} )
				break
			end
		end
	end
	table.sort(syndicates, function(a, b)
			if a.Cost == b.Cost then return a.Name < b.Name end
			return a.Cost < b.Cost
		end)
	for _, syndicate in ipairs(syndicates) do
		table.insert(syndicateStr, '[['..syndicate.Name..']]&nbsp;[[File:ReputationBlackx64.png|x20px|link=Standing]]'..syndicate.Cost)
	end
	
	if syndicates[1] then
		infobox:group():header('Sources')
			:tag('data'):attr('source', 'Syndicates')
				:tag('default'):wikitext(table.concat(syndicateStr, '<br />')):done()
			:done()
		:done()
	else
		for _, enemy in ipairs(dropData.Enemies) do
			if not(enemy.Ignore) and enemy.Mods then
				for _, mod in ipairs(enemy.Mods) do
					if mod[1] == name then
						table.insert(enemies, {Name = enemy.Name, Chance = enemy.ModChance * mod[2] / 100, Count = mod[3]} )
						break
					end
				end
			end
		end
		table.sort(enemies, function(a, b)
				if a.Chance*(a.Count or 1) == b.Chance*(b.Count or 1) then return a.Name < b.Name end
				return a.Chance*(a.Count or 1) > b.Chance*(b.Count or 1)
			end)
		for _, enemy in ipairs(enemies) do
			table.insert(enemyStr, (enemy.Count and enemy.Count..'x&nbsp;' or '')..'[['..enemy.Name..']]&nbsp;'..enemy.Chance..'%')
		end
		
		for _, mission in ipairs(dropData.Missions) do
			if not(mission.Ignore) and mission.Type ~= "Baro Ki'Teer" and mission.Rewards then
				for rotation, mods in pairs(mission.Rewards) do
					for _, mod in ipairs(mods) do
						if mod[1] == name then
							if not missions[mission.Type] then
								missions[mission.Type] = {}
							end
							if not missions[mission.Type][mission.Name or mission.Tier] then
								missions[mission.Type][mission.Name or mission.Tier] = {}
							end
							
							table.insert(missions[mission.Type][mission.Name or mission.Tier], {Rot = rotation, Chance = mod[3], Count = mod[4] and mod[4]..'x&nbsp;' or ''} )
							break
						end
					end
				end
			end
		end
		for mission, tiers in Table.skpairs(missions) do
			tierStr = {}
			for tier, rots in Table.skpairs(tiers) do
				rotStr = {}
				table.sort(rots, function(a, b) return a.Rot < b.Rot end)
				
				for _, v in ipairs(rots) do
					table.insert(rotStr, v.Count..'Rotation '..v.Rot..':&nbsp;'..v.Chance..'%')
				end
				
				table.insert(tierStr, ('<span style="border-bottom: 1px dotted;" class="basic-tooltip" title="%s">%s</span>'):format(table.concat(rotStr, '\\n'), tier:gsub('<br />', ': '):gsub(' ', '&nbsp;')))
			end
			
			table.insert(missionStr, '[['..mission..']] ('..table.concat(tierStr, ', ')..')')
		end
		
		if not missionStr[2] then missionStr = nil end
		if not enemyStr[2] then enemyStr = nil end
		
		if missionStr and enemyStr then
			table.remove(missionStr, 1)
			table.remove(enemyStr, 1)
			infobox:group():header('Sources')
				:tag('data'):attr('source', 'Drops')
					:tag('default')
						:tag('div'):addClass('tabber-borderless')
							:wikitext('<tabber>\n|-| Missions = '..table.concat(missionStr, '<br />')..'\n|-| Enemies = '..table.concat(enemyStr, '<br />')..'\n</tabber>')
						:done()
					:done()
				:done()
			:done()
		else
			infobox:group():header('Sources')
				:tag('data'):attr('source', 'Missions')
					:tag('default'):wikitext(missionStr and table.concat(missionStr, '<br />')):done()
				:done()
				:tag('data'):attr('source', 'Enemies')
					:tag('default'):wikitext(enemyStr and table.concat(enemyStr, '<br />')):done()
				:done()
			:done()
		end
	end

	return frame:preprocess(tostring(infobox))
end
}
Advertisement