local w=require(script.System)local O=require(script.Selectors)local T=require(script.Selectors.Util)return function(I)I.selectors=O(I)I.query=function(O,...)assert(type(O)=="\115\116\114\105\110\103")return(w.new(I,O,...)):setup()end I.get=function(O,...)assert(type(O)=="\115\116\114\105\110\103")local T={}for w,q in pairs((w.new(I,...)):instances())do table.insert(T,I:getEntity(q,O))end return T end I.system=function(O,q,B,f)assert(type(O)=="\115\116\114\105\110\103")assert(T.inheritsBase(q))assert(B==nil or type(B)=="\116\097\098\108\101")assert(f==nil or type(f)=="\102\117\110\099\116\105\111\110")local L=w.new(I,O,q)if B then for w,O in pairs(B)do if L[w]then error("\097\116 \108\101\097\115\116 \111\110\101 \112\114\111\112\101\114\116\121 \097\108\114\101\097\100\121 \105\110 \117\115\101 \098\121 \115\121\115\116\101\109",2)end L[w]=O end end if f then f(L)end return(L:setup()):catchup()end return I end
local System = require(script.System)
local Selectors = require(script.Selectors)
local Util = require(script.Selectors.Util)

return function(rocs)
	rocs.selectors = Selectors(rocs)

	rocs.query = function(scope, ...) -- optimized for reuse
		assert(type(scope) == "string")
		return System.new(rocs, scope, ...):setup()
	end

	rocs.get = function(scope, ...) -- single use entity list getter
		assert(type(scope) == "string")

		local entities = {}
		for _, instance in pairs(System.new(rocs, ...):instances()) do
			table.insert(entities, rocs:getEntity(instance, scope))
		end

		return entities
	end

	rocs.system = function(scope, selector, props, init) -- syntactic sugar around rocs.query
		assert(type(scope) == "string")
		assert(Util.inheritsBase(selector))
		assert(props == nil or type(props) == "table")
		assert(init == nil or type(init) == "function")

		local system = System.new(rocs, scope, selector)

		if props then
			for key, value in pairs(props) do
				if system[key] then
					error("at least one property already in use by system", 2)
				end
				system[key] = value
			end
		end

		if init then
			init(system)
		end

		return system:setup():catchup()
	end

	return rocs
end
