--
-- Joystick for telehander
-- Base : SpeedJoystick 
--
-- Create by lesagri ls modding (10/11/15)

--

SpeedJoystick = {};

SpeedJoystick.modDir = g_currentModDirectory;

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

function SpeedJoystick:load(xmlFile)
	self.sj = {};
	self.sj.node = Utils.indexToObject( self.components, getXMLString(xmlFile, "vehicle.speedJoystick#node") );
	self.sj.rotF = math.rad( getXMLFloat(xmlFile, "vehicle.speedJoystick#rotFront") );
	self.sj.rotB = math.rad( getXMLFloat(xmlFile, "vehicle.speedJoystick#rotBack") );
	self.sj.rotT = 0;
	self.sj.rotC = 0;
end;

function SpeedJoystick:delete()

end;

function SpeedJoystick:readStream(streamId, connection)
end;

function SpeedJoystick:writeStream(streamId, connection)
end;

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

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

function SpeedJoystick:update(dt)

	if self:getIsActive() then
		if self.isClient then
			
			local axisForward = 0;
			axisForward = InputBinding.getDigitalInputAxis(InputBinding.AXIS_FRONTLOADER_ARM);
			if InputBinding.isAxisZero(axisForward) then
				axisForward = InputBinding.getAnalogInputAxis(InputBinding.AXIS_FRONTLOADER_ARM)
			end;
			--print("axisForward="..axisForward);
			if axisForward < 0 then
				self.sj.rotT = -self.sj.rotF*axisForward;
			elseif axisForward > 0 then
				self.sj.rotT = self.sj.rotB*axisForward;
			else
				self.sj.rotT = 0;
			end			
			
			if self.sj.rotC < self.sj.rotT then
				self.sj.rotC = self.sj.rotC + dt/1000;
				if self.sj.rotC > self.sj.rotT then
					self.sj.rotC = self.sj.rotT;
				end;
			elseif self.sj.rotC > self.sj.rotT then
				self.sj.rotC = self.sj.rotC - dt/1000;
				if self.sj.rotC < self.sj.rotT then
					self.sj.rotC = self.sj.rotT;
				end;
			end;
			
			setRotation( self.sj.node, self.sj.rotC, 0, 0 );
			
		end;
	end;

	--print("axisForward="..tostring(axisForward).." self.movingDirection="..tostring(self.movingDirection).." "..tostring(self.lastSpeed).."   self.lastSpeedReal="..tostring(self.lastSpeedReal));

	if self.motor.speedLevel ~= 0 then
	end;
	
end;

function SpeedJoystick:updateTick(dt)

end;

function SpeedJoystick:onLeave()
end;

function SpeedJoystick:draw()
end;





--
--
--
--
--
