--
-- LeveDX
--
-- written by ice_black
--

LeveDX = {};

LeveDX.modDir = g_currentModDirectory;

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

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

function LeveDX:delete()

end;

function LeveDX:readStream(streamId, connection)
end;

function LeveDX:writeStream(streamId, connection)
end;

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

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

function LeveDX:update(dt)

	if self:getIsActive() then
		if self.isClient then
			
			local axisForward = 0;
			axisForward = InputBinding.getDigitalInputAxis(InputBinding.AXIS_MOVE_FORWARD_VEHICLE);
			if InputBinding.isAxisZero(axisForward) then
				axisForward = InputBinding.getAnalogInputAxis(InputBinding.AXIS_MOVE_FORWARD_VEHICLE)
			end;
			--print("axisForward="..axisForward);
			if axisForward < 0 then
				self.sj1.rotT = -self.sj1.rotF*axisForward;
			elseif axisForward > 0 then
				self.sj1.rotT = self.sj1.rotB*axisForward;
			else
				self.sj1.rotT = 0;
			end
			
			if self.ESLimiter ~= nil and self.lastLevel ~= 0 and self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection() then
				local percentage = self.ESLimiter.percentage;
				if InputBinding.isPressed(InputBinding.ESLimiter_PLUS) and percentage[self.lastLevel] < 100 then					
					self.sj1.rotT = self.sj1.rotF/2;
				elseif InputBinding.isPressed(InputBinding.ESLimiter_MINUS) and percentage[self.lastLevel] > 10 then
					self.sj1.rotT = self.sj1.rotB/2;
				end;
			end;			
			
			if self.sj1.rotC < self.sj1.rotT then
				self.sj1.rotC = self.sj1.rotC + dt/1000;
				if self.sj1.rotC > self.sj1.rotT then
					self.sj1.rotC = self.sj1.rotT;
				end;
			elseif self.sj1.rotC > self.sj1.rotT then
				self.sj1.rotC = self.sj1.rotC - dt/1000;
				if self.sj1.rotC < self.sj1.rotT then
					self.sj1.rotC = self.sj1.rotT;
				end;
			end;
			
			setRotation( self.sj1.node, self.sj1.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.LeveDXl ~= 0 then
	end;
	
end;

function LeveDX:updateTick(dt)

end;

function LeveDX:onLeave()
end;

function LeveDX:draw()
end;





--
--
--
--
--
