package v6.apps.zelvak;

import java.util.List;

class RotationFunction extends FixedArgumentsParsingFunction{

	private final int direction;
	
	RotationFunction(int direction){
		super(1);
		this.direction = direction;
	}
	
	@Override
	protected Command applyCheckedArguments(List<Object> arguments) throws WTFException {
		if(! (arguments.get(0) instanceof Double)){
			throw new WTFException("Unexpected argument type.");
		}
		final double arg = ((Double)arguments.get(0)).doubleValue();
		return new Command() {
			@Override
			public void execute(RunningContext context) throws RunningException {
				context.setAngle(context.getAngle() + direction*arg*(Math.PI/180));
			}
		};
	}
	
}
