<commit_before>/*jshint node:true jquery:true*/
"use strict";

module.exports = function(output) {
	var robot = require('../robot');
	var clayer = require('../clayer');
	var blockSize = 64;

	output.Robot = function() { return this.init.apply(this, arguments); };
	output.Robot.prototype = {
		init: function($div, editor, readOnly, columns, rows) {
			this.$div = $div;
			this.$div.addClass('output robot');
			this.readOnly = readOnly || false;

			this.$container = $('<div class="robot-not-highlighting"></div>');
			this.$container.on('mouseup', $.proxy(this.containerMouseUp, this));
			this.$container.on('mouseleave', $.proxy(this.containerMouseLeave, this));
			this.$div.append(this.$container);
			this.robot = new robot.Robot(this.$container, this.readOnly, blockSize, columns || 8, rows || 8);

			this.callNr = Infinity;
			this.highlighting = false;
			this.animation = null;
			this.stateChangedCallback = null;
			this.calls = [];

			if (!this.readOnly) {
				this.robot.$initial.on('mousedown', $.proxy(this.initialMouseDown, this));
				this.robot.$initial.on('mouseup', $.proxy(this.initialMouseUp, this));
				this.updateInterface();
			}

			this.editor = editor;
			this.editor.addOutput(this);
		},

		remove: function() {
			this.robot.remove();
			this.$div.removeClass('output robot');
			this.editor.removeOutput(this);
		},

		drive: function(context, name, args) {
			var amount = 1;
			if (args[0] !== undefined) {
				amount = args[0];
			}

			if (args.length > 1) {
				throw '<var>forward</var> accepts no more than <var>1</var> argument';
			} else if (typeof amount !== 'number' || !isFinite(amount)) {
				throw 'Argument has to be a valid number';
			} else if (Math.round(amount) !== amount && this.robot.mazeObjects > 0) {
				throw 'Fractional amounts are only allowed when the maze is empty';
			} else if (amount !== 0) {
				try {
					this.robot.drive(amount);
				} catch (error) {
					this.addCall(context);
					throw error;
				}
				this.addCall(context);
			}
		},

		turn: function(context, name, args) {
			var amount = 90;
			if (args[0] !== undefined) {
				amount = args[0];
			}

			if (args.length > 1) {
				throw '<var>' + name + '</var> accepts no more than <var>1</var> argument';
			} else if (typeof amount !== 'number' || !isFinite(amount)) {
				throw 'Argument has to be a valid number';
			} else if ([0, 90, 180, 270].indexOf((amount%360+360)%360) < 0 && this.robot.mazeObjects > 0) {
				throw 'Only <var>90</var>, <var>180</var> and <var>270</var> degrees are allowed when the maze is not empty';
			} else {
				this.robot[name](amount);
				this.addCall(context);
			}
		},

		detectWall: function(context, name, args) {
			var wall = this.robot.detectWall();
			this.addCall(context);
			return wall;
		},

		detectGoal: function(node, name, args) {
			return this.robot.detectGoal();
		},
		
		getAugmentedObject: function() {
			return {
				drive: {
					name: 'drive',
					type: 'function',
					example: 'drive(3)',
					func: $.proxy(this.drive, this)
				},
				turnLeft: {
					name: 'turnLeft',
					type: 'function',
					example: 'turnLeft()',
					func: $.proxy(this.turn, this)
				},
				turnRight: {
					name: 'turnRight',
					type: 'function',
					example: 'turnRight()',
					func: $.proxy(this.turn, this)
				},
				detectWall: {
					name: 'detectWall',
					type: 'function',
					example: 'detectWall()',
					func: $.proxy(this.detectWall, this)
				},
				detectGoal: {
					name: 'detectGoal',
					type: 'function',
					example: 'detectGoal()',
					func: $.proxy(this.detectGoal, this)
				}
			};
		},

		enableHighlighting: function() {
			this.highlighting = true;
			this.$container.removeClass('robot-not-highlighting');
			this.$container.addClass('robot-highlighting');
		},

		disableHighlighting: function() {<commit_msg>Small fix<commit_after>/*jshint node:true jquery:true*/
"use strict";

module.exports = function(output) {
	var robot = require('../robot');
	var clayer = require('../clayer');
	var blockSize = 64;

	output.Robot = function() { return this.init.apply(this, arguments); };
	output.Robot.prototype = {
		init: function($div, editor, readOnly, columns, rows) {
			this.$div = $div;
			this.$div.addClass('output robot');
			this.readOnly = readOnly || false;

			this.$container = $('<div class="robot-not-highlighting"></div>');
			this.$container.on('mouseup', $.proxy(this.containerMouseUp, this));
			this.$container.on('mouseleave', $.proxy(this.containerMouseLeave, this));
			this.$div.append(this.$container);
			this.robot = new robot.Robot(this.$container, this.readOnly, blockSize, columns || 8, rows || 8);

			this.callNr = Infinity;
			this.highlighting = false;
			this.animation = null;
			this.stateChangedCallback = null;
			this.calls = [];

			if (!this.readOnly) {
				this.robot.$initial.on('mousedown', $.proxy(this.initialMouseDown, this));
				this.robot.$initial.on('mouseup', $.proxy(this.initialMouseUp, this));
				this.updateInterface();
			}

			this.editor = editor;
			this.editor.addOutput(this);
		},

		remove: function() {
			this.robot.remove();
			this.$div.removeClass('output robot');
			this.editor.removeOutput(this);
		},

		drive: function(context, name, args) {
			var amount = 1;
			if (args[0] !== undefined) {
				amount = args[0];
			}

			if (args.length > 1) {
				throw '<var>forward</var> accepts no more than <var>1</var> argument';
			} else if (typeof amount !== 'number' || !isFinite(amount)) {
				throw 'Argument has to be a valid number';
			} else if (Math.round(amount) !== amount && this.robot.mazeObjects > 0) {
				throw 'Fractional amounts are only allowed when the maze is empty';
			} else if (amount !== 0) {
				try {
					this.robot.drive(amount);
				} catch (error) {
					this.addCall(context);
					throw error;
				}
				this.addCall(context);
			}
		},

		turn: function(context, name, args) {
			var amount = 90;
			if (args[0] !== undefined) {
				amount = args[0];
			}

			if (args.length > 1) {
				throw '<var>' + name + '</var> accepts no more than <var>1</var> argument';
			} else if (typeof amount !== 'number' || !isFinite(amount)) {
				throw 'Argument has to be a valid number';
			} else if ([0, 90, 180, 270].indexOf((amount%360+360)%360) < 0 && this.robot.mazeObjects > 0) {
				throw 'Only <var>90</var>, <var>180</var> and <var>270</var> degrees are allowed when the maze is not empty';
			} else {
				this.robot[name](amount);
				this.addCall(context);
			}
		},

		detectWall: function(context, name, args) {
			var wall = this.robot.detectWall();
			this.addCall(context);
			return wall;
		},

		detectGoal: function(node, name, args) {
			return this.robot.detectGoal();
		},
		
		getAugmentedObject: function() {
			return {
				drive: {
					name: 'drive',
					info: 'robot.drive',
					type: 'function',
					example: 'drive(3)',
					func: $.proxy(this.drive, this)
				},
				turnLeft: {
					name: 'turnLeft',
					info: 'robot.turnLeft',
					type: 'function',
					example: 'turnLeft()',
					func: $.proxy(this.turn, this)
				},
				turnRight: {
					name: 'turnRight',
					info: 'robot.turnRight',
					type: 'function',
					example: 'turnRight()',
					func: $.proxy(this.turn, this)
				},
				detectWall: {
					name: 'detectWall',
					info: 'robot.detectWall',
					type: 'function',
					example: 'detectWall()',
					func: $.proxy(this.detectWall, this)
				},
				detectGoal: {
					name: 'detectGoal',
					info: 'robot.detectGoal',
					type: 'function',
					example: 'detectGoal()',
					func: $.proxy(this.detectGoal, this)
				}
			};
		},

		enableHighlighting: function() {
			this.highlighting = true;
			this.$container.removeClass('robot-not-highlighting');
			this.$container.addClass('robot-highlighting');
		},

		disableHighlighting: function() {
{'fraction_non_alphanumeric': 0.17346286590821935, 'fraction_numerical': 0.011760194298862329, 'mean_word_length': 3.188436830835118, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1840154', 'n_tokens_mistral': 3293, 'n_tokens_neox': 2594, 'n_words': 591}