Fortnite Esports Wiki

Power Rankings of Brazil and Oceania are not yet fully updated. Currently all our efforts are on the C2S8 competitive season. We will aim to have all regions updated before the end of the year.

READ MORE

Fortnite Esports Wiki
Advertisement
Fortnite Esports Wiki

To edit the documentation or categories for this module, click here.


local util_args = require('Module:ArgsUtil')
local util_html = require("Module:HtmlUtil")
local util_map = require('Module:MapUtil')
local util_table = require("Module:TableUtil")
local util_text = require("Module:TextUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require("Module:I18nUtil")
local lang = mw.getLanguage('en')

local EntityListAbstract = require('Module:EntityListAbstract')

local p = EntityListAbstract:finalExtends()
local h = {}

p.Entity = require('Module:Role')

function p:init(str, opts)
	if not opts then opts = {} end
	self.opts = opts
	opts.sep = opts.sep or ';'
	self:super('init', str, opts)
	self.modifier = opts.modifier
	if self.is_nil and opts.modifier then
		-- case when we have a modifier but no string (e.g. solely sub or trainee)
		self.objs = { self.Entity(nil, opts) }
		self.is_nil = false
	end
	if self.is_nil then return end

	self.isFiltered = false	
end

function p:names(opts)
	if self.is_nil then return end
	if not opts then opts = {} end
	local opts2 = mw.clone(opts)
	local tbl = {}
	
	for i, obj in ipairs(self) do
		tbl[#tbl+1] = obj:name(opts2)
		
		-- skip the prefix starting with the second item in the list
		-- for example, we want to write Sub/Sup/Assistant Coach
		-- instead of Sub/Sup/Sub/Assistant coach
		
		-- however we'd want to write Assistant Coach/Sub/Sup
		if obj:isIngame() then
			opts2.skip_prefix = true
		end
	end
	return util_table.concat(tbl, opts.sep)
end

function p:sentence()
	if self.is_nil then return end
	local nouns = {}
	local preps = {}
	local phrases = {}
	local prep = self.objs[1]:get('prep')
	
	-- we have to print a preposition next to each word only if
	-- they disagree in the prepositions used, e.g. mid laner for and co-owner of
	-- but mid laner and manager for
	-- so track whether we've changed preposition at all;
	-- if so, then concat and return the phrases
	-- if not then just return the nouns
	local usePreps = false
	for i, obj in ipairs(self) do
		nouns[i] = obj:name{len='sentence'}
		phrases[i] = ('%s %s'):format(obj:name{len='sentence'}, obj:get('prep'))
		if prep ~= obj:get('prep') then
			usePreps = true
		end
	end
	if not usePreps then
		return util_table.printList(nouns) .. ' ' .. prep
	end
	return util_table.printList(phrases)
end

function p:sortnumber()
	if self.is_nil then return end
	return self.objs[1]:sortnumber()
end

function p:ingame()
	return self:getFilterKey('ingame')
end

function p:staff()
	return self:getFilterKey('staff')
end

function p:hasIngame()
	return self:getFilterKey('hasIngame')
end

function p:hasStaff()
	return self:getFilterKey('hasStaff')
end

function p:isIngameOnly()
	return self:getFilterKey('isIngameOnly')
end

function p:isStaffOnly()
	return self:getFilterKey('isStaffOnly')
end

function p:getFilterKey(key)
	if self.isFiltered then return self.filters[key] end
	self:getFilters()
	return self.filters[key]
end

function p:getFilters()
	optsIngame = mw.clone(self.opts)
	optsStaff = mw.clone(self.opts)
	optsStaff.modifier = nil
	optsStaff.trainee = nil
	optsStaff.Trainee = nil
	optsStaff.sub = nil
	optsStaff.Sub = nil
	optsIngame.alreadyCast = true
	optsStaff.alreadyCast = true
	local ingame = p(h.filterIngameRoles(self, true), optsIngame)
	local staff = p(h.filterIngameRoles(self, false), optsStaff)
	self.filters = {
		ingame = ingame,
		staff = staff,
		hasIngame = ingame:exists(),
		hasStaff = staff:exists(),
		isIngameOnly = not staff:exists(),
		isStaffOnly = not ingame:exists(),
	}
	self.isFiltered = true
end

function h.filterIngameRoles(objs, isIngame)
	local filteredRoles = {}
	for _, role in ipairs(objs) do
		if isIngame == role:isIngame() then
			filteredRoles[#filteredRoles+1] = role
		end
	end
	return filteredRoles
end

return p
Advertisement