homegames-client 0.2.1 → 0.2.2
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/THIRD_PARTY_NOTICES.txt +28 -2
- package/dist/homegames-client.js +29 -3
- package/package.json +4 -3
- package/src/game-view.js +36 -5
- package/src/index.js +86 -9
- package/src/input.js +51 -15
- package/src/local-game-chrome.js +15 -5
- package/src/local-session.js +10 -0
- package/src/player-sharing.js +78 -0
- package/src/portable-project.js +1 -0
- package/src/renderer.js +36 -13
- package/src/session-frame-styles.js +1 -1
- package/src/squish-map.js +3 -2
package/src/renderer.js
CHANGED
|
@@ -37,6 +37,12 @@ class Renderer {
|
|
|
37
37
|
this.thingIndices = [];
|
|
38
38
|
|
|
39
39
|
let i = 0;
|
|
40
|
+
// A native canvas ignores shadowColor = null, strokeStyle = null and
|
|
41
|
+
// lineWidth = 0. Avoid those no-op assignments, and only reset the two
|
|
42
|
+
// states that actually change. Start unknown because an embed may use
|
|
43
|
+
// the context between frames (or resizing may reset it).
|
|
44
|
+
let shadowBlurReset = false;
|
|
45
|
+
let globalAlphaReset = false;
|
|
40
46
|
|
|
41
47
|
while (buf && i < buf.length) {
|
|
42
48
|
const frameType = buf[i];
|
|
@@ -44,7 +50,11 @@ class Renderer {
|
|
|
44
50
|
|
|
45
51
|
let thing;
|
|
46
52
|
try {
|
|
47
|
-
|
|
53
|
+
// Decoders read the node bytes synchronously. A typed view
|
|
54
|
+
// avoids copying every node of every snapshot before decode;
|
|
55
|
+
// ordinary arrays remain supported by existing embeds.
|
|
56
|
+
thing = unsquish(typeof buf.subarray === 'function'
|
|
57
|
+
? buf.subarray(i, i + frameSize) : buf.slice(i, i + frameSize)).node;
|
|
48
58
|
} catch (e) {
|
|
49
59
|
i += frameSize;
|
|
50
60
|
continue;
|
|
@@ -85,10 +95,16 @@ class Renderer {
|
|
|
85
95
|
if (thing.effects && thing.effects.shadow) {
|
|
86
96
|
const sc = thing.effects.shadow.color;
|
|
87
97
|
ctx.shadowColor = 'rgba(' + sc[0] + ',' + sc[1] + ',' + sc[2] + ',' + sc[3] + ')';
|
|
88
|
-
if (thing.effects.shadow.blur)
|
|
98
|
+
if (thing.effects.shadow.blur) {
|
|
99
|
+
ctx.shadowBlur = thing.effects.shadow.blur;
|
|
100
|
+
shadowBlurReset = false;
|
|
101
|
+
}
|
|
89
102
|
}
|
|
90
103
|
|
|
91
|
-
if (thing.color)
|
|
104
|
+
if (thing.color) {
|
|
105
|
+
ctx.globalAlpha = thing.color[3] / 255;
|
|
106
|
+
globalAlphaReset = false;
|
|
107
|
+
}
|
|
92
108
|
|
|
93
109
|
if (thing.fill !== null && thing.fill !== undefined) {
|
|
94
110
|
ctx.fillStyle = 'rgba(' + thing.fill[0] + ',' + thing.fill[1] + ',' + thing.fill[2] + ',' + thing.fill[3] + ')';
|
|
@@ -110,15 +126,16 @@ class Renderer {
|
|
|
110
126
|
if (thing.fill !== undefined && thing.fill !== null) ctx.fill();
|
|
111
127
|
if (thing.border !== undefined && thing.border !== null) ctx.stroke();
|
|
112
128
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
129
|
+
if (!shadowBlurReset) {
|
|
130
|
+
ctx.shadowBlur = 0;
|
|
131
|
+
shadowBlurReset = true;
|
|
132
|
+
}
|
|
117
133
|
}
|
|
118
134
|
|
|
119
135
|
// --- Text ---
|
|
120
136
|
if (thing.text) {
|
|
121
137
|
ctx.globalAlpha = thing.text.color[3] / 255;
|
|
138
|
+
globalAlphaReset = false;
|
|
122
139
|
ctx.fillStyle = 'rgba(' + thing.text.color[0] + ',' + thing.text.color[1] + ',' + thing.text.color[2] + ',' + thing.text.color[3] + ')';
|
|
123
140
|
const maxTextSize = Math.floor(canvas.width);
|
|
124
141
|
const fontSize = (thing.text.size / 100) * maxTextSize;
|
|
@@ -178,7 +195,10 @@ class Renderer {
|
|
|
178
195
|
if (thing.effects && thing.effects.shadow) {
|
|
179
196
|
const sc = thing.effects.shadow.color;
|
|
180
197
|
ctx.shadowColor = 'rgba(' + sc[0] + ',' + sc[1] + ',' + sc[2] + ',' + sc[3] + ')';
|
|
181
|
-
if (thing.effects.shadow.blur)
|
|
198
|
+
if (thing.effects.shadow.blur) {
|
|
199
|
+
ctx.shadowBlur = thing.effects.shadow.blur;
|
|
200
|
+
shadowBlurReset = false;
|
|
201
|
+
}
|
|
182
202
|
}
|
|
183
203
|
|
|
184
204
|
const dx = (asset.pos.x / 100) * canvas.width;
|
|
@@ -227,11 +247,14 @@ class Renderer {
|
|
|
227
247
|
}
|
|
228
248
|
|
|
229
249
|
i += frameSize;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
250
|
+
if (!shadowBlurReset) {
|
|
251
|
+
ctx.shadowBlur = 0;
|
|
252
|
+
shadowBlurReset = true;
|
|
253
|
+
}
|
|
254
|
+
if (!globalAlphaReset) {
|
|
255
|
+
ctx.globalAlpha = 1;
|
|
256
|
+
globalAlphaReset = true;
|
|
257
|
+
}
|
|
235
258
|
}
|
|
236
259
|
|
|
237
260
|
for (const [id, player] of this.videos) {
|
|
@@ -8,7 +8,7 @@ module.exports = () => {
|
|
|
8
8
|
style.textContent = `
|
|
9
9
|
.hg-session-frame, .hg-share-dialog { font:14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,sans-serif; color:#f6f6ee; }
|
|
10
10
|
.hg-session-frame *, .hg-share-dialog * { box-sizing:border-box; }
|
|
11
|
-
.hg-session-frame { width:100%; height:100%;
|
|
11
|
+
.hg-session-frame { width:100%; height:100%; position:relative; overflow:hidden; background:#000; container-type:inline-size; }
|
|
12
12
|
.hg-session-game { flex:1; min-height:0; width:100%; position:relative; overflow:hidden; display:flex; align-items:center; background:#000; }
|
|
13
13
|
.hg-share-dialog button { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:44px; padding:0 18px; border:1px solid #4a5049; border-radius:10px; background:transparent; color:#f6f6ee; font:600 14px/1.2 system-ui,sans-serif; cursor:pointer; }
|
|
14
14
|
.hg-share-dialog .hg-share-copy { background:#fff78e; color:#22261e; }
|
package/src/squish-map.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
// dependency. Requires must stay static so webpack can bundle them.
|
|
5
5
|
|
|
6
6
|
const squishMap = {
|
|
7
|
-
'150': require('squish-150')
|
|
7
|
+
'150': require('squish-150'),
|
|
8
|
+
'151': require('squish-151')
|
|
8
9
|
};
|
|
9
10
|
|
|
10
|
-
const DEFAULT_VERSION = '
|
|
11
|
+
const DEFAULT_VERSION = '151';
|
|
11
12
|
|
|
12
13
|
module.exports = { squishMap, DEFAULT_VERSION };
|