Edit the documentation or categories for this module.
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:Role2')
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:serialize()
local tbl = {}
for _, obj in ipairs(self) do
tbl[#tbl+1] = obj:serialize()
end
-- same separator as we use in p:init
return util_table.concat(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