arcadible 1.0.19 → 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 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.20"
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
 
@@ -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 };