-- 
-- by Jukka
-- 

panonija = {};

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

function panonija:load(xmlFile)
	_=[[
    local i=0;
    while true do
        local baseName = string.format("vehicle.attacherJoints.attacherJoint(%d)", i);
        local index = getXMLString(xmlFile, baseName.. "#index");
        if index == nil then
            break;
        end;	

		local jointTypeStr = getXMLString(xmlFile, baseName .. "#jointType");
		if jointTypeStr ~= nil then
			local jointType = Vehicle.jointTypeNameToInt[jointTypeStr];
			
			if jointType == nil then
				Vehicle.registerJointType(jointTypeStr);
				print("register Jointtype: " .. jointTypeStr);
				jointType = Vehicle.jointTypeNameToInt[jointTypeStr];
			end;
			
			if jointType ~= nil then
				self.attacherJoints[i+1].jointType = jointType;				
			end;
		end;
		i = i + 1;
	end;	]]	
	

	local jointTypeStr = getXMLString(xmlFile,"vehicle.attacherJoints.attacherJoint#jointType");
	if jointTypeStr ~= nil then
		local jointType = Vehicle.jointTypeNameToInt[jointTypeStr];
		
		if jointType == nil then
			Vehicle.registerJointType(jointTypeStr);
			print("register Jointtype: " .. jointTypeStr);
			jointType = Vehicle.jointTypeNameToInt[jointTypeStr];
		end;
		
		if jointType ~= nil then
			self.attacherJoints[1].jointType = jointType;				
		end;
	end;

	self.attacherVehicleCopy = nil;
	
end;

function panonija:delete()
end;

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

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

function panonija:update(dt)	
end;

function panonija:draw()
end;

function panonija:onAttach(attacherVehicle)
	self.attacherVehicleCopy = attacherVehicle;
    for k,v in pairs(self.attachedImplements) do	
		if v.object.onForkLiftAttach ~= nil then
            v.object:onForkLiftAttach(attacherVehicle);
		end;
    end;
end;

function panonija:onDetach()
	self.attacherVehicleCopy = nil;
    for k,v in pairs(self.attachedImplements) do
		if v.object.onForkLiftDetach ~= nil then
            v.object:onForkLiftDetach(attacherVehicle);
		end;
    end;
end;

function panonija:validateAttacherJoint(implement, jointDesc, dt)
    return true;
end;