Leaguepedia | League of Legends Esports Wiki
[checked revision][checked revision]
([ST])
([ST] er try solve inf loop)
Line 26: Line 26:
 
if self.is_nil then return end
 
if self.is_nil then return end
 
 
  +
if not opts.alreadyCast then
-- local opts2 = mw.clone(opts)
 
-- opts2.alreadyCast = true
+
local opts2 = mw.clone(opts)
  +
opts2.alreadyCast = true
-- self.ingame = p(h.filterIngameRoles(self, true), opts2)
 
-- self.staff = p(h.filterIngameRoles(self, false), opts2)
+
self.ingame = p(h.filterIngameRoles(self, true), opts2)
 
self.staff = p(h.filterIngameRoles(self, false), opts2)
 
  +
-- self.hasIngame = self.ingame:exists()
 
-- self.hasStaff = self.staff:exists()
+
self.hasIngame = self.ingame:exists()
-- self.isIngameOnly = not self.staff:exists()
+
self.hasStaff = self.staff:exists()
-- self.isStaffOnly = not self.ingame:exists()
+
self.isIngameOnly = not self.staff:exists()
 
self.isStaffOnly = not self.ingame:exists()
  +
end
 
end
 
end
   

Revision as of 22:20, 17 July 2020

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
	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
	
	if not opts.alreadyCast then
		local opts2 = mw.clone(opts)
		opts2.alreadyCast = true
		self.ingame = p(h.filterIngameRoles(self, true), opts2)
		self.staff = p(h.filterIngameRoles(self, false), opts2)
		
		self.hasIngame = self.ingame:exists()
		self.hasStaff = self.staff:exists()
		self.isIngameOnly = not self.staff:exists()
		self.isStaffOnly = not self.ingame:exists()
	end
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

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

return p