arcadible 1.0.18 → 1.0.20
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 +1 -1
- package/src/action/serve/tool.js +14 -1
- package/src/action/validate/unsound.js +4 -32
- package/src/config/code.js +1 -1
- package/src/config/uri.js +3 -4
- package/src/schema/game.js +15 -1
- package/src/serve/page.js +123 -7
- package/src/serve/remote.js +9 -7
- package/src/serve/server.js +5 -2
- package/src/util/screenshot.js +37 -0
package/package.json
CHANGED
package/src/action/serve/tool.js
CHANGED
|
@@ -105,6 +105,18 @@ const storeIcon = function (root) {
|
|
|
105
105
|
|
|
106
106
|
// [function]
|
|
107
107
|
|
|
108
|
+
// the loading screen's art: the project's splash, else its banner, else its
|
|
109
|
+
// cover, as the play page picks it, or null; each time it's asked for.
|
|
110
|
+
const storeArt = function (root) {
|
|
111
|
+
return async () => {
|
|
112
|
+
const { game } = await media(root);
|
|
113
|
+
const file = game.splash ?? game.banner ?? game.cover;
|
|
114
|
+
return file ? readFile(join(root, file)) : null;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// [function]
|
|
119
|
+
|
|
108
120
|
// listens, turning a port in use into its code.
|
|
109
121
|
const listen = async function (options) {
|
|
110
122
|
try {
|
|
@@ -138,6 +150,7 @@ const main = async function (conf) {
|
|
|
138
150
|
const project = await given(conf);
|
|
139
151
|
const game = project.game;
|
|
140
152
|
const options = {
|
|
153
|
+
art: storeArt(root),
|
|
141
154
|
icon: storeIcon(root),
|
|
142
155
|
info: {
|
|
143
156
|
channel: CHANNEL,
|
|
@@ -148,8 +161,8 @@ const main = async function (conf) {
|
|
|
148
161
|
onRemote: handler.onRemote,
|
|
149
162
|
port,
|
|
150
163
|
remote: remoteFiles({
|
|
151
|
-
asset: cfguri.ARCADIBLE_ASSET,
|
|
152
164
|
dir: join(configDir(), cfgproduct.tool, "sdk"),
|
|
165
|
+
host: cfguri.HOST_HTTP_PLAY,
|
|
153
166
|
sdk: cfguri.ARCADIBLE_SDK,
|
|
154
167
|
}),
|
|
155
168
|
};
|
|
@@ -15,6 +15,7 @@ const cfgcode = require("../../config/code");
|
|
|
15
15
|
const cfgfile = require("../../config/file");
|
|
16
16
|
const output = require("../../util/output");
|
|
17
17
|
const phrase = require("../../phrase");
|
|
18
|
+
const screenshot = require("../../util/screenshot");
|
|
18
19
|
|
|
19
20
|
// [use]
|
|
20
21
|
|
|
@@ -35,8 +36,8 @@ const MEDIA = cfgfile.MEDIA;
|
|
|
35
36
|
const ART = cfgart
|
|
36
37
|
.map((file) => parse(file).name)
|
|
37
38
|
.filter((name) => !name.endsWith("_video"));
|
|
38
|
-
// a screenshot's name, as the store reads it (
|
|
39
|
-
const SCREENSHOT =
|
|
39
|
+
// a screenshot's name, as the store reads it (util/screenshot.js).
|
|
40
|
+
const SCREENSHOT = screenshot.SCREENSHOT;
|
|
40
41
|
// a name one case or separator away from a screenshot's: `Screenshot_01`,
|
|
41
42
|
// `screenshot-01`, `screenshot01`, with any qualifier after it.
|
|
42
43
|
const SCREENSHOT_NEAR = /^screenshot[-_ ]?(\d+)(?:[-_ ](.+))?$/iu;
|
|
@@ -99,30 +100,6 @@ const galleryNames = function (game) {
|
|
|
99
100
|
|
|
100
101
|
// [function]
|
|
101
102
|
|
|
102
|
-
// screenshots with one number and qualifier, such as `screenshot_1.png` and
|
|
103
|
-
// `screenshot_01.png`, which the store can show only one of.
|
|
104
|
-
const repeated = function (names) {
|
|
105
|
-
const groups = {};
|
|
106
|
-
for (const name of names) {
|
|
107
|
-
const match = SCREENSHOT.exec(name);
|
|
108
|
-
if (match) {
|
|
109
|
-
const key = `${Number(match[1])}_${match[2] ?? ""}`;
|
|
110
|
-
groups[key] = [...(groups[key] ?? []), name];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return Object.values(groups)
|
|
114
|
-
.filter((group) => group.length > 1)
|
|
115
|
-
.map((group) =>
|
|
116
|
-
warning(
|
|
117
|
-
WARNING.SCREENSHOT_NUMBER_REPEATED,
|
|
118
|
-
"game.gallery",
|
|
119
|
-
phrase.screenshotNumberRepeated(group),
|
|
120
|
-
),
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// [function]
|
|
125
|
-
|
|
126
103
|
// a gallery file named almost as a screenshot, with the name it might mean.
|
|
127
104
|
const misnamed = function (names) {
|
|
128
105
|
return names.flatMap((name) => {
|
|
@@ -153,12 +130,7 @@ const misnamed = function (names) {
|
|
|
153
130
|
const main = function (proj) {
|
|
154
131
|
const game = proj?.game ?? {};
|
|
155
132
|
const names = galleryNames(game);
|
|
156
|
-
return [
|
|
157
|
-
...unset(game),
|
|
158
|
-
...unpaired(game),
|
|
159
|
-
...repeated(names),
|
|
160
|
-
...misnamed(names),
|
|
161
|
-
];
|
|
133
|
+
return [...unset(game), ...unpaired(game), ...misnamed(names)];
|
|
162
134
|
};
|
|
163
135
|
|
|
164
136
|
// [export]
|
package/src/config/code.js
CHANGED
|
@@ -91,6 +91,7 @@ const ISSUE = {
|
|
|
91
91
|
OUT_OF_RANGE: "out_of_range",
|
|
92
92
|
PATH_INVALID: "path_invalid",
|
|
93
93
|
REQUIRED: "required",
|
|
94
|
+
SCREENSHOT_NUMBER_REPEATED: "screenshot_number_repeated",
|
|
94
95
|
TOO_LONG: "too_long",
|
|
95
96
|
TOO_MANY: "too_many",
|
|
96
97
|
TOO_SHORT: "too_short",
|
|
@@ -112,7 +113,6 @@ const WARNING = {
|
|
|
112
113
|
PACKAGE_FILE_DEV: "package_file_dev",
|
|
113
114
|
PACKAGE_FILE_PRIVATE: "package_file_private",
|
|
114
115
|
SCREENSHOT_NAME_INVALID: "screenshot_name_invalid",
|
|
115
|
-
SCREENSHOT_NUMBER_REPEATED: "screenshot_number_repeated",
|
|
116
116
|
VERSION_UNCHECKED: "version_unchecked",
|
|
117
117
|
};
|
|
118
118
|
// every error code, for checking one exists.
|
package/src/config/uri.js
CHANGED
|
@@ -12,10 +12,9 @@ const PROTOCOL = cfgproduct.protocol;
|
|
|
12
12
|
// [export]
|
|
13
13
|
|
|
14
14
|
module.exports = {
|
|
15
|
-
// where arc serve fetches
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
ARCADIBLE_ASSET: "https://asset.offst.net",
|
|
15
|
+
// a build origin, where arc serve fetches the SDK's hosted script
|
|
16
|
+
// (src/serve/remote.js): any of them serves it at /arcadible/sdk/. The play
|
|
17
|
+
// page's host comes from the play site, HOST_HTTP_PLAY.
|
|
19
18
|
ARCADIBLE_SDK: `https://sdk.${cfgproduct.handle}.io`,
|
|
20
19
|
HOST_APP_PLAY: `${PROTOCOL}://play`,
|
|
21
20
|
HOST_APP_STORE: `${PROTOCOL}://store`,
|
package/src/schema/game.js
CHANGED
|
@@ -27,6 +27,7 @@ const check = require("./check/game");
|
|
|
27
27
|
const paths = require("../util/paths");
|
|
28
28
|
const phrase = require("../phrase");
|
|
29
29
|
const schemaMessage = require("./message");
|
|
30
|
+
const screenshot = require("../util/screenshot");
|
|
30
31
|
const size = require("../util/size");
|
|
31
32
|
const uris = require("../util/uris");
|
|
32
33
|
|
|
@@ -430,6 +431,8 @@ const zDescription = function (root) {
|
|
|
430
431
|
|
|
431
432
|
// [function]
|
|
432
433
|
|
|
434
|
+
// the gallery, and no two screenshots of one number and qualifier, since
|
|
435
|
+
// the store shows one screenshot a number (the developer docs, Screenshots).
|
|
433
436
|
const zGallery = function (root) {
|
|
434
437
|
const field = "gallery";
|
|
435
438
|
return z.optional(
|
|
@@ -442,7 +445,18 @@ const zGallery = function (root) {
|
|
|
442
445
|
{ ...GALLERY_DIMENSIONS, maxSize: MAX_SIZE_MP4 },
|
|
443
446
|
),
|
|
444
447
|
{ max: 8 * 3, min: 1 },
|
|
445
|
-
),
|
|
448
|
+
).superRefine((files, ctx) => {
|
|
449
|
+
for (const group of screenshot.repeated(files)) {
|
|
450
|
+
ctx.addIssue({
|
|
451
|
+
code: "custom",
|
|
452
|
+
...message(
|
|
453
|
+
field,
|
|
454
|
+
phrase.screenshotNumberRepeated(group),
|
|
455
|
+
ISSUE.SCREENSHOT_NUMBER_REPEATED,
|
|
456
|
+
),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}),
|
|
446
460
|
);
|
|
447
461
|
};
|
|
448
462
|
|
package/src/serve/page.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// the local play page: it frames the game as the play page does
|
|
3
|
-
// (
|
|
3
|
+
// (ui2/src/play), with the same
|
|
4
4
|
// sandbox and permissions, and runs the play page's own host for the SDK,
|
|
5
5
|
// so saves are kept by the page, across builds. It reloads the
|
|
6
6
|
// game, and only the game, when told to. Its tab shows the game's store
|
|
@@ -32,6 +32,14 @@ const SANDBOX =
|
|
|
32
32
|
const HOST = "/_arcadible/host.js";
|
|
33
33
|
const RELOAD = "/_arcadible/reload";
|
|
34
34
|
const ICON = "/_arcadible/icon";
|
|
35
|
+
// the loading screen's art and icon, PNGs, or 404 without.
|
|
36
|
+
const ART = "/_arcadible/art.png";
|
|
37
|
+
const ICON_PNG = "/_arcadible/icon.png";
|
|
38
|
+
// the loading screen's timing, as the play page's (ui2/src/play/loading.ts): up at
|
|
39
|
+
// least the minimum, then a fade; a game that began and stops reporting
|
|
40
|
+
// comes down after `STUCK` without a call; the SDK's word at load is
|
|
41
|
+
// waited for `SAFETY` at most.
|
|
42
|
+
const LOADING = { FADE: 300, MINIMUM: 1500, SAFETY: 2000, STUCK: 30000 };
|
|
35
43
|
// the play page's own favicon.ico (app/src/web/arcadible-play/content), for a
|
|
36
44
|
// game without a store icon, and for /favicon.ico, which browsers ask for.
|
|
37
45
|
const FAVICON = join(__dirname, "favicon.ico");
|
|
@@ -83,13 +91,25 @@ const escapeHtml = function (text) {
|
|
|
83
91
|
|
|
84
92
|
// [function]
|
|
85
93
|
|
|
94
|
+
// the loading screen, as the play page's (ui2/src/play/play.css;
|
|
95
|
+
// ui2/ARCHITECTURE.md, The play page's loading screen): without
|
|
96
|
+
// the developer's name, which isn't known here, or the rotate prompt, since
|
|
97
|
+
// arc serve listens on this machine only.
|
|
98
|
+
const LOADING_CSS =
|
|
99
|
+
".loading{position:fixed;inset:0;z-index:2;overflow:hidden;pointer-events:none;background:#000;color:#fff;font-family:system-ui,-apple-system,'Segoe UI',sans-serif;transition:opacity 300ms ease}.loading-fading{opacity:0}.loading-gone{display:none}.loading-art{position:absolute;inset:0;inline-size:100%;block-size:100%;object-fit:cover;opacity:0;transition:opacity 400ms ease}.loading-scrim{position:absolute;inset:0;opacity:0;background:linear-gradient(to top,rgba(0,0,0,.8) 0%,rgba(0,0,0,.36) 32%,rgba(0,0,0,0) 58%);transition:opacity 400ms ease}.loading-info{position:absolute;inset-inline:28px;inset-block-end:30px;display:flex;align-items:center;column-gap:14px;opacity:0;transition:opacity 400ms ease}.loading-arrived .loading-art,.loading-arrived .loading-scrim,.loading-arrived .loading-info,.loading-bare .loading-scrim,.loading-bare .loading-info{opacity:1}.loading-bare{background:#141618}.loading-icon{inline-size:64px;block-size:64px;border-radius:22%;flex:none}.loading-title{margin:0;font-size:24px;font-weight:600;letter-spacing:-.02em;line-height:1.15;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.loading-bar{position:absolute;inset-inline:0;inset-block-end:0;block-size:4px;overflow:hidden;background:rgba(255,255,255,.18)}.loading-fill{inline-size:25%;block-size:100%;background:rgba(255,255,255,.85);animation:loading-sweep 1.6s cubic-bezier(.45,0,.55,1) infinite}.loading-counting .loading-fill{animation:none;background:#fff;transition:inline-size 400ms ease-out}@media (max-height:359px){.loading-info{inset-inline:18px;inset-block-end:20px;column-gap:12px}.loading-icon{inline-size:44px;block-size:44px}.loading-title{font-size:18px}.loading-bar{block-size:3px}}@media (min-width:1024px) and (min-height:600px){.loading-info{inset-inline:48px;inset-block-end:44px;column-gap:20px}.loading-icon{inline-size:88px;block-size:88px}.loading-title{font-size:32px}}@media (prefers-reduced-motion:reduce){.loading-fill{animation:none;inline-size:100%;opacity:.45}.loading-counting .loading-fill{opacity:1}}@keyframes loading-sweep{0%{transform:translateX(-100%)}100%{transform:translateX(400%)}}";
|
|
100
|
+
|
|
101
|
+
// [function]
|
|
102
|
+
|
|
86
103
|
// the page for `game`: `{ id, channel, version, title, src }`, where `src` is
|
|
87
104
|
// the game's URL, on its own origin.
|
|
88
105
|
const html = function (game) {
|
|
89
106
|
const config = {
|
|
90
107
|
allow: ALLOW,
|
|
108
|
+
art: ART,
|
|
91
109
|
channel: game.channel,
|
|
92
110
|
game: game.id,
|
|
111
|
+
icon: ICON_PNG,
|
|
112
|
+
loading: LOADING,
|
|
93
113
|
sandbox: SANDBOX,
|
|
94
114
|
src: game.src,
|
|
95
115
|
version: game.version,
|
|
@@ -101,18 +121,73 @@ const html = function (game) {
|
|
|
101
121
|
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
|
|
102
122
|
<title>${escapeHtml(game.title)}</title>
|
|
103
123
|
<link href="${ICON}" rel="icon">
|
|
104
|
-
<style>html,body{margin:0;height:100%;overflow:hidden;background:#000}iframe{display:block;width:100%;height:100%;border:0
|
|
124
|
+
<style>html,body{margin:0;height:100%;overflow:hidden;background:#000}iframe{display:block;width:100%;height:100%;border:0}${LOADING_CSS}</style>
|
|
105
125
|
</head>
|
|
106
126
|
<body>
|
|
127
|
+
<div class="loading" id="loading">
|
|
128
|
+
<img alt="" class="loading-art" id="loading-art">
|
|
129
|
+
<div class="loading-scrim"></div>
|
|
130
|
+
<div class="loading-info">
|
|
131
|
+
<img alt="" class="loading-icon" id="loading-icon">
|
|
132
|
+
<p class="loading-title">${escapeHtml(game.title)}</p>
|
|
133
|
+
</div>
|
|
134
|
+
<div aria-label="Loading ${escapeHtml(game.title)}" aria-valuemax="100" aria-valuemin="0" class="loading-bar" id="loading-bar" role="progressbar"><div class="loading-fill" id="loading-fill"></div></div>
|
|
135
|
+
</div>
|
|
107
136
|
<script src="${HOST}"></script>
|
|
108
137
|
<script>
|
|
109
138
|
const config = ${scriptJson(config)};
|
|
110
139
|
const frame = document.createElement("iframe");
|
|
111
140
|
frame.allow = config.allow;
|
|
112
141
|
frame.sandbox = config.sandbox;
|
|
142
|
+
// the loading screen, as the play page runs it (ui2/src/play/loading.ts): decided
|
|
143
|
+
// once, at the first load, from whether the game's SDK can report and
|
|
144
|
+
// began; down after LOADING.MINIMUM, faded. Reloads after a save don't
|
|
145
|
+
// show it again, so iterating stays instant.
|
|
146
|
+
const cover = document.getElementById("loading");
|
|
147
|
+
const loading = { begun: false, decided: false, down: false, leaving: false, reports: false, safety: 0, stuck: 0, visible: [] };
|
|
148
|
+
const gone = () => {
|
|
149
|
+
if (loading.down) return;
|
|
150
|
+
loading.down = true;
|
|
151
|
+
cover.classList.add("loading-gone");
|
|
152
|
+
for (const resolve of loading.visible) resolve();
|
|
153
|
+
loading.visible = [];
|
|
154
|
+
};
|
|
155
|
+
const takeDown = () => {
|
|
156
|
+
if (loading.down || loading.leaving) return;
|
|
157
|
+
loading.leaving = loading.decided = true;
|
|
158
|
+
clearTimeout(loading.stuck);
|
|
159
|
+
clearTimeout(loading.safety);
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
cover.classList.add("loading-fading");
|
|
162
|
+
setTimeout(gone, config.loading.FADE);
|
|
163
|
+
}, Math.max(0, config.loading.MINIMUM - performance.now()));
|
|
164
|
+
};
|
|
165
|
+
const armStuck = () => {
|
|
166
|
+
clearTimeout(loading.stuck);
|
|
167
|
+
if (!loading.down && !loading.leaving) loading.stuck = setTimeout(takeDown, config.loading.STUCK);
|
|
168
|
+
};
|
|
169
|
+
const decide = (keep) => {
|
|
170
|
+
if (loading.decided) return;
|
|
171
|
+
loading.decided = true;
|
|
172
|
+
if (keep) armStuck();
|
|
173
|
+
else takeDown();
|
|
174
|
+
};
|
|
175
|
+
// a frame that never loads mustn't keep it up.
|
|
176
|
+
setTimeout(() => decide(false), config.loading.STUCK);
|
|
177
|
+
const art = document.getElementById("loading-art");
|
|
178
|
+
// shown once decoded, so the title never shows before the art.
|
|
179
|
+
const arrive = () => cover.classList.add("loading-arrived");
|
|
180
|
+
art.addEventListener("load", () => art.decode().then(arrive, arrive));
|
|
181
|
+
art.addEventListener("error", () => cover.classList.add("loading-bare"));
|
|
182
|
+
art.src = config.art;
|
|
183
|
+
const icon = document.getElementById("loading-icon");
|
|
184
|
+
icon.addEventListener("error", () => icon.remove());
|
|
185
|
+
icon.src = config.icon;
|
|
113
186
|
frame.addEventListener("load", () => {
|
|
114
|
-
frame.style.visibility = "visible";
|
|
115
187
|
frame.focus();
|
|
188
|
+
if (loading.decided) return;
|
|
189
|
+
if (loading.reports) loading.safety = setTimeout(() => decide(loading.begun), config.loading.SAFETY);
|
|
190
|
+
else decide(false);
|
|
116
191
|
});
|
|
117
192
|
// the host answers the game's hello, so it's created before the frame
|
|
118
193
|
// exists. Without it, the game stands alone, as off Arcadible.
|
|
@@ -124,19 +199,45 @@ const html = function (game) {
|
|
|
124
199
|
channel: config.channel,
|
|
125
200
|
frame,
|
|
126
201
|
game: config.game,
|
|
202
|
+
lifecycle: {
|
|
203
|
+
begin: () => {
|
|
204
|
+
loading.begun = true;
|
|
205
|
+
},
|
|
206
|
+
end: () => new Promise((resolve) => {
|
|
207
|
+
if (loading.down) {
|
|
208
|
+
resolve();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
loading.visible.push(resolve);
|
|
212
|
+
takeDown();
|
|
213
|
+
}),
|
|
214
|
+
loaded: (begun) => {
|
|
215
|
+
clearTimeout(loading.safety);
|
|
216
|
+
decide(begun);
|
|
217
|
+
},
|
|
218
|
+
progress: (fraction) => {
|
|
219
|
+
if (loading.down || loading.leaving) return;
|
|
220
|
+
cover.classList.add("loading-counting");
|
|
221
|
+
document.getElementById("loading-fill").style.inlineSize = fraction * 100 + "%";
|
|
222
|
+
document.getElementById("loading-bar").setAttribute("aria-valuenow", String(Math.round(fraction * 100)));
|
|
223
|
+
if (loading.decided) armStuck();
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
onHello: (hello) => {
|
|
227
|
+
loading.reports = Boolean(lib.reportsInit && lib.reportsInit(hello.client));
|
|
228
|
+
},
|
|
127
229
|
origin: new URL(config.src).origin,
|
|
128
230
|
version: config.version,
|
|
129
231
|
});
|
|
130
232
|
} catch (err) {
|
|
131
|
-
console.error("Arcadible
|
|
233
|
+
console.error("Arcadible: the play page couldn't host the game, so it stands alone.", err);
|
|
132
234
|
}
|
|
133
235
|
} else {
|
|
134
|
-
console.error("Arcadible
|
|
236
|
+
console.error("Arcadible: the play page's host didn't load, so the game stands alone.");
|
|
135
237
|
}
|
|
136
238
|
frame.src = config.src;
|
|
137
239
|
document.body.prepend(frame);
|
|
138
240
|
new EventSource(${scriptJson(RELOAD)}).addEventListener("reload", () => {
|
|
139
|
-
frame.style.visibility = "hidden";
|
|
140
241
|
frame.src = config.src;
|
|
141
242
|
});
|
|
142
243
|
</script>
|
|
@@ -149,8 +250,9 @@ const html = function (game) {
|
|
|
149
250
|
|
|
150
251
|
// the request handler for the page's origin. `reloads` keeps the pages
|
|
151
252
|
// listening for a reload; `remote` has the host; `icon()` resolves with the
|
|
152
|
-
// game's store icon, or null.
|
|
253
|
+
// game's store icon, and `art()` with its loading screen's art, or null.
|
|
153
254
|
const pageHandler = function ({
|
|
255
|
+
art = () => Promise.resolve(null),
|
|
154
256
|
game,
|
|
155
257
|
icon = () => Promise.resolve(null),
|
|
156
258
|
onRemote = () => null,
|
|
@@ -185,6 +287,20 @@ const pageHandler = function ({
|
|
|
185
287
|
endWith(req, res, body);
|
|
186
288
|
});
|
|
187
289
|
}
|
|
290
|
+
if (pathname === ART || pathname === ICON_PNG) {
|
|
291
|
+
// read for each request, so art added while serving shows on the next
|
|
292
|
+
// load.
|
|
293
|
+
return (pathname === ART ? art() : icon())
|
|
294
|
+
.catch(() => null)
|
|
295
|
+
.then((png) => {
|
|
296
|
+
if (!png) {
|
|
297
|
+
res.writeHead(404, HEADERS).end();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
res.writeHead(200, { ...HEADERS, "content-type": "image/png" });
|
|
301
|
+
endWith(req, res, png);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
188
304
|
if (pathname === "/favicon.ico") {
|
|
189
305
|
return readFavicon().then((body) => {
|
|
190
306
|
res.writeHead(200, { ...HEADERS, "content-type": "image/x-icon" });
|
package/src/serve/remote.js
CHANGED
|
@@ -19,10 +19,12 @@ const writeFile = fs.promises.writeFile;
|
|
|
19
19
|
|
|
20
20
|
// [declare]
|
|
21
21
|
|
|
22
|
-
// the play page's host, published with each web
|
|
23
|
-
// site's
|
|
24
|
-
// is cached at Google's edge for a year, so a new one gets
|
|
25
|
-
|
|
22
|
+
// the play page's host, as the play page runs it, published with each web
|
|
23
|
+
// deploy on the play site (ui2's play build). Any number in /static/<n>/ is
|
|
24
|
+
// served, and each is cached at Google's edge for a year, so a new one gets
|
|
25
|
+
// the current copy. `v1` is the shape of the `arcadibleHost` global, which
|
|
26
|
+
// this CLI calls: a breaking change to it is v2, beside v1.
|
|
27
|
+
const HOST_PATH = "/asset/host.v1.min.js";
|
|
26
28
|
// the files under /arcadible/ that Arcadible serves: the SDK's, such as
|
|
27
29
|
// sdk/v1.js. Anything else there isn't found, as on Arcadible.
|
|
28
30
|
const SDK_PATH = /^sdk\/[\w.-]+$/u;
|
|
@@ -59,17 +61,17 @@ const keep = async function (dir, name, { body, ...meta }) {
|
|
|
59
61
|
|
|
60
62
|
// [function]
|
|
61
63
|
|
|
62
|
-
// the files from Arcadible. `
|
|
64
|
+
// the files from Arcadible. `host` is the play site's origin, `sdk` an
|
|
63
65
|
// origin that serves /arcadible/sdk/, and `dir` where copies are kept.
|
|
64
66
|
// `get(name)` resolves with `{ body, type, fetchedAt, kept }`, where `kept`
|
|
65
67
|
// says the copy is from disk because Arcadible couldn't be reached, or null
|
|
66
68
|
// when Arcadible has no such file; it rejects when Arcadible can't be reached
|
|
67
69
|
// and there's no copy. `name` is `host`, or a path under /arcadible/.
|
|
68
|
-
const remoteFiles = function ({
|
|
70
|
+
const remoteFiles = function ({ dir, host, request = fetch, sdk }) {
|
|
69
71
|
const session = {};
|
|
70
72
|
const url = function (name) {
|
|
71
73
|
if (name === "host") {
|
|
72
|
-
return `${
|
|
74
|
+
return `${host}/static/${Date.now()}${HOST_PATH}`;
|
|
73
75
|
}
|
|
74
76
|
return SDK_PATH.test(name) ? `${sdk}/arcadible/${name}` : null;
|
|
75
77
|
};
|
package/src/serve/server.js
CHANGED
|
@@ -45,12 +45,14 @@ const listen = function (handler, port, address) {
|
|
|
45
45
|
// [function]
|
|
46
46
|
|
|
47
47
|
// starts serving `files` for `info`, `{ id, channel, version, title }`, on
|
|
48
|
-
// `port`, with Arcadible's own files from `remote`,
|
|
49
|
-
// `icon()`,
|
|
48
|
+
// `port`, with Arcadible's own files from `remote`, the tab's icon from
|
|
49
|
+
// `icon()`, and the loading screen's art from `art()`, which each resolve
|
|
50
|
+
// with a PNG or null. With `src`, another
|
|
50
51
|
// server's page, it frames that instead, and serves no files. Resolves with
|
|
51
52
|
// `{ page, game, reload(), close() }`: the page's origin, the game's URL,
|
|
52
53
|
// and the controls.
|
|
53
54
|
const serve = async function ({
|
|
55
|
+
art,
|
|
54
56
|
files,
|
|
55
57
|
icon,
|
|
56
58
|
info,
|
|
@@ -69,6 +71,7 @@ const serve = async function ({
|
|
|
69
71
|
? gameHandler({ files, onRemote, page: origins.page, remote })
|
|
70
72
|
: null;
|
|
71
73
|
const forPage = pageHandler({
|
|
74
|
+
art,
|
|
72
75
|
game: { ...info, src: framed },
|
|
73
76
|
icon,
|
|
74
77
|
onRemote,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// [import]
|
|
4
|
+
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
|
|
7
|
+
// [use]
|
|
8
|
+
|
|
9
|
+
const posixBasename = path.posix.basename;
|
|
10
|
+
|
|
11
|
+
// [declare]
|
|
12
|
+
|
|
13
|
+
// a screenshot's name, as the store reads it (ui2's `screenshots()`): its
|
|
14
|
+
// number, and its qualifier, the platform it's for, if any.
|
|
15
|
+
const SCREENSHOT = /^screenshot_(\d+)(?:_([^.]+))?\.[^.]+$/u;
|
|
16
|
+
|
|
17
|
+
// [function]
|
|
18
|
+
|
|
19
|
+
// the gallery's screenshots that share a number and a qualifier, such as
|
|
20
|
+
// `screenshot_1.png` and `screenshot_01.png`, which the store can show only
|
|
21
|
+
// one of, as lists of their file names; a number read as a number, so its
|
|
22
|
+
// padding doesn't matter.
|
|
23
|
+
const repeated = function (files) {
|
|
24
|
+
const groups = {};
|
|
25
|
+
for (const name of files.map((file) => posixBasename(file))) {
|
|
26
|
+
const match = SCREENSHOT.exec(name);
|
|
27
|
+
if (match) {
|
|
28
|
+
const key = `${Number(match[1])}_${match[2] ?? ""}`;
|
|
29
|
+
groups[key] = [...(groups[key] ?? []), name];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return Object.values(groups).filter((group) => group.length > 1);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// [export]
|
|
36
|
+
|
|
37
|
+
module.exports = { SCREENSHOT, repeated };
|