--
-- LaLittorale
-- 
-- Controle mouvement de flêche
--
--
-- @auteur:		fozzy691
-- @version:	v1.0
-- @date:		01/08/2012
-- 
-- Copyright (C) 
--

LaLittorale = {};

function LaLittorale.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Trailer, specializations);
end;

function LaLittorale:load(xmlFile)
	self.doJointSearchCylindered = false;
	self.origMouseControlsAxes = self.mouseControlsAxes;
	self.disaMouseControlsAxes = {};
end;	
	

function LaLittorale:delete()
end;

function LaLittorale:mouseEvent(posX, posY, isDown, isUp, button)
end;

function LaLittorale:keyEvent(unicode, sym, modifier, isDown)
end;

function LaLittorale:update(dt)
end;

function LaLittorale:updateTick(dt)

	if self.varTip ~= nil then
		if self.varTip.activeTrailerIdx ~= self.varTip.trailerNr then
			self.mouseControlsAxes = self.disaMouseControlsAxes;
			return;
		else
			self.mouseControlsAxes = self.origMouseControlsAxes;
		end;
	end;

	-- ####
	if self.doJointSearchCylindered then
		if self.attacherVehicle ~= nil then
			for k,v in pairs(self.attacherVehicle.attachedImplements) do
				if v.object == self then
					local joint = self.attacherVehicle.attacherJoints[v.jointDescIndex];
					self.vehicleJoint = joint;
					self.doJointSearchCylindered = false;
					break;
				end;
			end;
		end;
		self.doJointSearchCylindered = false;
	end;
	
	-- #### update the attacherJoint!     
    if self.vehicleJoint ~= nil then
        setJointFrame(self.vehicleJoint.jointIndex, 1, self.attacherJoint.node);
	end;
	
	-- ### update PowerShaft!
	--[[
	if self.attacherVehiclePowerShaft ~= nil then
		self.doJointSearch = true;
	end;]]--
		
end;

function LaLittorale:draw()
end;

function LaLittorale:onAttach()
	self.doJointSearchCylindered = true;
end;

function LaLittorale:onDetach()
	self.vehicleJoint = nil;
	
	local rX, rY, rZ = getRotation( Utils.indexToObject(self.components, "6|12") );
	
	if rX < Utils.degToRad(3) then
		self.attacherJoint.jointType = Vehicle.JOINTTYPE_TRAILERLOW;
	else
		self.attacherJoint.jointType = Vehicle.JOINTTYPE_TRAILER;
	end;
end;

function LaLittorale:onLeave()
end;

function LaLittorale:onDeactivate()
end;

function LaLittorale:onDeactivateSounds()
end;


