function SchemaProcessor.Process(n,D)print("\080\114\111\099\101\115\115\105\110\103")local X,b=pcall(function()n.schema:Run()if not D then n.schema:cacheInitialTweenProperties()end n.schema:resetTweenObjects()n.schema.OrderedConfigs=n.schema:orderConfigs()n.connection=n.RunService.Heartbeat:Connect(function()for D,X in pairs(n.schema.OrderedConfigs)do local b=X.config local J=X.startTime if n.timePosition.Value>=J and b.Processed[J]==false then b.Processed[J]=true;(coroutine.wrap(function()b:Process(n,J)end))()end end end)n.Maid:add(n.connection)n.Maid:add(n.schema.Maid,"\099\108\101\097\110")end)if not X then warn("\082\117\110 \101\114\114\111\114\101\100 \102\111\114 \121\111\117\114 \115\099\101\110\101\033")warn(b)end return X,b end function SchemaProcessor.EndScene(D)print("\069\110\100 \111\102 \115\099\101\110\101\046 \082\117\110\110\105\110\103 \079\110\069\110\100\083\099\101\110\101 \102\111\114 \083\099\104\101\109\097")local n,X=pcall(function()D.schema:EndScene()end)if not n then warn("\069\110\100\083\099\101\110\101 \101\114\114\111\114\101\100 \102\111\114 \121\111\117\114 \115\099\101\110\101\033")warn(X)end return n,X end function SchemaProcessor.new(D,n)assert(D~=nil,"\089\111\117 \104\097\118\101\110\'\116 \115\117\098\115\099\114\105\098\101\100 \097 \115\099\104\101\109\097 \102\105\108\101 \102\111\114 \116\104\101 \083\099\104\101\109\097 \080\114\111\099\101\115\115\111\114\033")assert(n~=nil,"\089\111\117 \104\097\118\101\110\'\116 \115\117\098\115\099\114\105\098\101\100 \097 \116\105\109\101 \112\111\115\105\116\105\111\110 \102\111\114 \116\104\101 \083\099\104\101\109\097 \080\114\111\099\101\115\115\111\114\033")local X={Maid=Maid.new();schema=D,timePosition=n;processingPool={}}setmetatable(X,SchemaProcessor)X.Maid:add(X.schema.Maid,"\099\108\101\097\110")return X end function SchemaProcessor.SetPaused(n,D)n.isPaused=D end function SchemaProcessor.CleanUp(D)D.Maid:clean()end return SchemaProcessor
-- Generates a heartbeat connection for every audio visual / tween in the given schema file
function SchemaProcessor:Process(isSeeking)
	print("Processing")

	local success, err = pcall(function()
		self.schema:Run()
		if not isSeeking then
			self.schema:cacheInitialTweenProperties()
		end

		self.schema:resetTweenObjects()
		self.schema.OrderedConfigs = self.schema:orderConfigs()

		self.connection = self.RunService.Heartbeat:Connect(function()
			for _, data in pairs(self.schema.OrderedConfigs) do
				local config = data.config
				local startTime = data.startTime

				if self.timePosition.Value >= startTime and config.Processed[startTime] == false then
					config.Processed[startTime] = true
					coroutine.wrap(function()
						config:Process(self, startTime)
					end)()
				end
			end
		end)

		self.Maid:add(self.connection)
		self.Maid:add(self.schema.Maid, "clean")
	end)

	if not success then
		warn("Run errored for your scene!")
		warn(err)
	end
	return success, err
end

function SchemaProcessor:EndScene()
	print("End of scene. Running OnEndScene for Schema")
	local success, err = pcall(function()
		self.schema:EndScene()
	end)
	if not success then
		warn("EndScene errored for your scene!")
		warn(err)
	end
	return success, err
end

function SchemaProcessor.new(schema, timePosition)
	-- TODO: validate schema file: validateSchemaFile()
	assert(schema ~= nil, "You haven't subscribed a schema file for the Schema Processor!")
	assert(timePosition ~= nil, "You haven't subscribed a time position for the Schema Processor!")

	local self = {
		Maid = Maid.new(),
		schema = schema,
		timePosition = timePosition,
		processingPool = {},
	}

	setmetatable(self, SchemaProcessor)

	self.Maid:add(self.schema.Maid, "clean")

	return self
end

function SchemaProcessor:SetPaused(isPaused)
	self.isPaused = isPaused
end

function SchemaProcessor:CleanUp()
	self.Maid:clean()
end

return SchemaProcessor
