 

animamustafa= {};

function animamustafa.prerequisitesPresent(specializations)
      return true;
end;
function animamustafa.initSpecialization()
end
function animamustafa.registerOverwrittenFunctions(vehicleType)
end
function animamustafa.registerFunctions(vehicleType)	
end
function animamustafa.registerEvents(vehicleType)
end
function animamustafa:registerActionEventsPlayer()
end
function animamustafa:registerActionEventsMenu()
end

function animamustafa:onRegisterActionEvents(isSelected, isOnActiveVehicle)
	if isOnActiveVehicle then
		if self.animamustafa == nil then 
			self.animamustafa = {}
		else	
			self:clearActionEventsTable( self.animamustafa )
		end 
		for _,actionName in pairs({"ridelle_ar","ridelle_G","ridelle_D"}) do
			local _, eventName = self:addActionEvent(self.animamustafa, InputAction[actionName], self, animamustafa.actionCallback, true, true, false, true, nil);
	
			if isSelected then
				g_inputBinding.events[eventName].displayPriority = 1
			end
		end
	end
end

function animamustafa.registerEventListeners(vehicleType)
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", animamustafa)
	SpecializationUtil.registerEventListener(vehicleType, "onDelete", animamustafa)
    SpecializationUtil.registerEventListener(vehicleType, "onReadStream", animamustafa)
    SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", animamustafa)
    --SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", animamustafa)
    --SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", animamustafa)
	SpecializationUtil.registerEventListener(vehicleType, "onUpdate", animamustafa)
	SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", animamustafa)
	SpecializationUtil.registerEventListener(vehicleType, "onDraw", animamustafa)
	SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", animamustafa)
end

function animamustafa:onLoad(vehicle)	
	self.ridelle_ar = animamustafa.ridelle_ar
	self.ridelle_G = animamustafa.ridelle_G
	self.ridelle_D = animamustafa.ridelle_D
	self.RidelleAR = false
	self.RidelleG = false
	self.RidelleD = false
	
end;

function animamustafa:onDelete() 
end;
function animamustafa:onReadStream(streamId, connection)   
end;  
function animamustafa:onWriteStream(streamId, connection)  
end;
function animamustafa:mouseEvent(posX, posY, isDown, isUp, button)
end;
function animamustafa:keyEvent(unicode, sym, modifier, isDown)    
end;
function animamustafa:onUpdate(dt, vehicle)		
end;
function animamustafa:onUpdateTick() 
end;	
function animamustafa:onDeactivate()	
end;       
function animamustafa:onDraw()  
end;

function animamustafa:actionCallback(actionName, keyStatus, arg4, arg5, arg6)
	if keyStatus > 0 then
		if actionName == 'ridelle_ar' then
			if self.RidelleAR then
				self:ridelle_ar(false)
			else 
				self:ridelle_ar(true)
			end
		end
		if actionName == 'ridelle_G' then
			if self.RidelleG then
				self:ridelle_G(false)
			else 
				self:ridelle_G(true)
			end
		end
		if actionName == 'ridelle_D' then
			if self.RidelleD then
				self:ridelle_D(false)
			else 
				self:ridelle_D(true)
			end
		end
	end
end

