--kompass
--by Bullgore


kompass = {};

function kompass.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function kompass:load(xmlFile)

    self.pipeLight = nil
    if self.pipeLight ~= nil then
	setVisibility(self.pipeLight, false);
    end;
    self.pipeLightActive = false;
    self.balcamera = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.balcamera#index"));
    self.jobbcamera = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.jobbcamera#index"));
    end;	

function kompass:delete()

end;

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

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

function kompass:update(dt)

	if self.isEntered then

		if self.camIndex == 2 then

    				--Kompass
	local x,y,z = localDirectionToWorld(self.rootNode, 0, 0, 1);
	local length = Utils.vector2Length(x,z);
	local dX = x/length;
	local dZ = z/length;
	local Richtung = math.deg(math.atan2(dX,dZ));
	if Richtung < 0  then 
		Richtung = 360 - (Richtung * -1);
    end;
	renderText(0.49,0.95,0.03,string.format("%3.0f ",360 - math.floor(Richtung + 0.5) ));
	
	
   		
		end;
	
        	if Input.isKeyPressed(Input.KEY_shift) and self.camIndex == 2 then
                	setCamera(self.balcamera);
       		end;
        	if Input.isKeyPressed(60) and self.camIndex == 2 then
                	setCamera(self.jobbcamera);
       		end;
        	if self.pipeLight ~= nil then
            		if self.pipeLightActive then
            			setVisibility(self.pipeLight, self.pipeLightActive);
	    		else
            			setVisibility(self.pipeLight, self.pipeLightActive);
	    		end;
        	end;
		if self.numAttachedCutters == 0 then
			self.lepcsoMax = true;
		else
    			self.lepcsoMax = false;
		end;

	end;	

end;

function kompass:draw()  
end;

function kompass:onEnter()

    self.lepcsoMax = true;

end;

function kompass:onLeave()

    if self.pipeLight ~= nil then
    	setVisibility(self.pipeLight, false);
    end;
	
end;

