<commit_before>// Definition of Player object.
var Player = function() {
	this.id 		= null;
	this.position 	= null;
	this.team 		= null;
	this.alive		= null;
	this.clock		= null;
	this.turret_direction = 0;
	this.hull_direction = null;
	this.received_damage = false;
}

Player.prototype = {

}

// Definition of Model object
var Model = function(game, map_boundaries) {
	this.players 		= {};
	this.clock			= 0;
	this.game			= game;
	this.map_boundaries = map_boundaries;
}

Model.prototype = {
	getPlayer: function(id) {
		var player = this.players[id];
		if (typeof(player) == 'undefined') {
			player = new Player();
			player.id = id;
			player.alive = true;
			this.players[id] = player;
		}
		return player;
	},
	update: function(frame) {
		// update clock
		if (typeof(frame.clock) == 'undefined') {
			return;
		}

		if (frame.clock != null) {
			this.clock = frame.clock;
		}

		// we are only interested in the packet if it has a clock / player / team values
		if (typeof(frame.position) != 'undefined' 
				&& typeof(frame.player_id) != 'undefined') {
			var player = this.getPlayer(frame.player_id);
			player.position = frame.position;
			player.turret_direction += frame.hull_orientation[1] * 0.34 / 2;
			player.hull_direction = frame.hull_orientation[0];
			player.team 	= frame.team;
			player.clock	= this.clock;
		}

		if (typeof(frame.source) != 'undefined'
				&& typeof(frame.health) != 'undefined') {
			var player = this.getPlayer(frame.player_id);
			player.received_damage = true;
			player.clock = this.clock;
			var vehicles = this.game.vehicles;
			console.log(vehicles[frame.source].name + " (" + vehicles[frame.source].vehicleType + ") hit " 
				+ vehicles[player.id].name + " (" + vehicles[player.id].vehicleType + ")" );
		}

		if (typeof(frame.target) != 'undefined'
				&& typeof(frame.destroyed_by) != 'undefined') {
			var player 	 = this.getPlayer(frame.target);
			player.alive = false;
			player.clock = this.clock;
		}
	}
}

var Viewer = function(target, serviceUrl) {
	this.target = target;
	this.serviceUrl = serviceUrl;
	this.model = null;

	// configure the target element as a replay viewer
	target.classList.add('replay-viewer');

	this.map = document.createElement('img');
	this.map.classList.add('map');
	this.map.width = this.map.height = 500
	this.target.appendChild(this.map);

	this.overlay = document.createElement('canvas');
	this.overlay.classList.add('overlay');
	this.overlay.width = this.overlay .height = 500;
	this.target.appendChild(this.overlay);

	this.link = document.createElement('a');
	this.link.classList.add('permalink');
	this.link.innerText = "PERMALINK";
	this.link.style.display = "none";
	this.target.appendChild(this.link);
}

