@luceosports/play-rendering 1.11.5 → 1.11.6
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 +1 -1
- package/dist/play-rendering.js.map +1 -1
- package/package.json +1 -1
- package/src/layers/NoteLayer.js +31 -17
- package/src/models/Note.js +26 -17
package/package.json
CHANGED
package/src/layers/NoteLayer.js
CHANGED
|
@@ -6,8 +6,6 @@ class NoteLayer extends BaseLayer {
|
|
|
6
6
|
apply() {
|
|
7
7
|
this.ctx.save();
|
|
8
8
|
|
|
9
|
-
this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH;
|
|
10
|
-
|
|
11
9
|
this.playData.notes.forEach(note => {
|
|
12
10
|
this.ctx.save();
|
|
13
11
|
|
|
@@ -22,7 +20,7 @@ class NoteLayer extends BaseLayer {
|
|
|
22
20
|
|
|
23
21
|
this.setFont(note);
|
|
24
22
|
this.drawBubble(box);
|
|
25
|
-
this.drawText(lines);
|
|
23
|
+
this.drawText(note, lines);
|
|
26
24
|
|
|
27
25
|
this.ctx.restore();
|
|
28
26
|
});
|
|
@@ -71,30 +69,31 @@ class NoteLayer extends BaseLayer {
|
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
setFont(note) {
|
|
74
|
-
this.ctx.font = note.
|
|
72
|
+
this.ctx.font = note.fontComputed;
|
|
75
73
|
this.ctx.textBaseline = note.textBaseline;
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
drawBubble({ width, height }) {
|
|
77
|
+
this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH;
|
|
79
78
|
this.ctx.beginPath();
|
|
80
79
|
this.ctx.rect(0, 0, width, height);
|
|
81
80
|
this.ctx.fill();
|
|
82
81
|
this.ctx.stroke();
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
drawText(lines) {
|
|
84
|
+
drawText(note, lines) {
|
|
86
85
|
lines.forEach(({ words }, index) => {
|
|
87
86
|
this.ctx.save();
|
|
88
87
|
|
|
89
|
-
this.ctx.translate(Note.NOTE_WRAP_PADDING, Note.NOTE_WRAP_PADDING +
|
|
88
|
+
this.ctx.translate(Note.NOTE_WRAP_PADDING, Note.NOTE_WRAP_PADDING + note.lineHeight * index);
|
|
90
89
|
|
|
91
90
|
let wordStartX = 0;
|
|
92
91
|
words.forEach((word, i) => {
|
|
93
92
|
const matches = [...word.text.matchAll(/(<player=(\d*)>)/gi)];
|
|
94
93
|
|
|
95
94
|
if (matches.length && matches[0].index === 0) {
|
|
96
|
-
this.drawPlayerToken(wordStartX, matches[0][2]);
|
|
97
|
-
wordStartX +=
|
|
95
|
+
this.drawPlayerToken(note, wordStartX, matches[0][2]);
|
|
96
|
+
wordStartX += note.playerTokenRadius * 2;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
this.ctx.fillStyle = `rgba(0, 0, 0, ${this.noteAlpha})`;
|
|
@@ -102,12 +101,12 @@ class NoteLayer extends BaseLayer {
|
|
|
102
101
|
this.ctx.fillText(wordText, wordStartX, 0);
|
|
103
102
|
wordStartX += word.width;
|
|
104
103
|
if (matches.length) {
|
|
105
|
-
wordStartX -=
|
|
104
|
+
wordStartX -= note.playerTokenRadius * 2;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
if (matches.length && matches[0].index > 0) {
|
|
109
|
-
this.drawPlayerToken(wordStartX, matches[0][2]);
|
|
110
|
-
wordStartX +=
|
|
108
|
+
this.drawPlayerToken(note, wordStartX, matches[0][2]);
|
|
109
|
+
wordStartX += note.playerTokenRadius * 2;
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
if (i !== words.length - 1) {
|
|
@@ -116,23 +115,38 @@ class NoteLayer extends BaseLayer {
|
|
|
116
115
|
}
|
|
117
116
|
});
|
|
118
117
|
|
|
118
|
+
if (note.font.underline || note.font.strikethrough) {
|
|
119
|
+
this.ctx.lineWidth = 0.07;
|
|
120
|
+
this.ctx.strokeStyle = `rgba(0, 0, 0, ${this.noteAlpha})`;
|
|
121
|
+
this.ctx.beginPath();
|
|
122
|
+
if (note.font.underline) {
|
|
123
|
+
this.ctx.moveTo(0, note.lineHeight - Note.NOTE_LINE_HEIGHT_OFFSET);
|
|
124
|
+
this.ctx.lineTo(wordStartX, note.lineHeight - Note.NOTE_LINE_HEIGHT_OFFSET);
|
|
125
|
+
}
|
|
126
|
+
if (note.font.strikethrough) {
|
|
127
|
+
this.ctx.moveTo(0, note.lineHeight / 2 - Note.NOTE_LINE_HEIGHT_OFFSET);
|
|
128
|
+
this.ctx.lineTo(wordStartX, note.lineHeight / 2 - Note.NOTE_LINE_HEIGHT_OFFSET);
|
|
129
|
+
}
|
|
130
|
+
this.ctx.stroke();
|
|
131
|
+
}
|
|
132
|
+
|
|
119
133
|
this.ctx.restore();
|
|
120
134
|
});
|
|
121
135
|
}
|
|
122
136
|
|
|
123
|
-
drawPlayerToken(x, label) {
|
|
137
|
+
drawPlayerToken(note, x, label) {
|
|
124
138
|
this.ctx.save();
|
|
125
139
|
|
|
126
|
-
this.ctx.translate(x +
|
|
140
|
+
this.ctx.translate(x + note.playerTokenRadius, 0);
|
|
127
141
|
|
|
128
142
|
this.ctx.beginPath();
|
|
129
|
-
this.ctx.strokeStyle =
|
|
130
|
-
this.ctx.fillStyle =
|
|
131
|
-
this.ctx.arc(0,
|
|
143
|
+
this.ctx.strokeStyle = `rgba(255, 255, 255, ${this.noteAlpha})`;
|
|
144
|
+
this.ctx.fillStyle = `rgba(243, 111, 33, ${this.noteAlpha})`;
|
|
145
|
+
this.ctx.arc(0, note.fontSize / 2, note.playerTokenRadius, 0, Math.PI * 2);
|
|
132
146
|
this.ctx.fill();
|
|
133
147
|
this.ctx.stroke();
|
|
134
148
|
|
|
135
|
-
this.ctx.fillStyle =
|
|
149
|
+
this.ctx.fillStyle = `rgba(255, 255, 255, ${this.noteAlpha})`;
|
|
136
150
|
this.ctx.fillText(label, -this.ctx.measureText(label).width / 2, 0);
|
|
137
151
|
|
|
138
152
|
this.ctx.restore();
|
package/src/models/Note.js
CHANGED
|
@@ -7,29 +7,17 @@ class Note extends Model {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
static get NOTE_WRAP_MAX_WIDTH() {
|
|
10
|
-
return
|
|
10
|
+
return 22;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
static get NOTE_WRAP_PADDING() {
|
|
14
14
|
return 0.43;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
static get NOTE_PLAYER_TOKEN_RADIUS() {
|
|
18
|
-
return 0.7;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
17
|
static get NOTE_LINE_HEIGHT_OFFSET() {
|
|
22
18
|
return 0.3;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
static get NOTE_FONT_SIZE() {
|
|
26
|
-
return 1;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static get NOTE_LINE_HEIGHT() {
|
|
30
|
-
return Note.NOTE_FONT_SIZE + Note.NOTE_LINE_HEIGHT_OFFSET;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
21
|
get id() {
|
|
34
22
|
return this._getAttr('id');
|
|
35
23
|
}
|
|
@@ -47,7 +35,28 @@ class Note extends Model {
|
|
|
47
35
|
}
|
|
48
36
|
|
|
49
37
|
get font() {
|
|
50
|
-
return
|
|
38
|
+
return this._getAttr('font');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get fontSize() {
|
|
42
|
+
return this.font.fontSize / 10;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get lineHeight() {
|
|
46
|
+
return this.fontSize + Note.NOTE_LINE_HEIGHT_OFFSET;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get playerTokenRadius() {
|
|
50
|
+
return 0.7 * this.fontSize;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get fontComputed() {
|
|
54
|
+
const fontOptions = [];
|
|
55
|
+
if (this.font.bold) fontOptions.push('bold');
|
|
56
|
+
if (this.font.italic) fontOptions.push('italic');
|
|
57
|
+
fontOptions.push(`${this.fontSize}px`);
|
|
58
|
+
fontOptions.push('Arial');
|
|
59
|
+
return fontOptions.join(' ');
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
get textBaseline() {
|
|
@@ -66,13 +75,13 @@ class Note extends Model {
|
|
|
66
75
|
lines,
|
|
67
76
|
box: {
|
|
68
77
|
width: maxLineWidth + Note.NOTE_WRAP_PADDING * 2,
|
|
69
|
-
height: lines.length *
|
|
78
|
+
height: lines.length * this.lineHeight + Note.NOTE_WRAP_PADDING * 2 - Note.NOTE_LINE_HEIGHT_OFFSET
|
|
70
79
|
}
|
|
71
80
|
};
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
_getLines() {
|
|
75
|
-
this.internalCtx.font = this.
|
|
84
|
+
this.internalCtx.font = this.fontComputed;
|
|
76
85
|
this.internalCtx.textBaseline = this.textBaseline;
|
|
77
86
|
|
|
78
87
|
const fitWidth = Note.NOTE_WRAP_MAX_WIDTH - Note.NOTE_WRAP_PADDING * 2;
|
|
@@ -123,7 +132,7 @@ class Note extends Model {
|
|
|
123
132
|
const wordProcessed = {
|
|
124
133
|
text: w,
|
|
125
134
|
width: matches.length
|
|
126
|
-
? this.internalCtx.measureText(w.replace(/<player=(\d*)>/, '')).width +
|
|
135
|
+
? this.internalCtx.measureText(w.replace(/<player=(\d*)>/, '')).width + this.playerTokenRadius * 2
|
|
127
136
|
: this.internalCtx.measureText(w).width
|
|
128
137
|
};
|
|
129
138
|
lineWidth += wordProcessed.width;
|