@luceosports/play-rendering 1.11.16 → 1.11.19
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/dist/play-rendering.js +3 -3
- package/dist/play-rendering.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.js +2 -2
- package/src/layers/LineLayer.js +1 -1
- package/src/layers/PlayerLayer.js +24 -11
- package/src/layers/court/layers/NBA/CenterCircleLayer.js +2 -0
- package/src/layers/line/index.js +11 -11
- package/src/models/Animation.js +8 -9
- package/src/models/Play/Options.js +32 -0
- package/src/models/Play.js +3 -45
package/package.json
CHANGED
package/src/constants.js
CHANGED
|
@@ -5,7 +5,7 @@ module.exports = Object.freeze({
|
|
|
5
5
|
COURT_RECT_HEIGHT: 94.0,
|
|
6
6
|
PLAYER_TOKEN_RADIUS: 1.5,
|
|
7
7
|
PLAYER_TOKEN_SCALE: 1,
|
|
8
|
-
|
|
8
|
+
LINE_WIDTH: 0.33,
|
|
9
9
|
LINE_MASKING: true
|
|
10
10
|
},
|
|
11
11
|
FOOTBALL: {
|
|
@@ -15,7 +15,7 @@ module.exports = Object.freeze({
|
|
|
15
15
|
END_ZONE_HEIGHT: 30,
|
|
16
16
|
PLAYER_TOKEN_RADIUS: 1.5,
|
|
17
17
|
PLAYER_TOKEN_SCALE: 2,
|
|
18
|
-
|
|
18
|
+
LINE_WIDTH: 0.55,
|
|
19
19
|
LINE_MASKING: false
|
|
20
20
|
}
|
|
21
21
|
});
|
package/src/layers/LineLayer.js
CHANGED
|
@@ -23,13 +23,9 @@ class PlayerLayer extends BaseLayer {
|
|
|
23
23
|
|
|
24
24
|
const { x, y } = player.location;
|
|
25
25
|
|
|
26
|
-
this.
|
|
26
|
+
this.setPlayerPuckStyle(player);
|
|
27
27
|
|
|
28
|
-
this.
|
|
29
|
-
this.ctx.moveTo(x, y);
|
|
30
|
-
|
|
31
|
-
this.ctx.arc(x, y, this.radius, 0, Math.PI * 2, true);
|
|
32
|
-
this.ctx.fill();
|
|
28
|
+
this.drawPlayerPuck(player);
|
|
33
29
|
|
|
34
30
|
this.setPlayerLabel(player);
|
|
35
31
|
|
|
@@ -64,10 +60,10 @@ class PlayerLayer extends BaseLayer {
|
|
|
64
60
|
this.ctx.restore();
|
|
65
61
|
}
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
setPlayerPuckStyle(player) {
|
|
68
64
|
const { red, green, blue, alpha } = player.color;
|
|
69
65
|
|
|
70
|
-
const
|
|
66
|
+
const isDefaultInputColor = red === 0 && green === 0 && blue === 0 && alpha === 1;
|
|
71
67
|
|
|
72
68
|
const payerInPosition = this.options.position && player.position === this.options.position;
|
|
73
69
|
const r = payerInPosition ? 0 : Math.ceil(red * 255);
|
|
@@ -76,12 +72,29 @@ class PlayerLayer extends BaseLayer {
|
|
|
76
72
|
|
|
77
73
|
let color = `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
78
74
|
|
|
79
|
-
if (player.isDefender && !payerInPosition &&
|
|
75
|
+
if (player.isDefender && !payerInPosition && isDefaultInputColor) {
|
|
80
76
|
color = '#bb271b';
|
|
81
77
|
}
|
|
82
|
-
if (player.possession &&
|
|
78
|
+
if (player.possession && isDefaultInputColor) color = '#ff8000';
|
|
79
|
+
|
|
80
|
+
if (this.options.legacyPrintStyle) {
|
|
81
|
+
color = '#000000';
|
|
82
|
+
this.ctx.lineWidth = this.courtTypeConstants.LINE_WIDTH;
|
|
83
|
+
}
|
|
83
84
|
|
|
84
85
|
this.ctx.fillStyle = color;
|
|
86
|
+
this.ctx.strokeStyle = color;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
drawPlayerPuck(player) {
|
|
90
|
+
const { x, y } = player.location;
|
|
91
|
+
this.ctx.beginPath();
|
|
92
|
+
this.ctx.arc(x, y, this.radius, 0, Math.PI * 2, true);
|
|
93
|
+
if (this.options.legacyPrintStyle) {
|
|
94
|
+
if (player.possession) this.ctx.stroke();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.ctx.fill();
|
|
85
98
|
}
|
|
86
99
|
|
|
87
100
|
setPlayerLabel(player) {
|
|
@@ -92,7 +105,7 @@ class PlayerLayer extends BaseLayer {
|
|
|
92
105
|
|
|
93
106
|
if (!alpha) return;
|
|
94
107
|
|
|
95
|
-
this.ctx.fillStyle = '#ffffff';
|
|
108
|
+
this.ctx.fillStyle = this.options.legacyPrintStyle ? '#000000' : '#ffffff';
|
|
96
109
|
this.ctx.textAlign = 'center';
|
|
97
110
|
this.ctx.font = `${fontSize}px Helvetica`;
|
|
98
111
|
|
|
@@ -5,6 +5,8 @@ const {
|
|
|
5
5
|
|
|
6
6
|
class CenterCircleLayer extends InternalCourtLayer {
|
|
7
7
|
drawLogic() {
|
|
8
|
+
if (!this.options.showHalfCourtCircle) return;
|
|
9
|
+
|
|
8
10
|
const outerCenterRadius = 6.0;
|
|
9
11
|
const innerCenterRadius = 2.0;
|
|
10
12
|
const centerCourtPoint = { x: COURT_RECT_WIDTH / 2, y: COURT_RECT_HEIGHT / 2 };
|
package/src/layers/line/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// require all modules on the path and with the pattern defined
|
|
2
|
-
const req = require.context('./layers/', 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;
|
|
1
|
+
// require all modules on the path and with the pattern defined
|
|
2
|
+
const req = require.context('./layers/', 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;
|
package/src/models/Animation.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const config = require('../config');
|
|
3
3
|
const Frame = require('./Frame');
|
|
4
|
+
const Line = require('./Line');
|
|
4
5
|
|
|
5
6
|
class Animation {
|
|
6
7
|
constructor(ctx, play) {
|
|
@@ -50,13 +51,11 @@ class Animation {
|
|
|
50
51
|
return result;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
get
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
get linePhaseIntervalMaxRounded() {
|
|
59
|
-
return this.linePhaseIntervalMax;
|
|
54
|
+
get lastLineAnimationMax() {
|
|
55
|
+
return this.play.playData.lines.reduce((result, line) => {
|
|
56
|
+
const lineModel = new Line(line);
|
|
57
|
+
return result > lineModel.lastAnimEndTime ? result : lineModel.lastAnimEndTime;
|
|
58
|
+
}, 0);
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
start(finishCallback, progressCallback) {
|
|
@@ -106,8 +105,8 @@ class Animation {
|
|
|
106
105
|
drawFrame(finishCallback, progressCallback, timestamp) {
|
|
107
106
|
if (!this.running) return;
|
|
108
107
|
|
|
109
|
-
if (this.globalProgress >= this.
|
|
110
|
-
progressCallback(this.
|
|
108
|
+
if (this.globalProgress >= this.lastLineAnimationMax) {
|
|
109
|
+
progressCallback(this.lastLineAnimationMax);
|
|
111
110
|
this.reset();
|
|
112
111
|
cancelAnimationFrame(this.loopId);
|
|
113
112
|
setTimeout(() => {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
useDefaults: function(options = {}) {
|
|
3
|
+
const defaults = {
|
|
4
|
+
width: 300,
|
|
5
|
+
lineColor: '#fff', // courtBorderColor
|
|
6
|
+
linesDisplay: true,
|
|
7
|
+
linesDisplayOnMoveOnly: true,
|
|
8
|
+
linesHiddenIds: [],
|
|
9
|
+
linesSelectedIds: [],
|
|
10
|
+
shapeSelectedId: null,
|
|
11
|
+
noteSelectedId: null,
|
|
12
|
+
playersHiddenPositions: [],
|
|
13
|
+
background: '',
|
|
14
|
+
watermark: null,
|
|
15
|
+
mirror: false,
|
|
16
|
+
speed: 1,
|
|
17
|
+
position: null,
|
|
18
|
+
huddleMode: false,
|
|
19
|
+
magnetMode: false,
|
|
20
|
+
flipPlayerLabels: false,
|
|
21
|
+
legacyPrintStyle: false,
|
|
22
|
+
playerTokenScale: 1,
|
|
23
|
+
// TODO: refactor NBA court type constants below
|
|
24
|
+
big3: false,
|
|
25
|
+
showHalfCourtCircle: true
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
...defaults,
|
|
29
|
+
...options
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
package/src/models/Play.js
CHANGED
|
@@ -2,57 +2,15 @@ const _ = require('lodash');
|
|
|
2
2
|
const { loadImage } = require('canvas');
|
|
3
3
|
const playerHatsConfig = require('../playerHatsConfig');
|
|
4
4
|
const shapesConfig = require('../shapesConfig');
|
|
5
|
+
const { useDefaults } = require('./Play/Options');
|
|
5
6
|
|
|
6
7
|
const STORAGE_URL = 'https://playbooksstore.blob.core.windows.net/public';
|
|
7
8
|
const LUCEOSPORTS_WATERMARK_PATH = 'partners/LuceoSports/luceo-sports-logo-powered-by-sm.png';
|
|
8
9
|
|
|
9
10
|
class Play {
|
|
10
|
-
constructor(
|
|
11
|
-
data,
|
|
12
|
-
{
|
|
13
|
-
width = 300,
|
|
14
|
-
lineColor = '#fff', // courtBorderColor
|
|
15
|
-
linesDisplay = true,
|
|
16
|
-
linesDisplayOnMoveOnly = true,
|
|
17
|
-
linesHiddenIds = [],
|
|
18
|
-
linesSelectedIds = [],
|
|
19
|
-
shapeSelectedId = null,
|
|
20
|
-
noteSelectedId = null,
|
|
21
|
-
playersHiddenPositions = [],
|
|
22
|
-
background = '',
|
|
23
|
-
watermark = null,
|
|
24
|
-
mirror = false,
|
|
25
|
-
speed = 1,
|
|
26
|
-
position = null,
|
|
27
|
-
big3 = false,
|
|
28
|
-
huddleMode = false,
|
|
29
|
-
magnetMode = false,
|
|
30
|
-
flipPlayerLabels = false,
|
|
31
|
-
playerTokenScale = 1
|
|
32
|
-
} = {}
|
|
33
|
-
) {
|
|
11
|
+
constructor(data, options = {}) {
|
|
34
12
|
this.name = data.name;
|
|
35
|
-
this.options =
|
|
36
|
-
width,
|
|
37
|
-
lineColor,
|
|
38
|
-
linesDisplay,
|
|
39
|
-
linesDisplayOnMoveOnly,
|
|
40
|
-
linesHiddenIds,
|
|
41
|
-
linesSelectedIds,
|
|
42
|
-
shapeSelectedId,
|
|
43
|
-
noteSelectedId,
|
|
44
|
-
playersHiddenPositions,
|
|
45
|
-
background,
|
|
46
|
-
watermark,
|
|
47
|
-
mirror,
|
|
48
|
-
speed,
|
|
49
|
-
position,
|
|
50
|
-
big3,
|
|
51
|
-
huddleMode,
|
|
52
|
-
magnetMode,
|
|
53
|
-
flipPlayerLabels,
|
|
54
|
-
playerTokenScale
|
|
55
|
-
};
|
|
13
|
+
this.options = useDefaults(options);
|
|
56
14
|
this.setPlayData(data.playData);
|
|
57
15
|
}
|
|
58
16
|
|