@luceosports/play-rendering 1.10.2 → 1.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@luceosports/play-rendering",
3
- "version": "1.10.2",
3
+ "version": "1.10.5",
4
4
  "description": "",
5
5
  "main": "dist/play-rendering.js",
6
6
  "scripts": {
7
7
  "build": "webpack",
8
+ "build:dev": "webpack --mode=development",
8
9
  "lint": "npx eslint . --ext .js",
9
10
  "lint:fix": "npx eslint . --ext .js --fix",
10
11
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -3,9 +3,9 @@
3
3
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
4
  <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
5
  width="978px" height="952px" viewBox="0 0 978 952" enable-background="new 0 0 978 952" xml:space="preserve">
6
- <path d="M520.289,1.967c-1.615,4.413-14.747,7.465-31.096,7.465c-16.88,0-30.314-4.884-31.217-8.822l-76.571,214.588h-0.018
6
+ <path fill="#f36f21" d="M520.289,1.967c-1.615,4.413-14.747,7.465-31.096,7.465c-16.88,0-30.314-4.884-31.217-8.822l-76.571,214.588h-0.018
7
7
  c0.037,17,48.295,30.526,107.535,30.526c59.236,0,107.535-13.084,107.535-29.72v-0.005L520.289,1.967z"/>
8
- <path d="M897.207,691.268l-148.072-45.49l34.283,96.421h-0.003c-0.099,46-131.985,82.708-294.66,82.708
8
+ <path fill="#f36f21" d="M897.207,691.268l-148.072-45.49l34.283,96.421h-0.003c-0.099,46-131.985,82.708-294.66,82.708
9
9
  c-162.679,0-294.562-36.708-294.663-82.708h0.055l34.278-96.406L80.652,691.284C-6.557,718.129-27.55,764.646,41.001,795.37
10
10
  l282.491,126.619c89.181,39.971,241.994,40.025,331.121,0.096l282.621-126.606C1005.879,764.728,984.701,718.146,897.207,691.268z"
11
11
  />
@@ -16,7 +16,7 @@
16
16
  <path fill="#FFFFFF" d="M457.995,0.666l0.002-0.056l-0.011,0.03C457.988,0.649,457.992,0.658,457.995,0.666z"/>
17
17
  </g>
18
18
  <g>
19
- <path d="M655.997,381.461c-4.879,11.841-21.986,22.058-50.218,29.847c-31.25,8.622-72.838,13.37-117.103,13.37
19
+ <path fill="#f36f21" d="M655.997,381.461c-4.879,11.841-21.986,22.058-50.218,29.847c-31.25,8.622-72.838,13.37-117.103,13.37
20
20
  c-44.28,0-85.87-4.857-117.109-13.678c-27.324-7.715-44.232-17.743-49.711-29.335l-69.411,194.533h-0.043
21
21
  c0.08,35,106.409,66.121,236.528,66.121c130.117,0,236.528-29.668,236.528-66.207v-0.012L655.997,381.461z"/>
22
22
  </g>
@@ -1,5 +1,7 @@
1
1
  const InternalBaseLayer = require('../../base/InternalBaseLayer');
2
2
 
3
+ const DEBUG_WRAP_POINTS = false;
4
+
3
5
  class InternalShapeLayer extends InternalBaseLayer {
4
6
  constructor(parentLayer, shape) {
5
7
  super(parentLayer);
@@ -15,6 +17,7 @@ class InternalShapeLayer extends InternalBaseLayer {
15
17
  drawLogic() {
16
18
  this.setColor();
17
19
  this.drawShape();
20
+ this.drawShapeWrapPoints();
18
21
  }
19
22
 
20
23
  setColor() {
@@ -29,6 +32,19 @@ class InternalShapeLayer extends InternalBaseLayer {
29
32
  this.ctx.strokeStyle = `rgba(${r}, ${g}, ${b}, ${alpha})`;
30
33
  }
31
34
 
35
+ drawShapeWrapPoints() {
36
+ if (!DEBUG_WRAP_POINTS) return;
37
+
38
+ const { rectWrapPoints } = this.shape;
39
+
40
+ rectWrapPoints.forEach(point => {
41
+ this.ctx.beginPath();
42
+ this.ctx.arc(point.x, point.y, 0.5, 0, Math.PI * 2);
43
+ this.ctx.stroke();
44
+ this.ctx.fill();
45
+ });
46
+ }
47
+
32
48
  drawShape() {
33
49
  // Override this function in a subclass
34
50
  }
@@ -1,15 +1,13 @@
1
1
  const InternalShapeLayer = require('../base/InternalShapeLayer');
2
2
 
3
- const CIRCLE_SHAPE_RADIUS = 5;
4
-
5
3
  class CircleShapeLayer extends InternalShapeLayer {
6
4
  drawShape() {
7
- const { location, scale } = this.shape;
5
+ const { location, scale, outerCircleRadius } = this.shape;
8
6
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH;
9
7
  this.ctx.translate(location.x, location.y);
10
8
  this.ctx.scale(scale.x, scale.y);
11
9
  this.ctx.beginPath();
12
- this.ctx.arc(0, 0, CIRCLE_SHAPE_RADIUS, 0, Math.PI * 2);
10
+ this.ctx.arc(0, 0, outerCircleRadius, 0, Math.PI * 2);
13
11
  this.ctx.stroke();
14
12
  this.ctx.fill();
15
13
  }
@@ -1,17 +1,22 @@
1
1
  const InternalShapeLayer = require('../base/InternalShapeLayer');
2
2
 
3
- const SHAPE_SIZE = 5;
4
-
5
3
  class ConeShapeLayer extends InternalShapeLayer {
6
4
  drawShape() {
7
- const { location, scale } = this.shape;
8
- this.ctx.translate(location.x - SHAPE_SIZE / 2, location.y - SHAPE_SIZE / 2);
5
+ const { location, scale, outerCircleRadius } = this.shape;
6
+ this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH;
7
+ this.ctx.translate(location.x, location.y);
9
8
  this.ctx.scale(scale.x, scale.y);
10
9
 
11
10
  if (this.staticData.shapes && this.staticData.shapes.length) {
12
11
  const coneShape = this.staticData.shapes.find(shape => shape.key === 'cone');
13
12
  if (coneShape) {
14
- this.ctx.drawImage(coneShape.image, 0, 0, SHAPE_SIZE, SHAPE_SIZE);
13
+ this.ctx.drawImage(
14
+ coneShape.image,
15
+ -outerCircleRadius / 2,
16
+ -outerCircleRadius / 2,
17
+ outerCircleRadius,
18
+ outerCircleRadius
19
+ );
15
20
  }
16
21
  }
17
22
  }
@@ -1,16 +1,14 @@
1
1
  const InternalShapeLayer = require('../base/InternalShapeLayer');
2
2
 
3
- const SQUARE_SIDE_LENGTH = 10;
4
-
5
3
  class SquareShapeLayer extends InternalShapeLayer {
6
4
  drawShape() {
7
- const { location, scale } = this.shape;
5
+ const { location, scale, outerCircleRadius } = this.shape;
8
6
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH;
9
7
  this.ctx.translate(location.x, location.y);
10
8
  this.ctx.scale(scale.x, scale.y);
11
9
 
12
10
  this.ctx.beginPath();
13
- this.ctx.rect(-SQUARE_SIDE_LENGTH / 2, -SQUARE_SIDE_LENGTH / 2, SQUARE_SIDE_LENGTH, SQUARE_SIDE_LENGTH);
11
+ this.ctx.rect(-outerCircleRadius / 2, -outerCircleRadius / 2, outerCircleRadius, outerCircleRadius);
14
12
 
15
13
  this.ctx.stroke();
16
14
  this.ctx.fill();
@@ -1,16 +1,8 @@
1
- const { sin, cos } = require('mathjs');
2
1
  const InternalShapeLayer = require('../base/InternalShapeLayer');
3
2
 
4
- const OUTER_RADIUS = 10;
5
-
6
3
  class TriangleShapeLayer extends InternalShapeLayer {
7
4
  drawShape() {
8
- const { location, scale } = this.shape;
9
- const triangle = [
10
- { x: 0, y: -OUTER_RADIUS },
11
- { x: OUTER_RADIUS * cos(210), y: OUTER_RADIUS * sin(210) },
12
- { x: -OUTER_RADIUS * cos(210), y: OUTER_RADIUS * sin(210) }
13
- ];
5
+ const { location, scale, shapeControlPoints: triangle } = this.shape;
14
6
 
15
7
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH;
16
8
  this.ctx.translate(location.x, location.y);
@@ -9,6 +9,7 @@ const ShapeLayer = require('../layers/ShapeLayer');
9
9
  const LineControlPointLayer = require('../layers/LineControlPointLayer');
10
10
  const Line = require('./Line');
11
11
  const Player = require('./Player');
12
+ const ShapeModels = require('./ShapeModels');
12
13
 
13
14
  class Frame {
14
15
  constructor(play, phase = 1, animationGlobalProgress = false) {
@@ -55,9 +56,11 @@ class Frame {
55
56
 
56
57
  get shapes() {
57
58
  if (!this.play.playData.shapes) return [];
58
- return this.play.playData.shapes.map(s => {
59
- return JSON.parse(JSON.stringify(s));
60
- });
59
+ return this.play.playData.shapes
60
+ .filter(s => ShapeModels[s.type] !== undefined)
61
+ .map(s => {
62
+ return new ShapeModels[s.type](s);
63
+ });
61
64
  }
62
65
 
63
66
  get currentPhasePlayers() {
@@ -257,6 +260,9 @@ class Frame {
257
260
  if (objectType === 'player') {
258
261
  return this.closestPlayerToPoint(courtPoint, filterCallback);
259
262
  }
263
+ if (objectType === 'shape') {
264
+ return this.closestShapeToPoint(courtPoint, filterCallback);
265
+ }
260
266
  if (objectType === 'line') {
261
267
  return this.closestLineToPoint(courtPoint, filterCallback);
262
268
  }
@@ -290,8 +296,7 @@ class Frame {
290
296
  return result;
291
297
  }, []);
292
298
 
293
- const minLineDistance = _.minBy(lineDistances, 'distance');
294
- return minLineDistance;
299
+ return _.minBy(lineDistances, 'distance');
295
300
  }
296
301
 
297
302
  closestLineVertexToPoint(courtPoint, filterCallback = null) {
@@ -316,8 +321,7 @@ class Frame {
316
321
  });
317
322
  return result;
318
323
  }, []);
319
- const minLineDistance = _.minBy(lineVertexDistances, 'distance');
320
- return minLineDistance;
324
+ return _.minBy(lineVertexDistances, 'distance');
321
325
  }
322
326
 
323
327
  closestPlayerToPoint(courtPoint, filterCallback = null) {
@@ -334,8 +338,22 @@ class Frame {
334
338
  });
335
339
  return result;
336
340
  }, []);
337
- const minPlayerDistance = _.minBy(playerDistances, 'distance');
338
- return minPlayerDistance;
341
+ return _.minBy(playerDistances, 'distance');
342
+ }
343
+
344
+ closestShapeToPoint(courtPoint) {
345
+ const shapeDistances = this.shapes
346
+ .filter(shape => shape.rectWrapperContains(courtPoint))
347
+ .reduce((result, item) => {
348
+ const shapeLocation = this.prepareCourtPoint(item.location);
349
+ result.push({
350
+ object: item,
351
+ objectPoint: shapeLocation,
352
+ distance: distanceBetweenPoints(shapeLocation, courtPoint)
353
+ });
354
+ return result;
355
+ }, []);
356
+ return _.minBy(shapeDistances, 'distance');
339
357
  }
340
358
 
341
359
  prepareCourtPoint(courtPoint) {
@@ -0,0 +1,53 @@
1
+ const Model = require('./Base/InternalFrameModel');
2
+
3
+ class Shape extends Model {
4
+ get id() {
5
+ return this._getAttr('id');
6
+ }
7
+
8
+ get location() {
9
+ return this._getAttr('location');
10
+ }
11
+
12
+ get scale() {
13
+ return this._getAttr('scale');
14
+ }
15
+
16
+ get color() {
17
+ return this._getAttr('color');
18
+ }
19
+
20
+ get type() {
21
+ return this._getAttr('type');
22
+ }
23
+
24
+ get outerCircleRadius() {
25
+ return 10;
26
+ }
27
+
28
+ get rectWrapPoints() {
29
+ const topLeft = { x: -this.outerCircleRadius / 2, y: -this.outerCircleRadius / 2 };
30
+ const topRight = { x: this.outerCircleRadius / 2, y: -this.outerCircleRadius / 2 };
31
+ const botRight = { x: this.outerCircleRadius / 2, y: this.outerCircleRadius / 2 };
32
+ const botLeft = { x: -this.outerCircleRadius / 2, y: this.outerCircleRadius / 2 };
33
+ return [topLeft, topRight, botRight, botLeft];
34
+ }
35
+
36
+ get rectWrapPointsTranslated() {
37
+ return this.rectWrapPoints.map(point => {
38
+ return { x: point.x * this.scale.x + this.location.x, y: point.y * this.scale.y + this.location.y };
39
+ });
40
+ }
41
+
42
+ get shapeControlPoints() {
43
+ // Override this function in a subclass if needed
44
+ return [];
45
+ }
46
+
47
+ rectWrapperContains({ x, y }) {
48
+ const [topLeft, topRight, botRight] = this.rectWrapPointsTranslated;
49
+ return topLeft.x <= x && x <= topRight.x && topLeft.y <= y && y <= botRight.y;
50
+ }
51
+ }
52
+
53
+ module.exports = Shape;
@@ -0,0 +1,17 @@
1
+ const Shape = require('../Shape');
2
+
3
+ class CircleShape extends Shape {
4
+ get outerCircleRadius() {
5
+ return 5;
6
+ }
7
+
8
+ get rectWrapPoints() {
9
+ const topLeft = { x: -this.outerCircleRadius, y: -this.outerCircleRadius };
10
+ const topRight = { x: this.outerCircleRadius, y: -this.outerCircleRadius };
11
+ const botRight = { x: this.outerCircleRadius, y: this.outerCircleRadius };
12
+ const botLeft = { x: -this.outerCircleRadius, y: this.outerCircleRadius };
13
+ return [topLeft, topRight, botRight, botLeft];
14
+ }
15
+ }
16
+
17
+ module.exports = CircleShape;
@@ -0,0 +1,13 @@
1
+ const Shape = require('../Shape');
2
+
3
+ class ConeShape extends Shape {
4
+ get outerCircleRadius() {
5
+ return 5;
6
+ }
7
+
8
+ get shapeControlPoints() {
9
+ return this.rectWrapPoints;
10
+ }
11
+ }
12
+
13
+ module.exports = ConeShape;
@@ -0,0 +1,13 @@
1
+ const Shape = require('../Shape');
2
+
3
+ class SquareShape extends Shape {
4
+ get outerCircleRadius() {
5
+ return 10;
6
+ }
7
+
8
+ get shapeControlPoints() {
9
+ return this.rectWrapPoints;
10
+ }
11
+ }
12
+
13
+ module.exports = SquareShape;
@@ -0,0 +1,25 @@
1
+ const { cos, sin } = require('mathjs');
2
+ const Shape = require('../Shape');
3
+
4
+ class TriangleShape extends Shape {
5
+ get outerCircleRadius() {
6
+ return 10;
7
+ }
8
+
9
+ get shapeControlPoints() {
10
+ return [
11
+ { x: 0, y: -this.outerCircleRadius },
12
+ { x: this.outerCircleRadius * cos(210), y: this.outerCircleRadius * sin(210) },
13
+ { x: -this.outerCircleRadius * cos(210), y: this.outerCircleRadius * sin(210) }
14
+ ];
15
+ }
16
+
17
+ get rectWrapPoints() {
18
+ const [topPoint, botRight, botLeft] = this.shapeControlPoints;
19
+ const topLeft = { x: botLeft.x, y: topPoint.y };
20
+ const topRight = { x: botRight.x, y: topPoint.y };
21
+ return [topLeft, topRight, botRight, botLeft];
22
+ }
23
+ }
24
+
25
+ module.exports = TriangleShape;
@@ -0,0 +1,12 @@
1
+ // require all modules on the path and with the pattern defined
2
+ const req = require.context('./', true, /.js$/);
3
+
4
+ const modules = {};
5
+
6
+ req.keys().forEach(key => {
7
+ if (key.indexOf('index') >= 0) return;
8
+ const mname = key.replace('./', '').replace('Shape.js', '');
9
+ modules[mname.toUpperCase()] = req(key);
10
+ });
11
+
12
+ module.exports = modules;