--[[

***************************************************************
Created by: clockwork
Bug reports and suggestions appreciated: http://bit.ly/ZJMQpY

Version 1.2.7
Updated: April 19, 2013
***************************************************************

--]]

function SimPostInit(player)
	GLOBAL.LoadScript("commands.lua")
	
	AddTestToolController(player)
	HUDOverride(player)
end

function AddTestToolController(player)
	player:AddComponent("testtoolcontroller")	
end

-- Overrides PlayerHud:SetMainCharacter
-- Re-adds custom component if player switches characters
function HUDOverride(player)
	GLOBAL.PlayerHud.PreSetMainCharacter = GLOBAL.PlayerHud.SetMainCharacter
	
	GLOBAL.PlayerHud.SetMainCharacter = function(self, maincharacter)
		AddTestToolController(maincharacter)
		self:PreSetMainCharacter(maincharacter)
	end
end

AddSimPostInit(SimPostInit)

-- Overrides AmbientSoundMixer:UpdateAmbientVolume
-- Adds a sanity check to the function since switching characters will cause a nil player reference
function MixerOverride(mixer, inst)
	mixer.Original = mixer.UpdateAmbientVolumes
	
	mixer.UpdateAmbientVolumes = function(self)
		local player = GLOBAL.GetPlayer()
		
		if player then
			self:Original()
		else
			return
		end
	end
end

AddComponentPostInit("ambientsoundmixer", MixerOverride)