-- In FS15: Rockstar94 --



SteeringAnimationNodes = {};

function SteeringAnimationNodes.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function SteeringAnimationNodes:load(xmlFile)
	self.steeringAnimationNodes = {}
	self.steeringAnimationTime = 0
	local i = 0
	while true do
		do
		local baseName = string.format("vehicle.steeringAnimationNodes.animationNode(%d)", i)
		if not hasXMLProperty(xmlFile, baseName) then
			break
		end
		local animationNode = {}
		local wheelIndex = getXMLInt(xmlFile, baseName .. "#wheelIndex")
		animationNode.wheel = self.wheels[wheelIndex + 1]
		animationNode.wheelMinRot = animationNode.wheel.rotMin
		animationNode.wheelMaxRot = animationNode.wheel.rotMax
			if animationNode.wheel.rotMin == 0 then
				animationNode.wheelMinRot = animationNode.wheel.steeringAxleRotMin
				animationNode.wheelMaxRot = animationNode.wheel.steeringAxleRotMax
			end
			animationNode.node = Utils.indexToObject(self.components, getXMLString(xmlFile, baseName .. "#index"))
			animationNode.minXRot = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, baseName .. "#minXRot"), 0))
			animationNode.maxXRot = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, baseName .. "#maxXRot"), 0))
			table.insert(self.steeringAnimationNodes, animationNode)
			i = i + 1
		end
	end
end;

function SteeringAnimationNodes:delete()
end;

function SteeringAnimationNodes:keyEvent(unicode, sym, modifier, isDown)
 end;
 
function SteeringAnimationNodes:update(dt)	
    self.steeringAnimationTime = self.time + 2000
	
	if self.steeringAnimationTime > self.time then
		for _, animationNode in pairs(self.steeringAnimationNodes) do
		local rotation = animationNode.wheelMaxRot
		local animRotation = animationNode.maxXRot
			if 0 >= animationNode.wheel.steeringAngle then
				rotation = animationNode.wheelMinRot
				animRotation = animationNode.minXRot
			end
			local percent = 0
			if rotation ~= 0 then
				percent = math.abs(animationNode.wheel.steeringAngle / rotation)
			end
			setRotation(animationNode.node, animRotation * percent, 0, 0)
		end
	end
end;

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

function SteeringAnimationNodes:validateAttacherJoint(implement, jointDesc, dt)
return true;
end;

function SteeringAnimationNodes:draw()
end;