Ver Código Fonte

send and receive arrays of pixls.

preparation for possible batching later.
Lucas Stadler 12 anos atrás
pai
commit
d03cc45643
2 arquivos alterados com 6 adições e 5 exclusões
  1. 1 1
      js/pixl/index.html
  2. 5 4
      js/pixl/server.js

+ 1 - 1
js/pixl/index.html

@ -53,7 +53,7 @@
53 53
			pixl.ctx.fillRect(screen_pos.x, screen_pos.y, pixl.size, pixl.size);
54 54
			pixl.world[pos.x + "," + pos.y] = {};
55 55
			if (pixl.online) {
56
				pixl.ws.send(JSON.stringify({x: pos.x, y: pos.y, color: color || "black"}));
56
				pixl.ws.send(JSON.stringify([{x: pos.x, y: pos.y, color: color || "black"}]));
57 57
			}
58 58
		}
59 59

+ 5 - 4
js/pixl/server.js

@ -8,10 +8,11 @@ server.on('connection', function(socket) {
8 8
	socket.send(JSON.stringify(world));
9 9
10 10
	socket.on('message', function(msg) {
11
		var pixl = JSON.parse(msg);
12
		world[pixl.x + "," + pixl.y] = {color: pixl.color};
13
14
		console.log(pixl);
11
		var pixls = JSON.parse(msg);
12
		pixls.forEach(function(pixl) {
13
			world[pixl.x + "," + pixl.y] = {color: pixl.color};
14
			console.log(pixl);
15
		});
15 16
16 17
		server.clients.forEach(function(client) {
17 18
			if (socket != client) {