@luceosports/play-rendering 1.9.31 → 1.9.32

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@luceosports/play-rendering",
3
- "version": "1.9.31",
3
+ "version": "1.9.32",
4
4
  "description": "",
5
5
  "main": "dist/play-rendering.js",
6
6
  "scripts": {
@@ -0,0 +1,17 @@
1
+ module.exports = Object.freeze({
2
+ NBA: {
3
+ COURT_LINE_WIDTH: 0.1667,
4
+ COURT_RECT_WIDTH: 50.0,
5
+ COURT_RECT_HEIGHT: 94.0,
6
+ PLAYER_TOKEN_SCALE: 1,
7
+ LINE_SCALE: 1
8
+ },
9
+ FOOTBALL: {
10
+ COURT_LINE_WIDTH: 0.32,
11
+ COURT_RECT_WIDTH: 160.0,
12
+ COURT_RECT_HEIGHT: 360.0,
13
+ END_ZONE_HEIGHT: 30,
14
+ PLAYER_TOKEN_SCALE: 2,
15
+ LINE_SCALE: 1.65
16
+ }
17
+ });
@@ -1,15 +1,7 @@
1
+ const BaseLayer = require('./base/BaseLayer');
1
2
  const courtLayers = require('./court');
2
- const constants = require('./court/constants');
3
-
4
- class CourtLayer {
5
- constructor(ctx, { court, options }) {
6
- this.ctx = ctx;
7
- this.options = {
8
- court: JSON.parse(JSON.stringify(court)),
9
- ...options
10
- };
11
- }
12
3
 
4
+ class CourtLayer extends BaseLayer {
13
5
  get frameWidth() {
14
6
  return this.options.width;
15
7
  }
@@ -23,16 +15,12 @@ class CourtLayer {
23
15
  }
24
16
 
25
17
  get courtTypeLayers() {
26
- if (!courtLayers[this.options.court.type]) throw new Error('unknown court type');
27
- return courtLayers[this.options.court.type];
28
- }
29
-
30
- get courtTypeConstants() {
31
- return constants[this.options.court.type];
18
+ if (!courtLayers[this.playData.court.type]) throw new Error('unknown court type');
19
+ return courtLayers[this.playData.court.type];
32
20
  }
33
21
 
34
22
  get background() {
35
- return this.options.background || this.options.court.type;
23
+ return this.options.background || this.playData.court.type;
36
24
  }
37
25
 
38
26
  apply() {
@@ -92,12 +80,12 @@ class CourtLayer {
92
80
  }
93
81
 
94
82
  const fullCourtIndentY =
95
- this.options.court.courtRect.size.height > this.courtTypeConstants.COURT_RECT_HEIGHT
96
- ? Math.abs(this.options.court.courtRect.origin.y)
83
+ this.playData.court.courtRect.size.height > this.courtTypeConstants.COURT_RECT_HEIGHT
84
+ ? Math.abs(this.playData.court.courtRect.origin.y)
97
85
  : 0;
98
86
 
99
- const dx = (1 + Math.abs(this.options.court.courtRect.origin.x)) * this.scale;
100
- const dy = (this.options.court.courtRect.size.height - fullCourtIndentY - 1) * this.scale - destination.height;
87
+ const dx = (1 + Math.abs(this.playData.court.courtRect.origin.x)) * this.scale;
88
+ const dy = (this.playData.court.courtRect.size.height - fullCourtIndentY - 1) * this.scale - destination.height;
101
89
 
102
90
  this.ctx.drawImage(
103
91
  this.staticData.watermark[this.options.watermark],
@@ -1,12 +1,6 @@
1
- class LineControlPointLayer {
2
- constructor(ctx, playData) {
3
- this.ctx = ctx;
4
- this.playData = playData;
5
- this.options = {
6
- ...playData.options
7
- };
8
- }
1
+ const BaseLayer = require('./base/BaseLayer');
9
2
 
3
+ class LineControlPointLayer extends BaseLayer {
10
4
  apply() {
11
5
  if (!this.options.linesDisplay) return;
12
6
 
@@ -1,14 +1,10 @@
1
1
  const _ = require('lodash');
2
+ const BaseLayer = require('./base/BaseLayer');
2
3
  const lineLayers = require('./line');
3
4
 
4
- class LineLayer {
5
- constructor(ctx, playData) {
6
- this.ctx = ctx;
7
- this.playData = playData;
8
- this.options = {
9
- ...playData.options,
10
- lineWidth: 0.33
11
- };
5
+ class LineLayer extends BaseLayer {
6
+ get lineWidth() {
7
+ return 0.33 * this.courtTypeConstants.LINE_SCALE;
12
8
  }
13
9
 
14
10
  apply() {
@@ -16,7 +12,7 @@ class LineLayer {
16
12
 
17
13
  this.ctx.save();
18
14
 
19
- this.ctx.lineWidth = this.options.lineWidth;
15
+ this.ctx.lineWidth = this.lineWidth;
20
16
  this.playData.lines.forEach(line => {
21
17
  if (this.options.linesHiddenIds.indexOf(line.id) >= 0) return;
22
18
  const layerKey = `${_.capitalize(line.type)}LineLayer`;
@@ -1,25 +1,23 @@
1
- class PlayerLayer {
2
- constructor(ctx, { players, options, court }) {
3
- this.ctx = ctx;
4
- this.players = players;
5
- this.options = { ...options, ...court };
6
- }
1
+ const BaseLayer = require('./base/BaseLayer');
7
2
 
3
+ class PlayerLayer extends BaseLayer {
8
4
  get staticData() {
9
5
  return this.options.staticData;
10
6
  }
11
7
 
12
8
  apply() {
13
- if (!this.players.length) return;
14
- const radius = 1.5;
9
+ if (!this.playData.players.length) return;
10
+
11
+ const playerScale = this.courtTypeConstants.PLAYER_TOKEN_SCALE;
12
+ const radius = 1.5 * playerScale;
15
13
 
16
14
  this.ctx.save();
17
15
 
18
- this.players.forEach(player => {
16
+ this.playData.players.forEach(player => {
19
17
  if (this.options.playersHiddenPositions.findIndex(p => parseInt(p) === parseInt(player.position)) >= 0) return;
20
18
 
21
- const fontSize = player.textLabel.length > 1 ? 2.0 : 2.5;
22
- const textVerticalOffset = player.textLabel.length > 1 ? 0.7 : 0.85;
19
+ const fontSize = (player.textLabel.length > 1 ? 2.0 : 2.5) * playerScale;
20
+ const textVerticalOffset = (player.textLabel.length > 1 ? 0.7 : 0.85) * playerScale;
23
21
 
24
22
  const { x, y } = player.location;
25
23
 
@@ -1,19 +1,14 @@
1
- class BaseLayer {
2
- constructor(parentLayer) {
3
- this.ctx = parentLayer.ctx;
4
- this.options = parentLayer.options ? parentLayer.options : {};
5
- }
6
-
7
- apply() {
8
- this.ctx.save();
1
+ const constants = require('../../constants');
9
2
 
10
- this.drawLogic();
11
-
12
- this.ctx.restore();
3
+ class BaseLayer {
4
+ constructor(ctx, playData) {
5
+ this.ctx = ctx;
6
+ this.playData = playData;
7
+ this.options = { ...playData.options };
13
8
  }
14
9
 
15
- drawLogic() {
16
- // Override this
10
+ get courtTypeConstants() {
11
+ return constants[this.playData.court.type];
17
12
  }
18
13
  }
19
14
 
@@ -0,0 +1,20 @@
1
+ class InternalBaseLayer {
2
+ constructor(parentLayer) {
3
+ this.ctx = parentLayer.ctx;
4
+ this.options = parentLayer.options ? parentLayer.options : {};
5
+ }
6
+
7
+ apply() {
8
+ this.ctx.save();
9
+
10
+ this.drawLogic();
11
+
12
+ this.ctx.restore();
13
+ }
14
+
15
+ drawLogic() {
16
+ // Override this
17
+ }
18
+ }
19
+
20
+ module.exports = InternalBaseLayer;
@@ -1,6 +1,6 @@
1
- const BaseLayer = require('../../base/BaseLayer');
1
+ const InternalBaseLayer = require('../../base/InternalBaseLayer');
2
2
 
3
- class InternalCourtLayer extends BaseLayer {
3
+ class InternalCourtLayer extends InternalBaseLayer {
4
4
  constructor(parentLayer) {
5
5
  super(parentLayer);
6
6
  this.courtTypeConstants = parentLayer.courtTypeConstants;
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH } = require('../../constants/FOOTBALL');
2
+ const {
3
+ FOOTBALL: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class BorderRectLayer extends InternalCourtLayer {
5
7
  drawLogic() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH } = require('../../constants/FOOTBALL');
2
+ const {
3
+ FOOTBALL: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class CenterLineLayer extends InternalCourtLayer {
5
7
  drawLogic() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_LINE_WIDTH } = require('../../constants/FOOTBALL');
2
+ const {
3
+ FOOTBALL: { COURT_RECT_WIDTH, COURT_LINE_WIDTH }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class EndZoneLayer extends InternalCourtLayer {
5
7
  reflection() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { END_ZONE_HEIGHT, COURT_RECT_WIDTH } = require('../../constants/FOOTBALL');
2
+ const {
3
+ FOOTBALL: { COURT_RECT_WIDTH, END_ZONE_HEIGHT }
4
+ } = require('../../../../constants');
3
5
 
4
6
  const NUMBER_VERTICAL_OFFSET = -6;
5
7
 
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_HEIGHT, COURT_LINE_WIDTH, END_ZONE_HEIGHT, COURT_RECT_WIDTH } = require('../../constants/FOOTBALL');
2
+ const {
3
+ FOOTBALL: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH, END_ZONE_HEIGHT }
4
+ } = require('../../../../constants');
3
5
 
4
6
  const HASH_MARK_OFFSET_X = 3;
5
7
  const HASH_MARK_LENGTH = 3;
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH, END_ZONE_HEIGHT } = require('../../constants/FOOTBALL');
2
+ const {
3
+ FOOTBALL: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH, END_ZONE_HEIGHT }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class YardLineLayer extends InternalCourtLayer {
5
7
  reflection() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_LINE_WIDTH, COURT_RECT_WIDTH } = require('../../constants/NBA');
2
+ const {
3
+ NBA: { COURT_RECT_WIDTH, COURT_LINE_WIDTH }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class Big3Layer extends InternalCourtLayer {
5
7
  drawLogic() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH } = require('../../constants/NBA');
2
+ const {
3
+ NBA: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class BorderRectLayer extends InternalCourtLayer {
5
7
  drawLogic() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_RECT_HEIGHT } = require('../../constants/NBA');
2
+ const {
3
+ NBA: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class CenterCircleLayer extends InternalCourtLayer {
5
7
  drawLogic() {
@@ -1,5 +1,7 @@
1
1
  const InternalCourtLayer = require('../../base/InternalCourtLayer');
2
- const { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH } = require('../../constants/NBA');
2
+ const {
3
+ NBA: { COURT_RECT_WIDTH, COURT_RECT_HEIGHT, COURT_LINE_WIDTH }
4
+ } = require('../../../../constants');
3
5
 
4
6
  class CenterLineLayer extends InternalCourtLayer {
5
7
  drawLogic() {
@@ -1,7 +1,7 @@
1
- const BaseLayer = require('../../base/BaseLayer');
1
+ const InternalBaseLayer = require('../../base/InternalBaseLayer');
2
2
  const LineDrawingMath = require('../../../math/LineDrawingMath');
3
3
 
4
- class InternalLineLayer extends BaseLayer {
4
+ class InternalLineLayer extends InternalBaseLayer {
5
5
  constructor(parentLineLayer, line) {
6
6
  super(parentLineLayer);
7
7
  this.line = line;
@@ -1,7 +0,0 @@
1
- module.exports = Object.freeze({
2
- COURT_LINE_WIDTH: 0.32,
3
- COURT_RECT_WIDTH: 160.0,
4
- COURT_RECT_HEIGHT: 360.0,
5
- END_ZONE_HEIGHT: 30,
6
- TEN_YARDS_HEIGHT: 30
7
- });
@@ -1,5 +0,0 @@
1
- module.exports = Object.freeze({
2
- COURT_LINE_WIDTH: 0.1667,
3
- COURT_RECT_WIDTH: 50.0,
4
- COURT_RECT_HEIGHT: 94.0
5
- });
@@ -1,11 +0,0 @@
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
- const mName = key.replace('./', '').replace('.js', '');
8
- modules[mName] = req(key);
9
- });
10
-
11
- module.exports = modules;