------------------------------------
--       by FWKB / Dusty          --
--#Matrix1 = Stop Polizei         --
--#Matrix2 = Bitte Folgen         --
--#Matrix3 = Unfall               --
--#Matrix4 = Stau                 --
--#Matrix5 = Pfeil linksweisend   --
--#Matrix6 = Pfeil rechtsweisend  --
------------------------------------

FWKBAnimationScript = {};

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

function FWKBAnimationScript:onRegisterActionEvents(isSelected, isOnActiveVehicle)
	if isOnActiveVehicle then
		if self.FWKBAnimationScript == nil then 
			self.FWKBAnimationScript = {}
		else	
			self:clearActionEventsTable( self.FWKBAnimationScript )
		end 
		for _,actionName in pairs({"matrix1","matrix2","matrix3","matrix4","matrix5","matrix6"}) do
			local _, eventName = self:addActionEvent(self.FWKBAnimationScript, InputAction[actionName], self, FWKBAnimationScript.actionCallback, true, true, false, true, nil);
	
			if isSelected then
				g_inputBinding.events[eventName].displayPriority = 1
			end
		end
	end
end

function FWKBAnimationScript.registerEventListeners(vehicleType)
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", FWKBAnimationScript)
	SpecializationUtil.registerEventListener(vehicleType, "onDelete", FWKBAnimationScript)
    SpecializationUtil.registerEventListener(vehicleType, "onReadStream", FWKBAnimationScript)
    SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", FWKBAnimationScript)
	SpecializationUtil.registerEventListener(vehicleType, "onUpdate", FWKBAnimationScript)
	SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", FWKBAnimationScript)
	SpecializationUtil.registerEventListener(vehicleType, "onDraw", FWKBAnimationScript)
	SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", FWKBAnimationScript)
end

function FWKBAnimationScript:onLoad(vehicle)	
	self.matrix1 = FWKBAnimationScript.matrix1
	self.matrix2 = FWKBAnimationScript.matrix2
	self.matrix3 = FWKBAnimationScript.matrix3
	self.matrix4 = FWKBAnimationScript.matrix4
	self.matrix5 = FWKBAnimationScript.matrix5
	self.matrix6 = FWKBAnimationScript.matrix6
	self.Matrix1 = false
	self.Matrix2 = false
	self.Matrix3 = false
	self.Matrix4 = false
	self.Matrix5 = false
	self.Matrix6 = false
	
end;

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

function FWKBAnimationScript:actionCallback(actionName, keyStatus, arg4, arg5, arg6)
	if keyStatus > 0 then
		if actionName == 'matrix1' then
			if self.Matrix1 then
				self:matrix1(false)
			else 
				self:matrix1(true)
			end
		end
		if actionName == 'matrix2' then
			if self.Matrix2 then
				self:matrix2(false)
			else 
				self:matrix2(true)
			end
		end
		if actionName == 'matrix3' then
			if self.Matrix3 then
				self:matrix3(false)
			else 
				self:matrix3(true)
			end
		end
		if actionName == 'matrix4' then
			if self.Matrix4 then
				self:matrix4(false)
			else 
				self:matrix4(true)
			end
		end
		if actionName == 'matrix5' then
			if self.Matrix5 then
				self:matrix5(false)
			else 
				self:matrix5(true)
			end
		end
		if actionName == 'matrix6' then
			if self.Matrix6 then
				self:matrix6(false)
			else 
				self:matrix6(true)
			end
		end
	end
end


function FWKBAnimationScript:matrix1(Matrix1, noEventSend)
	matrix1Event.sendEvent(self, Matrix1, noEventSend)
	self.Matrix1 = Matrix1;
		if self.Matrix1 then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix1", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix1", -1, nil, true)
			end
		end;
end;

function FWKBAnimationScript:matrix2(Matrix2, noEventSend)
	matrix2Event.sendEvent(self, Matrix2, noEventSend)
	self.Matrix2 = Matrix2;
		if self.Matrix2 then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix2", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix2", -1, nil, true)
			end
		end;
end;

function FWKBAnimationScript:matrix3(Matrix3, noEventSend)
	matrix3Event.sendEvent(self, Matrix3, noEventSend)
	self.Matrix3 = Matrix3;
		if self.Matrix3 then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix3", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix3", -1, nil, true)
			end
		end;
end;

function FWKBAnimationScript:matrix4(Matrix4, noEventSend)
	matrix4Event.sendEvent(self, Matrix4, noEventSend)
	self.Matrix4 = Matrix4;
		if self.Matrix4 then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix4", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix4", -1, nil, true)
			end
		end;
end;

function FWKBAnimationScript:matrix5(Matrix5, noEventSend)
	matrix5Event.sendEvent(self, Matrix5, noEventSend)
	self.Matrix5 = Matrix5;
		if self.Matrix5 then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix5", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix5", -1, nil, true)
			end
		end;
end;

function FWKBAnimationScript:matrix6(Matrix6, noEventSend)
	matrix6Event.sendEvent(self, Matrix6, noEventSend)
	self.Matrix6 = Matrix6;
		if self.Matrix6 then
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix6", 1, nil, true)
			end
		else
			for name,_ in pairs(self.spec_animatedVehicle.animations) do
				self:playAnimation("matrix6", -1, nil, true)
			end
		end;
end;

matrix1Event = {};
matrix1Event_mt = Class(matrix1Event, Event);
InitEventClass(matrix1Event, "matrix1Event");

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

matrix2Event = {};
matrix2Event_mt = Class(matrix2Event, Event);
InitEventClass(matrix2Event, "matrix2Event");

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

matrix3Event = {};
matrix3Event_mt = Class(matrix3Event, Event);
InitEventClass(matrix3Event, "matrix3Event");

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

matrix4Event = {};
matrix4Event_mt = Class(matrix4Event, Event);
InitEventClass(matrix4Event, "matrix4Event");

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

matrix5Event = {};
matrix5Event_mt = Class(matrix5Event, Event);
InitEventClass(matrix5Event, "matrix5Event");

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

matrix6Event = {};
matrix6Event_mt = Class(matrix6Event, Event);
InitEventClass(matrix6Event, "matrix6Event");

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