function animamustafa:ridelle_ar(RidelleAR, noEventSend)
	ridelle_arEvent.sendEvent(self, RidelleAR, noEventSend)
	self.RidelleAR = RidelleAR;
		if self.RidelleAR then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("ridelle_ar", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("ridelle_ar", -1, nil, true)
			end
		end;
end;


function animamustafa:ridelle_G(RidelleG, noEventSend)
	ridelle_GEvent.sendEvent(self, RidelleG, noEventSend)
	self.RidelleG = RidelleG;
		if self.RidelleG then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("ridelle_G", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("ridelle_G", -1, nil, true)
			end
		end;
end;

function animamustafa:ridelle_D(RidelleD, noEventSend)
	ridelle_DEvent.sendEvent(self, RidelleD, noEventSend)
	self.RidelleD = RidelleD;
		if self.RidelleD then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("ridelle_D", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("ridelle_D", -1, nil, true)
			end
		end;
end;

--- Event ---

ridelle_arEvent = {};
ridelle_arEvent_mt = Class(ridelle_arEvent, Event);
InitEventClass(ridelle_arEvent, "ridelle_arEvent");

function ridelle_arEvent:emptyNew()
    local self = Event:new(ridelle_arEvent_mt);
    return self;
end;
function ridelle_arEvent:new(object, RidelleAR)
	local self = ridelle_arEvent:emptyNew()
	self.object = object;
	self.RidelleAR = RidelleAR;
	return self;
end;
function ridelle_arEvent:readStream(streamId, connection)
	self.object = NetworkUtil.readNodeObject(streamId);
	self.RidelleAR = streamReadBool(streamId);
	self:run(connection);
end;
function ridelle_arEvent:writeStream(streamId, connection)
	NetworkUtil.writeNodeObject(streamId, self.object);
	streamWriteBool(streamId, self.RidelleAR);
end;
function ridelle_arEvent:run(connection)
	if not connection:getIsServer() then
		g_server:broadcastEvent(self, false, connection, self.object);
	end;
	if self.object ~= nil then
		self.object:ridelle_ar(self.RidelleAR, true);
	end;
end;
function ridelle_arEvent.sendEvent(vehicle, RidelleAR, noEventSend)
	if RidelleAR ~= vehicle.RidelleAR then
		if noEventSend == nil or noEventSend == false then
			if g_server ~= nil then
				g_server:broadcastEvent(ridelle_arEvent:new(vehicle, RidelleAR), nil, nil, vehicle);
			else
				g_client:getServerConnection():sendEvent(ridelle_arEvent:new(vehicle, RidelleAR));
			end;
		end;
	end;
end;

ridelle_GEvent = {};
ridelle_GEvent_mt = Class(ridelle_GEvent, Event);
InitEventClass(ridelle_GEvent, "ridelle_GEvent");

function ridelle_GEvent:emptyNew()
    local self = Event:new(ridelle_GEvent_mt);
    return self;
end;
function ridelle_GEvent:new(object, RidelleG)
	local self = ridelle_GEvent:emptyNew()
	self.object = object;
	self.RidelleG = RidelleG;
	return self;
end;
function ridelle_GEvent:readStream(streamId, connection)
	self.object = NetworkUtil.readNodeObject(streamId);
	self.RidelleG = streamReadBool(streamId);
	self:run(connection);
end;
function ridelle_GEvent:writeStream(streamId, connection)
	NetworkUtil.writeNodeObject(streamId, self.object);
	streamWriteBool(streamId, self.RidelleG);
end;
function ridelle_GEvent:run(connection)
	if not connection:getIsServer() then
		g_server:broadcastEvent(self, false, connection, self.object);
	end;
	if self.object ~= nil then
		self.object:ridelle_G(self.RidelleG, true);
	end;
end;
function ridelle_GEvent.sendEvent(vehicle, RidelleG, noEventSend)
	if RidelleG ~= vehicle.RidelleG then
		if noEventSend == nil or noEventSend == false then
			if g_server ~= nil then
				g_server:broadcastEvent(ridelle_GEvent:new(vehicle, RidelleG), nil, nil, vehicle);
			else
				g_client:getServerConnection():sendEvent(ridelle_GEvent:new(vehicle, RidelleG));
			end;
		end;
	end;
end;


ridelle_DEvent = {};
ridelle_DEvent_mt = Class(ridelle_DEvent, Event);
InitEventClass(ridelle_DEvent, "ridelle_DEvent");

function ridelle_DEvent:emptyNew()
    local self = Event:new(ridelle_DEvent_mt);
    return self;
end;
function ridelle_DEvent:new(object, RidelleD)
	local self = ridelle_DEvent:emptyNew()
	self.object = object;
	self.RidelleD = RidelleD;
	return self;
end;
function ridelle_DEvent:readStream(streamId, connection)
	self.object = NetworkUtil.readNodeObject(streamId);
	self.RidelleD = streamReadBool(streamId);
	self:run(connection);
end;
function ridelle_DEvent:writeStream(streamId, connection)
	NetworkUtil.writeNodeObject(streamId, self.object);
	streamWriteBool(streamId, self.RidelleD);
end;
function ridelle_DEvent:run(connection)
	if not connection:getIsServer() then
		g_server:broadcastEvent(self, false, connection, self.object);
	end;
	if self.object ~= nil then
		self.object:ridelle_D(self.RidelleD, true);
	end;
end;
function ridelle_DEvent.sendEvent(vehicle, RidelleD, noEventSend)
	if RidelleD ~= vehicle.RidelleD then
		if noEventSend == nil or noEventSend == false then
			if g_server ~= nil then
				g_server:broadcastEvent(ridelle_DEvent:new(vehicle, RidelleD), nil, nil, vehicle);
			else
				g_client:getServerConnection():sendEvent(ridelle_DEvent:new(vehicle, RidelleD));
			end;
		end;
	end;
end;