Skip to content

Commit

Permalink
NEXT-63 Correct map border
Browse files Browse the repository at this point in the history
  • Loading branch information
xzfc committed Mar 20, 2016
1 parent d6d08dc commit 456d74e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions client/js/map-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MapSize {
centerY() { return (this.minY + this.maxY) / 2; }
width() { return this.maxX - this.minX; }
height() { return this.maxY - this.minY; }
isLegit() { return this.width() >= 6000 && this.height() >= 3400; }
static default() {
const dim = -1000;
return new MapSize(-dim, dim, -dim, dim);
Expand Down
22 changes: 14 additions & 8 deletions client/js/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ class Viewer extends EventEmitter {
this.addRenderer();
this.addStats();
this.mapSize = MapSize.default();
client.once('mapSizeLoad', (minX, minY, maxX, maxY) => {
this.mapSize = new MapSize(minX, minY, maxX, maxY);
this.gameWidth = maxX;
this.gameHeight = maxY;
client.once('connected', () => {
this.zoom = 0;
this.initStage();
this.addListners();
this.addBorders();
this.animate();
this.homeview = true;
client.once('myNewBall', () => this.homeview = false);
this.emit('launched');
});
client.on('mapSizeLoad', (minX, minY, maxX, maxY) => {
const mapSize = new MapSize(minX, minY, maxX, maxY);
if (mapSize.isLegit()) {
this.mapSize = mapSize;
this.updateBorders();
}
});
window.addEventListener('resize', () => this.updateSize());
window.addEventListener('wheel', e => this.modifyZoom(e.deltaY));
}
Expand Down Expand Up @@ -86,12 +89,15 @@ class Viewer extends EventEmitter {
this.client.on('ballDestroy', id => delete this.client.balls[id]);
}

addBorders() {
this.borders = new PIXI.Graphics();
updateBorders() {
if (!this.borders) {
this.borders = new PIXI.Graphics();
this.stage.addChild(this.borders);
}
this.borders.clear();
this.borders.lineStyle(5, 0xFF3300, 1);
const s = this.mapSize;
this.borders.drawRect(s.minX, s.minY, s.width(), s.height());
this.stage.addChild(this.borders);
}

addStats() {
Expand Down
17 changes: 17 additions & 0 deletions test/map-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ describe('MapSize', function () {
expect(new MapSize(-10, -20, 30, 50).height()).to.be.equal(70);
});

describe('.isLegit()', function () {
it('should be true on full world size', function () {
expect(new MapSize(-6796.050310292858,
-9203.937550139428,
+7346.085313438094,
+4938.198073591524).isLegit())
.to.be.true;
});
it('should be false on partial world size', function () {
expect(new MapSize(-3517.222111139978,
+1457.9073725840553,
+2242.777888860022,
+4697.907372584055).isLegit())
.to.be.false;
});
});

it('should have default() constructor', function () {
expect(MapSize.default()).to.be.an.instanceof(MapSize);
});
Expand Down

0 comments on commit 456d74e

Please sign in to comment.