View difference between Paste ID: PH691yus and 1ztMy1br
SHOW: | | - or go back to the newest paste.
1
//Public/Client JS
2
var socket = null;
3
var identifier = null;
4
$(document).ready(function() {
5
	var currentNum = 0;
6
	function roll(num) {
7
		var numWidth = 1050/15;
8
9
		var layout = [1, 14, 2, 13, 3, 12, 4, 0, 11, 5, 10, 6, 9, 7, 8];
10
11
		function getMoves() {
12
			let to = layout.indexOf(num);
13
			let at = layout.indexOf(currentNum);
14
15
			if(to > at)
16
			{return (to - at);}
17
			else
18
			{return (layout.length - at + to);}
19
		}
20
21
		var currentPos = parseInt($('#case').css( "background-position" ).split(" ")[0].slice(0, -2));
22
		currentPos ? null : currentPos = 0;
23
		$('#case').animate({
24
			"background-position": currentPos-2100-(getMoves()*numWidth),
25
		}, 3000);
26
		currentNum = num;
27
		setTimeout(function() {
28
			if($("#past .ball").length >= 10)
29
			{
30
            $("#past .ball").first().remove();
31
			}
32
            if (num == 0) 
33
			{
34
				$(".ball").last().after("<div class='ball ball-0'>" + num + "</div>");
35
            } 
36
			else if (num <= 7) 
37
			{;
38
				 $(".ball").last().after("<div class='ball ball-1'>" + num + "</div>");
39
            } 
40
			else 
41
			{
42
			   $(".ball").last().after("<div class='ball ball-8'>" + num + "</div>");
43
            }
44
			$.each($('.list-group-item'), function (index, value) { 
45
				$(this).remove();
46
			});
47
        }, 3000);
48
	}
49
	
50
	identifier = $('meta[name="identifier"]').attr('content');
51
	if(!socket) 
52
	{
53
		if(!identifier)
54
		{
55
			console.log("User not logged in.");
56
		}
57
		else
58
		{
59
			socket = io("localhost:8000");
60
			socket.on('connect', function(msg) {
61
				console.log("Connected!");
62
				socket.emit('authenticate', identifier);
63
			});
64
		}
65
	}
66
	else
67
	{
68
		console.log("Connection already exists.");
69
	}
70
	socket.on('roll', function(rolledNumber)
71
	{
72
		roll(rolledNumber);
73
		//$('#banner').html(timer + '<span style="font-size:17px">S</span>')
74
	});
75
	socket.on('updateTime', function(timer)
76
	{
77
		$(".timer").width((timer/20)*100+"%");
78
		//$('#banner').html(timer + '<span style="font-size:17px">S</span>')
79
	});
80
	socket.on('users', function(num)
81
	{
82
		$('.users-online').html(num);
83
	});
84
});