@rig-c/parts 1.9.1 → 1.10.0

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/src/layers.ts CHANGED
@@ -25,6 +25,11 @@
25
25
  * and for a PSD it is the stacking order itself, with `depth` null because a
26
26
  * PSD carries none. Every refusal is collected and thrown once, so one run
27
27
  * names every missing file.
28
+ *
29
+ * A layer is named by a See-through v3 tag or, for a layer the author made
30
+ * by hand and added to the run (issue #256), by `author:<label>`
31
+ * (`src/tags.ts`, `AUTHOR_PREFIX`): read with `group` "author", it has no
32
+ * role, and its place in the draw order is read like any other layer's.
28
33
  */
29
34
  import { existsSync, readFileSync, statSync } from 'node:fs';
30
35
  import { basename, dirname, join } from 'node:path';
@@ -32,7 +37,7 @@ import { initializeCanvas, type Layer as PsdLayer, readPsd } from 'ag-psd';
32
37
  import { type Problem, refuseIfAny } from './errors.ts';
33
38
  import { decodePngBytes } from './raster/png.ts';
34
39
  import type { Raster } from './raster/types.ts';
35
- import { acceptedTagNames, readTag, type TagReading } from './tags.ts';
40
+ import { type LayerTagReading, layerTagRequirement, readLayerTag } from './tags.ts';
36
41
 
37
42
  /** Alpha strictly above this counts as painted. The reference uses the same cut for its ghost clean-up and its sheets. */
38
43
  export const OPAQUE_ALPHA_ABOVE = 8;
@@ -45,9 +50,9 @@ export const OPAQUE_ALPHA_ABOVE = 8;
45
50
  export const NEAR_WHITE_MIN = 235;
46
51
 
47
52
  export interface Layer {
48
- /** As the input names it; always a v3 tag, possibly with a `-r`/`-l` side. */
53
+ /** As the input names it: a v3 tag, possibly with a `-r`/`-l` side, or an author-made layer's `author:<label>`. */
49
54
  name: string;
50
- tag: TagReading;
55
+ tag: LayerTagReading;
51
56
  /** The file the pixels came from, or null for a PSD layer. */
52
57
  file: string | null;
53
58
  /** The layer's own pixels, `(right-left)x(bottom-top)`, straight alpha. */
@@ -197,9 +202,9 @@ export function readWrapperLayers(path: string): LayerSet {
197
202
  return;
198
203
  }
199
204
  const name = e.name;
200
- const tag = readTag(name);
205
+ const tag = readLayerTag(name);
201
206
  if (tag === null) {
202
- refuse('LAYERS_TAG_KNOWN', `layer "${name}"`, `is not a See-through v3 tag; one of ${acceptedTagNames().join(', ')} is required`);
207
+ refuse('LAYERS_TAG_KNOWN', `layer "${name}"`, layerTagRequirement(name));
203
208
  ok = false;
204
209
  }
205
210
  for (const key of ['left', 'top', 'right', 'bottom'] as const) {
@@ -369,9 +374,9 @@ export function readPsdLayers(path: string): LayerSet {
369
374
  const layers: Layer[] = [];
370
375
  leaves.forEach((layer) => {
371
376
  const name = layer.name ?? '';
372
- const tag = readTag(name);
377
+ const tag = readLayerTag(name);
373
378
  if (tag === null) {
374
- refuse('LAYERS_TAG_KNOWN', `PSD layer "${name}"`, `is not a See-through v3 tag; one of ${acceptedTagNames().join(', ')} is required`);
379
+ refuse('LAYERS_TAG_KNOWN', `PSD layer "${name}"`, layerTagRequirement(name));
375
380
  return;
376
381
  }
377
382
  if (seen.has(name)) {