-- Fredzaza --

Godet = {};
Godet.modDirectory = g_currentModDirectory;

function Godet.prerequisitesPresent(specializations)
      return true;
end;
function Godet.initSpecialization()
	local schema = Vehicle.xmlSchema
    schema:setXMLSpecializationType("Godet")
	schema:register(XMLValueType.NODE_INDEX, "vehicle.objet#index", "index")
	schema:register(XMLValueType.NODE_INDEX, "vehicle.godetvisual#index", "index")
end
function Godet.registerOverwrittenFunctions(vehicleType)
end
function Godet.registerFunctions(vehicleType)	
end
function Godet.registerEvents(vehicleType)
end
function Godet:registerActionEventsPlayer()
end
function Godet:registerActionEventsMenu()
end

function Godet:onRegisterActionEvents(isSelected, isOnActiveVehicle)
end

function Godet.registerEventListeners(vehicleType)
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", Godet)
	SpecializationUtil.registerEventListener(vehicleType, "onDelete", Godet)
    SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Godet)
    SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Godet)

	SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Godet)
	SpecializationUtil.registerEventListener(vehicleType, "onPostDetach", Godet)
	SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Godet)
	SpecializationUtil.registerEventListener(vehicleType, "onDraw", Godet)
	SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Godet)
end

function Godet:onLoad(vehicle)	
	self.racine2 = self.xmlFile:getValue("vehicle.objet#index", nil, self.components, self.i3dMappings)
	self.godetvisual = self.xmlFile:getValue("vehicle.godetvisual#index", nil, self.components, self.i3dMappings)
end;

function Godet:onDelete() 
end;

function Godet:onPostDetach()
end

function Godet:onReadStream(streamId, connection)
end;
  
function Godet:onWriteStream(streamId, connection)
end;

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

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

function Godet:onUpdate(dt, vehicle)
	if self.godetvisual == nil then
		return
	end

	local targetParent = self.racine2
	local attacherVehicle = self:getAttacherVehicle()
	if attacherVehicle ~= nil then
		targetParent = attacherVehicle.godetvisualpelle
	end

	if targetParent ~= nil then
		local currentParent = getParent(self.godetvisual)
		if currentParent ~= targetParent then
			unlink(self.godetvisual)
			link(targetParent, self.godetvisual)
		end
	end
end;

function Godet:onUpdateTick() 
end;	
function Godet:onDeactivate()
	if self.godetvisual ~= nil and self.racine2 ~= nil then
		unlink(self.godetvisual)
		link(self.racine2, self.godetvisual)
	end
end;       
function Godet:onDraw()  
end;
