--BY Dami95 & Mlody & LenoX--

--Nome.XML
--<load index="??" />

zegary = {};

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

function zegary:load(xmlFile)


	
--ladownosc - load
	self.load = {};
	self.load.index = Utils.indexToObject(self.rootNode, getXMLString(xmlFile,  "vehicle.load#index"));
	--self.load.light = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.zegary#load_light"));
	--self.load.alert = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.zegary#load_alert"));

	--Suono Pieno
	self.FullSound = createSample("FullSound");
    loadSample(self.FullSound, Utils.getFilename("sounds/Full2.wav", self.baseDirectory), false);
end;

function zegary:delete()
	if self.FullSound ~= nil then
        stopSample(self.FullSound);
    end;
end;

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

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

function zegary:update(dt)
	
--ladownosc - load
local f,c = self:getAttachedTrailersFillLevelAndCapacity();
if f and c ~= nil then
	local prozent = f/c*100;
	local load_pos = prozent*202.5/100;
	setRotation(self.load.index, 0, 0, Utils.degToRad(load_pos/3));
	
	if prozent == 0 then
	setRotation(self.load.index, 0, 0, 0);
	end;
	end;

	
	if self:getIsActiveForSound() then
	local prozent = f/c*100;
	if prozent >= 97 and prozent ~= 100 and not self.isTurnedOn then
			playSample(self.FullSound, 1, 0.5,0);
	elseif self.isTurnedOn and prozent<3 then
			playSample(self.FullSound, 1, 0.5,0);
	end;
	end;



end;

function zegary:onLeave()
	if self.FullPlaying then
		stopSample(self.FullSoundId);
		self.FullPlaying = false;
	end;
end;

function zegary:draw()
end;