Module:CompoundRoleAbstract

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 CompoundEntityAbstract = require('Module:CompoundEntityAbstract')

local p = CompoundEntityAbstract:extends 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) 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		-- 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 if i == 2 then opts2.skip_prefix = true end tbl[#tbl+1] = obj:name(opts2) end return util_table.concat(tbl, opts.sep) end

function p:sentence if self.is_nil then return end local tbl = {} for i, obj in ipairs(self) do		tbl[i] = obj:name{len='sentence'} end return util_table.printList(tbl) 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