-- by modelleicher
-- www.schwabenmodding.bplaced.net

TractorAnimations = {};

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

function TractorAnimations:load(savegame)
	-- Luefter
	self.Luefter = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations#luefterIndex"));
	
	-- Rolle
	self.rolle = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations.Rolle#rolleIndex"));
	-- Rolle
	self.rolle1 = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations.Rolle1#rolleIndex"));
	-- Rolle
	self.rolle2 = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations.Rolle2#rolleIndex"));
	-- Rolle
	self.rolle3 = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations.Rolle3#rolleIndex"));
	
	-- Temperaturzeiger / temperature Display animation
	self.temperaturZeiger = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations.TemperaturZeiger#zeigerIndex"));
	self.temperaturZeigerMaxRot = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.TractorAnimations.TemperaturZeiger#maxRotation"));
	self.tempCnt = 0;

	-- Temperaturzeiger2 / temperature Display animation
	self.temperaturZeiger2 = Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.TractorAnimations.TemperaturZeiger2#zeigerIndex"));
	self.temperaturZeigerMaxRot2 = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.TractorAnimations.TemperaturZeiger2#maxRotation"));
	self.tempCnt2 = 0;
	
end;
function TractorAnimations:delete()
end;
function TractorAnimations:mouseEvent(posX, posY, isDown, isUp, button)
end;
function TractorAnimations:keyEvent(unicode, sym, modifier, isDown)
end;

function TractorAnimations:updateTick(dt)
end;
function TractorAnimations:update(dt)
	if self:getIsActive() then
		if self.isMotorStarted then
			-- Luefter
			rotate(self.Luefter, 0,0,0.8*dt);
			
			--Rolle
			rotate(self.rolle, 0,0,0.8*dt);
			--Rolle
			rotate(self.rolle1, 0,0,0.8*dt);
			--Rolle
			rotate(self.rolle2, 0,0,0.8*dt);
			--Rolle
			rotate(self.rolle3, 0,0,0.8*dt);
			
			-- Temperaturanzeiger / temperature display animation und / and berechnung / calculation
			if self.tempCnt < 3000 then
				setRotation(self.temperaturZeiger, 0, Utils.degToRad((self.temperaturZeigerMaxRot/10000)*self.tempCnt), 0);
				self.tempCnt = self.tempCnt + 0.5;
			elseif self.tempCnt > 3000 and self.tempCnt < 6000 then
				setRotation(self.temperaturZeiger, 0, Utils.degToRad((self.temperaturZeigerMaxRot/10000)*self.tempCnt), 0);
				self.tempCnt = math.min(self.tempCnt + 0.2, 10000);			
			else
				setRotation(self.temperaturZeiger, 0, Utils.degToRad((self.temperaturZeigerMaxRot/10000)*self.tempCnt), 0);
				self.tempCnt = math.min(self.tempCnt + 0.05, 10000);
			end;
			if self.tempCnt2 < 3000 then
				setRotation(self.temperaturZeiger2, 0, Utils.degToRad((self.temperaturZeigerMaxRot2/10000)*self.tempCnt2), 0);
				self.tempCnt2 = self.tempCnt2 + 0.8;
			elseif self.tempCnt2 > 3000 and self.tempCnt2 < 6000 then
				setRotation(self.temperaturZeiger2, 0, Utils.degToRad((self.temperaturZeigerMaxRot2/10000)*self.tempCnt2), 0);
				self.tempCnt2 = math.min(self.tempCnt2 + 0.3, 10000);			
			else
				setRotation(self.temperaturZeiger2, 0, Utils.degToRad((self.temperaturZeigerMaxRot2/10000)*self.tempCnt2), 0);
				self.tempCnt2 = math.min(self.tempCnt2 + 0.04, 10000);
			end;			
		end;
	else
		self.tempCnt = math.max(self.tempCnt - 0.08, 0);
		self.tempCnt2 = math.max(self.tempCnt2 - 0.1, 0);
	end;
end;
function TractorAnimations:draw()
end;

function TractorAnimations:onEnter()
end;
function TractorAnimations:onLeave()
end;

