-- Called once when the realism client is starting.
-- This is intended for compatibility with AeroGameFramework modules,
-- but the function will automatically be called if executed from a LocalScript.


function CharacterRealism:Start()
	assert(not _G.DefineRealismClient, "Realism can only be started once on the client!")
	_G.DefineRealismClient = true
	
	for key, value in pairs(Config) do
		self[key] = value
	end
	
	for _,humanoid in pairs(CollectionService:GetTagged(self.BindTag)) do
		self:OnHumanoidAdded(humanoid)
	end
	
	self:Connect("UpdateLookAngles", RunService.Heartbeat)
	self:Connect("OnLookReceive", self.SetLookAngles.OnClientEvent)
	self:Connect("OnHumanoidAdded", CollectionService:GetInstanceAddedSignal(self.BindTag))
	
	FpsCamera:Start()
end

if script:IsA("ModuleScript") then
	-- Return the system as a module table.
	return CharacterRealism
else
	-- Sanity check
	assert(script:FindFirstAncestorOfClass("PlayerScripts"), "RealismClient must be a descendant of the PlayerScripts!")
	assert(Players.LocalPlayer, "RealismClient expects a Player on the client to automatically start execution!")	
	
	-- Start automatically.
	CharacterRealism:Start()
end
