arcadible 1.0.19 → 1.0.21

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
@@ -65,5 +65,5 @@
65
65
  "scripts": {
66
66
  "test": "node --test \"test/**/*.test.js\""
67
67
  },
68
- "version": "1.0.19"
68
+ "version": "1.0.21"
69
69
  }
@@ -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 (ui2's `screenshots()`).
39
- const SCREENSHOT = /^screenshot_(\d+)(?:_([^.]+))?\.[^.]+$/u;
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]
@@ -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.
@@ -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
- // (ui2/src/play), with the same
3
+ // (ui/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
@@ -35,8 +35,8 @@ const ICON = "/_arcadible/icon";
35
35
  // the loading screen's art and icon, PNGs, or 404 without.
36
36
  const ART = "/_arcadible/art.png";
37
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
38
+ // the loading screen's timing, as the play page's (ui/src/play/loading.ts): up at
39
+ // least the minimum, then a fade; a game that started and stops reporting
40
40
  // comes down after `STUCK` without a call; the SDK's word at load is
41
41
  // waited for `SAFETY` at most.
42
42
  const LOADING = { FADE: 300, MINIMUM: 1500, SAFETY: 2000, STUCK: 30000 };
@@ -91,8 +91,8 @@ const escapeHtml = function (text) {
91
91
 
92
92
  // [function]
93
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
94
+ // the loading screen, as the play page's (ui/src/play/play.css;
95
+ // ui/ARCHITECTURE.md, The play page's loading screen): without
96
96
  // the developer's name, which isn't known here, or the rotate prompt, since
97
97
  // arc serve listens on this machine only.
98
98
  const LOADING_CSS =
@@ -139,12 +139,12 @@ const html = function (game) {
139
139
  const frame = document.createElement("iframe");
140
140
  frame.allow = config.allow;
141
141
  frame.sandbox = config.sandbox;
142
- // the loading screen, as the play page runs it (ui2/src/play/loading.ts): decided
142
+ // the loading screen, as the play page runs it (ui/src/play/loading.ts): decided
143
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
144
+ // started; down after LOADING.MINIMUM, faded. Reloads after a save don't
145
145
  // show it again, so iterating stays instant.
146
146
  const cover = document.getElementById("loading");
147
- const loading = { begun: false, decided: false, down: false, leaving: false, reports: false, safety: 0, stuck: 0, visible: [] };
147
+ const loading = { started: false, decided: false, down: false, leaving: false, reports: false, safety: 0, stuck: 0, visible: [] };
148
148
  const gone = () => {
149
149
  if (loading.down) return;
150
150
  loading.down = true;
@@ -186,7 +186,7 @@ const html = function (game) {
186
186
  frame.addEventListener("load", () => {
187
187
  frame.focus();
188
188
  if (loading.decided) return;
189
- if (loading.reports) loading.safety = setTimeout(() => decide(loading.begun), config.loading.SAFETY);
189
+ if (loading.reports) loading.safety = setTimeout(() => decide(loading.started), config.loading.SAFETY);
190
190
  else decide(false);
191
191
  });
192
192
  // the host answers the game's hello, so it's created before the frame
@@ -200,10 +200,10 @@ const html = function (game) {
200
200
  frame,
201
201
  game: config.game,
202
202
  lifecycle: {
203
- begin: () => {
204
- loading.begun = true;
203
+ start: () => {
204
+ loading.started = true;
205
205
  },
206
- end: () => new Promise((resolve) => {
206
+ complete: () => new Promise((resolve) => {
207
207
  if (loading.down) {
208
208
  resolve();
209
209
  return;
@@ -211,9 +211,9 @@ const html = function (game) {
211
211
  loading.visible.push(resolve);
212
212
  takeDown();
213
213
  }),
214
- loaded: (begun) => {
214
+ loaded: (started) => {
215
215
  clearTimeout(loading.safety);
216
- decide(begun);
216
+ decide(started);
217
217
  },
218
218
  progress: (fraction) => {
219
219
  if (loading.down || loading.leaving) return;
@@ -20,7 +20,7 @@ const writeFile = fs.promises.writeFile;
20
20
  // [declare]
21
21
 
22
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
23
+ // deploy on the play site (ui's play build). Any number in /static/<n>/ is
24
24
  // served, and each is cached at Google's edge for a year, so a new one gets
25
25
  // the current copy. `v1` is the shape of the `arcadibleHost` global, which
26
26
  // this CLI calls: a breaking change to it is v2, beside v1.
@@ -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 (ui'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 };