Ejemplo n.º 1
0
		test('works as expected', function () {
			var res = [];
			var l = new Location({players: [
				dummyPlayer('P1', res),
				dummyPlayer('P2', res),
				dummyPlayer('P3', res),
			]}, new Geo());
			l.players.P1.location = l;
			l.players.P2.location = l;
			l.players.P3.location = new Location({}, new Geo());  // some other loc
			l.send({});
			assert.deepEqual(res, ['P1', 'P2']);
			assert.sameMembers(Object.keys(l.players), ['P1', 'P2'],
				'P3 silently removed (because it is not actually in l)');
			res.length = 0;  // reset res
			l.send({}, false, ['P1', 'P4']);
			assert.deepEqual(res, ['P2']);
		});
Ejemplo n.º 2
0
		test('does not send changes to wrong player(s)', function () {
			var res = {};
			var p1 = new Player({tsid: 'P1'});
			var p2 = new Player({tsid: 'P2'});
			var mockSend = function (tsid, msg) {
				res[tsid] = msg;
			};
			p1.session = {send: mockSend.bind(null, p1.tsid)};
			p2.session = {send: mockSend.bind(null, p2.tsid)};
			var l = new Location({players: [p1, p2]}, new Geo());
			p1.location = l;
			p2.location = l;
			// simulate queued changes for P1:
			p1.getPropChanges = function () {
				return 'FAKE_PROP_CHANGES';
			};
			l.send({});
			assert.deepEqual(res.P1, {changes: {stat_values: 'FAKE_PROP_CHANGES'}});
			assert.deepEqual(res.P2, {}, 'changes for P1 not sent to P2');
		});