Viewer.prototype = {
	replay: function(data) {
		var ctx = this.overlay.getContext("2d");
		this.model = new Model(data.summary, data.map_boundaries);

		var update = function(model, packets, window_start, window_size, start_ix) {
			// model of the viewer change -> stop
			if (this.model != model) {
				return;
			}

			var window_end = window_start + window_size, ix;
			for (ix = start_ix; ix < packets.length; ix++) {
				var packet = packets[ix];

				if (typeof(packet.clock) == 'undefined') {
					continue;
				}

				// escape when outside of window size
				if (packet.clock > window_end) {
					break;
				}

				// update model with packet
				model.update(packet);
			}

			this.show(data, ctx);
			
			if (ix < packets.length) {
				setTimeout(update.bind(this, model, packets, window_end, window_size, ix), 100);	
			}
		}

		update.call(this, this.model, data.packets, 0, 0.2, 0);
	},
	show: function(data, ctx) {
		// reset overlay
		ctx.clearRect(0, 0, 500, 500);

		ctx.fillStyle = "#FFFF00";
		ctx.textBaseline = "top";
		ctx.font = "bold 20px sans-serif";
		ctx.fillText(String(this.model.clock.toFixed(2)), 8, 5);

		for (var player_id in this.model.players) {
			var player = this.model.players[player_id];
			if (typeof(player.team) == undefined
					|| player.position == null
					|| [0,1].indexOf(player.team) < 0) {
				continue;
			}

			var coord = to_2d_coord(player.position, this.model.map_boundaries, 500, 500);
			
			var colors = [
				[0, 255, 0],
				[255, 0, 0]
			];

			var recorder_color = [0, 0, 255];

			ctx.lineWidth = 2;
			var color = player.id == data.recorder_id ?  recorder_color : colors[player.team];

			if (player.received_damage) {
				color = [255, 255, 255];
				player.received_damage = false;
			}

			var age   = player.alive ? ((this.model.clock - player.clock) / 20) : 0;<commit_msg>Fix team coloring of tanks<commit_after>// Definition of Player object.
var Player = function() {
	this.id 		= null;
	this.position 	= null;
	this.team 		= null;
	this.alive		= null;
	this.clock		= null;
	this.turret_direction = 0;
	this.hull_direction = null;
	this.received_damage = false;
}

Player.prototype = {

}

// Definition of Model object
var Model = function(game, map_boundaries) {
	this.players 		= {};
	this.clock			= 0;
	this.game			= game;
	this.map_boundaries = map_boundaries;
}

Model.prototype = {
	getPlayer: function(id) {
		var player = this.players[id];
		if (typeof(player) == 'undefined') {
			player = new Player();
			player.id = id;
			player.alive = true;
			this.players[id] = player;
		}
		return player;
	},
	update: function(frame) {
		// update clock
		if (typeof(frame.clock) == 'undefined') {
			return;
		}

		if (frame.clock != null) {
			this.clock = frame.clock;
		}

		// we are only interested in the packet if it has a clock / player / team values
		if (typeof(frame.position) != 'undefined' 
				&& typeof(frame.player_id) != 'undefined') {
			var player = this.getPlayer(frame.player_id);
			player.position = frame.position;
			player.turret_direction += frame.hull_orientation[1] * 0.34 / 2;
			player.hull_direction = frame.hull_orientation[0];
			player.team 	= frame.team;
			player.clock	= this.clock;
		}

		if (typeof(frame.source) != 'undefined'
				&& typeof(frame.health) != 'undefined') {
			var player = this.getPlayer(frame.player_id);
			player.received_damage = true;
			player.clock = this.clock;
			var vehicles = this.game.vehicles;
			console.log(vehicles[frame.source].name + " (" + vehicles[frame.source].vehicleType + ") hit " 
				+ vehicles[player.id].name + " (" + vehicles[player.id].vehicleType + ")" );
		}

		if (typeof(frame.target) != 'undefined'
				&& typeof(frame.destroyed_by) != 'undefined') {
			var player 	 = this.getPlayer(frame.target);
			player.alive = false;
			player.clock = this.clock;
		}
	}
}

var Viewer = function(target, serviceUrl) {
	this.target = target;
	this.serviceUrl = serviceUrl;
	this.model = null;

	// configure the target element as a replay viewer
	target.classList.add('replay-viewer');

	this.map = document.createElement('img');
	this.map.classList.add('map');
	this.map.width = this.map.height = 500
	this.target.appendChild(this.map);

	this.overlay = document.createElement('canvas');
	this.overlay.classList.add('overlay');
	this.overlay.width = this.overlay .height = 500;
	this.target.appendChild(this.overlay);

	this.link = document.createElement('a');
	this.link.classList.add('permalink');
	this.link.innerText = "PERMALINK";
	this.link.style.display = "none";
	this.target.appendChild(this.link);

	this.recorder_team  = null;
}

Viewer.prototype = {
	replay: function(data) {
		var ctx = this.overlay.getContext("2d");
		this.model = new Model(data.summary, data.map_boundaries);
		this.recorder_team = data.summary.vehicles[data.recorder_id].team - 1;
		var update = function(model, packets, window_start, window_size, start_ix) {
			// model of the viewer change -> stop
			if (this.model != model) {
				return;
			}

			var window_end = window_start + window_size, ix;
			for (ix = start_ix; ix < packets.length; ix++) {
				var packet = packets[ix];

				if (typeof(packet.clock) == 'undefined') {
					continue;
				}

				// escape when outside of window size
				if (packet.clock > window_end) {
					break;
				}

				// update model with packet
				model.update(packet);
			}

			this.show(data, ctx);
			
			if (ix < packets.length) {
				setTimeout(update.bind(this, model, packets, window_end, window_size, ix), 100);	
			}
		}

		update.call(this, this.model, data.packets, 0, 0.2, 0);
	},
	show: function(data, ctx) {
		// reset overlay
		ctx.clearRect(0, 0, 500, 500);

		ctx.fillStyle = "#FFFF00";
		ctx.textBaseline = "top";
		ctx.font = "bold 20px sans-serif";
		ctx.fillText(String(this.model.clock.toFixed(2)), 8, 5);

		for (var player_id in this.model.players) {
			var player = this.model.players[player_id];
			if (typeof(player.team) == undefined
					|| player.position == null
					|| [0,1].indexOf(player.team) < 0) {
				continue;
			}

			var coord = to_2d_coord(player.position, this.model.map_boundaries, 500, 500);
			
			var colors = [
				[0, 255, 0],
				[255, 0, 0]
			];

			var recorder_color = [0, 0, 255];

			ctx.lineWidth = 2;
			var color = player.id == data.recorder_id ?  recorder_color : colors[player.team ^ this.recorder_team];

			if (player.received_damage) {
				color = [255, 255, 255];
				player.received_damage = false;
			}

			var age   = player.alive ? ((this.model.clock - player.clock) / 20) : 0;
{'fraction_non_alphanumeric': 0.1518726997185538, 'fraction_numerical': 0.01634552933535397, 'mean_word_length': 3.303213786679087, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7521047', 'n_tokens_mistral': 3786, 'n_tokens_neox': 3195, 'n_words': 685}