--
-- Specialization intSound
--
-- @Author  	Aluha74rus
-- @version 	v1.0
-- @date  		04/09/19

-- @edit by _-OvErClOcKeR-_ special for 150gus
-- @date of edit 21.11.19
-- @Version of edit v1.1

intSound = {};

intSound.modDir = g_currentModDirectory;

function intSound.prerequisitesPresent(specializations)
    return true; 
end;

function intSound.registerEventListeners(vehicleType)	
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", intSound)
	SpecializationUtil.registerEventListener(vehicleType, "onDelete", intSound)
	SpecializationUtil.registerEventListener(vehicleType, "onUpdate", intSound)
end
function intSound:onLoad(savegame)
	if self.isClient then
	    self.sampleKLSwetStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkBackStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkBackStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkBackEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkBackEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetAwStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetAwStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetAwEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetAwEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	end
end;

function intSound:onDelete()
    if self.isClient then
		g_soundManager.deleteSample(self.sampleKLSwetStart);
		g_soundManager.deleteSample(self.sampleKLSwetEnd);
		g_soundManager.deleteSample(self.sampleKLSwetWorkStart);
		g_soundManager.deleteSample(self.sampleKLSwetWorkEnd);
		g_soundManager.deleteSample(self.sampleKLSwetWorkBackStart);
		g_soundManager.deleteSample(self.sampleKLSwetWorkBackEnd);
		g_soundManager.deleteSample(self.sampleKLSwetAwStart);
		g_soundManager.deleteSample(self.sampleKLSwetAwEnd);
    end
end

function intSound:onUpdate(dt)
	
    
    if self.isClient then
	    if self:getIsAnimationPlaying("klawishaBliznii") then
		    if self.spec_animatedVehicle.animations["klawishaBliznii"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaBliznii"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaBliznii"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaBliznii"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetEnd,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("klawishaWork") then
		    if self.spec_animatedVehicle.animations["klawishaWork"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaWork"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaWork"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaWork"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkEnd,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("klawishaWorkBack") then
		    if self.spec_animatedVehicle.animations["klawishaWorkBack"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaWorkBack"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkBackStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkBackStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaWorkBack"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaWorkBack"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkBackEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkBackEnd,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("klawishaAwarika") then
		    if self.spec_animatedVehicle.animations["klawishaAwarika"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaAwarika"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetAwStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetAwStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaAwarika"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaAwarika"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetAwEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetAwEnd,1.5*dt);
			    end;
		    end;
		end;
	end;
end;