pixelkiln 0.140.0 → 0.142.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/dist/cli.js CHANGED
@@ -3522,6 +3522,25 @@ var AssetSchema = z.object({
3522
3522
  });
3523
3523
  var DEFAULT_HISTORY_LIMIT = 5;
3524
3524
  var HistoryLimitSchema = z.number().int().min(0).max(100);
3525
+ var ParallaxRunSpriteSchema = z.object({
3526
+ asset: z.string().min(1).optional(),
3527
+ /** The style the asset was generated under, when it was generated under more than one. */
3528
+ style: z.string().min(1).optional(),
3529
+ file: z.string().min(1).optional()
3530
+ }).strict().superRefine((sprite, ctx) => {
3531
+ if (sprite.asset === void 0 === (sprite.file === void 0)) {
3532
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "a run sprite needs exactly one of asset or file" });
3533
+ }
3534
+ if (sprite.style !== void 0 && sprite.asset === void 0) {
3535
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["style"], message: "style only applies to an asset sprite" });
3536
+ }
3537
+ });
3538
+ var RUN_ONLY = ["seed", "step", "gap", "jitter", "width"];
3539
+ var ParallaxTintSchema = z.object({
3540
+ color: HexColorSchema,
3541
+ /** 0 leaves the picture as it is; 1 makes every pixel the colour, snapped. */
3542
+ amount: z.number().min(0).max(1)
3543
+ }).strict();
3525
3544
  var ParallaxLayerSchema = z.object({
3526
3545
  /** Names the layer in exports; defaults to the asset id, the file name, or "sky". */
3527
3546
  name: z.string().regex(/^[A-Za-z][A-Za-z0-9_-]*$/, "letters, digits, - and _, starting with a letter").optional(),
@@ -3533,6 +3552,22 @@ var ParallaxLayerSchema = z.object({
3533
3552
  file: z.string().min(1).optional(),
3534
3553
  /** Flat colour bands, top to bottom, with a dithered step between neighbours. */
3535
3554
  sky: z.array(HexColorSchema).min(1).max(64).optional(),
3555
+ /**
3556
+ * Isolated silhouettes laid left to right in an overlapping run, each
3557
+ * flipped at random and never the same one twice in a row, so a long
3558
+ * level never shows the same stretch twice.
3559
+ */
3560
+ run: z.array(ParallaxRunSpriteSchema).min(1).max(32).optional(),
3561
+ /** Seeds a run's layout; the same seed lays the same run. Defaults to one taken from the layer's name. */
3562
+ seed: z.number().int().min(0).max(2 ** 32 - 1).optional(),
3563
+ /** How far across one sprite the next starts, as a fraction of its width; 0.72 by default. */
3564
+ step: z.number().min(0.1).max(2).optional(),
3565
+ /** Up to this many more pixels between sprites, at random; 16 by default. */
3566
+ gap: z.number().int().min(0).max(4096).optional(),
3567
+ /** Moves each sprite's foot up or down by up to this many pixels; 0 by default. */
3568
+ jitter: z.number().int().min(0).max(256).optional(),
3569
+ /** The run's length in pixels; by default as much as the camera sees of the layer. */
3570
+ width: z.number().int().min(1).max(1e5).optional(),
3536
3571
  speed: z.number().min(0).max(4),
3537
3572
  /** Vertical speed; 1, moving with the level, when the set does not climb. */
3538
3573
  speedY: z.number().min(0).max(4).optional(),
@@ -3549,15 +3584,37 @@ var ParallaxLayerSchema = z.object({
3549
3584
  /** Repeat sideways (the default) so the layer loops. */
3550
3585
  repeat: z.boolean().optional(),
3551
3586
  /** Repeat vertically, for an endless climb. */
3552
- repeatY: z.boolean().optional()
3587
+ repeatY: z.boolean().optional(),
3588
+ /**
3589
+ * Trim the picture to its opaque box, then thin out this fraction of it
3590
+ * from the bottom with a 4x4 ordered dither, so its foot dissolves into
3591
+ * what is behind it. A layer that repeats sideways keeps its width. In a
3592
+ * run, each sprite is trimmed and thinned before it is laid.
3593
+ */
3594
+ foot: z.number().gt(0).max(1).optional(),
3595
+ /** Pull the picture (each sprite of a run) toward a colour and snap it to the set's palette. Applied after `foot`. */
3596
+ tint: ParallaxTintSchema.optional()
3553
3597
  }).strict().superRefine((layer, ctx) => {
3554
- const sources = [layer.asset, layer.file, layer.sky].filter((value) => value !== void 0).length;
3598
+ const sources = [layer.asset, layer.file, layer.sky, layer.run].filter((value) => value !== void 0).length;
3555
3599
  if (sources !== 1) {
3556
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: "a layer needs exactly one of asset, file, or sky" });
3600
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "a layer needs exactly one of asset, file, sky, or run" });
3601
+ }
3602
+ if (layer.run === void 0) {
3603
+ for (const key3 of RUN_ONLY) {
3604
+ if (layer[key3] !== void 0) ctx.addIssue({ code: z.ZodIssueCode.custom, path: [key3], message: `${key3} only applies to a run layer` });
3605
+ }
3557
3606
  }
3558
3607
  if (layer.style !== void 0 && layer.asset === void 0) {
3559
3608
  ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["style"], message: "style only applies to an asset layer" });
3560
3609
  }
3610
+ if (layer.sky !== void 0) {
3611
+ for (const key3 of ["foot", "tint"]) {
3612
+ if (layer[key3] !== void 0) ctx.addIssue({ code: z.ZodIssueCode.custom, path: [key3], message: `${key3} does not apply to a sky layer` });
3613
+ }
3614
+ }
3615
+ if (layer.foot !== void 0 && layer.extend !== void 0) {
3616
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["extend"], message: "extend repeats the bottom row, which foot thins out; use one or the other" });
3617
+ }
3561
3618
  });
3562
3619
  var ParallaxSetSchema = z.object({
3563
3620
  /** The game's view in pixels, [width, height]. */
@@ -3566,6 +3623,12 @@ var ParallaxSetSchema = z.object({
3566
3623
  travel: z.number().int().min(0).max(1e5).optional(),
3567
3624
  /** How far the camera climbs, in pixels. */
3568
3625
  climb: z.number().int().min(0).max(1e5).optional(),
3626
+ /**
3627
+ * What a layer's `tint` snaps to: a style id, for that style's palette, or
3628
+ * a list of colours. Without one, a tint snaps to the colours already in
3629
+ * the picture, so it adds none.
3630
+ */
3631
+ palette: z.union([z.string().min(1), z.array(HexColorSchema).min(2).max(256)]).optional(),
3569
3632
  layers: z.array(ParallaxLayerSchema).min(1).max(32)
3570
3633
  }).strict();
3571
3634
  var ParallaxSetIdSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/, "a set id is letters, digits, - and _, starting with a letter or digit");
@@ -16585,17 +16648,25 @@ ${issues}`);
16585
16648
  for (const assetId of Object.keys(parsed.data.assets)) visitConnections(assetId);
16586
16649
  for (const [setId, set] of Object.entries(parsed.data.parallax ?? {})) {
16587
16650
  const names = /* @__PURE__ */ new Set();
16651
+ if (typeof set.palette === "string") {
16652
+ const style = parsed.data.styles[set.palette];
16653
+ if (!style) unknownReferences.push(`parallax.${setId}.palette: unknown style "${set.palette}"`);
16654
+ else if (style.palette.length < 2) unknownReferences.push(`parallax.${setId}.palette: style "${set.palette}" has no palette`);
16655
+ }
16588
16656
  set.layers.forEach((layer, index) => {
16589
16657
  const at2 = `parallax.${setId}.layers.${index}`;
16590
- if (layer.asset !== void 0) {
16591
- const asset = parsed.data.assets[layer.asset];
16592
- if (!asset) unknownReferences.push(`${at2}.asset: unknown asset "${layer.asset}"`);
16593
- else if (layer.style !== void 0 && !asset.styles.includes(layer.style)) {
16594
- unknownReferences.push(`${at2}.style: asset "${layer.asset}" is not generated under style "${layer.style}"`);
16595
- } else if (layer.style === void 0 && asset.styles.length > 1) {
16596
- unknownReferences.push(`${at2}.style: asset "${layer.asset}" has ${asset.styles.length} styles; name one`);
16658
+ const checkAsset = (where, ref) => {
16659
+ if (ref.asset === void 0) return;
16660
+ const asset = parsed.data.assets[ref.asset];
16661
+ if (!asset) unknownReferences.push(`${where}.asset: unknown asset "${ref.asset}"`);
16662
+ else if (ref.style !== void 0 && !asset.styles.includes(ref.style)) {
16663
+ unknownReferences.push(`${where}.style: asset "${ref.asset}" is not generated under style "${ref.style}"`);
16664
+ } else if (ref.style === void 0 && asset.styles.length > 1) {
16665
+ unknownReferences.push(`${where}.style: asset "${ref.asset}" has ${asset.styles.length} styles; name one`);
16597
16666
  }
16598
- }
16667
+ };
16668
+ checkAsset(at2, layer);
16669
+ layer.run?.forEach((sprite, n) => checkAsset(`${at2}.run.${n}`, sprite));
16599
16670
  if (layer.name !== void 0) {
16600
16671
  if (names.has(layer.name)) unknownReferences.push(`${at2}.name: "${layer.name}" is used twice`);
16601
16672
  names.add(layer.name);
@@ -35595,6 +35666,11 @@ import { readFile as readFile50 } from "fs/promises";
35595
35666
  import path73 from "path";
35596
35667
  var PARALLAX_FORMATS = ["tiled", "godot", "ldtk"];
35597
35668
  var SEAM_WARN_RATIO = 2;
35669
+ function layerFiles(layer) {
35670
+ if (layer.source.kind === "sky") return [];
35671
+ if (layer.source.kind === "run") return layer.source.sprites.map((sprite) => sprite.path);
35672
+ return [layer.source.path];
35673
+ }
35598
35674
  var BAYER4 = [
35599
35675
  [0, 8, 2, 10],
35600
35676
  [12, 4, 14, 6],
@@ -35656,7 +35732,7 @@ function seamRatio(png) {
35656
35732
  }
35657
35733
  function layerName(layer, index) {
35658
35734
  if (layer.name) return layer.name;
35659
- const base = layer.asset ?? (layer.file ? path73.basename(layer.file, path73.extname(layer.file)) : "sky");
35735
+ const base = layer.asset ?? (layer.file ? path73.basename(layer.file, path73.extname(layer.file)) : layer.run ? "run" : "sky");
35660
35736
  const slug3 = base.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[^A-Za-z]+/, "");
35661
35737
  return slug3 || `layer${index + 1}`;
35662
35738
  }
@@ -35672,34 +35748,33 @@ async function resolveParallaxSet(manifest, manifestDir, lock, setId) {
35672
35748
  const warnings = [];
35673
35749
  const layers = [];
35674
35750
  const taken = /* @__PURE__ */ new Set();
35751
+ const palette = typeof set.palette === "string" ? manifest.styles[set.palette]?.palette : set.palette;
35752
+ if (set.palette !== void 0 && !palette?.length) throw new Error(`parallax ${setId}: style "${set.palette}" has no palette`);
35675
35753
  for (const [index, layer] of set.layers.entries()) {
35676
35754
  let name = layerName(layer, index);
35677
35755
  for (let n = 2; taken.has(name); n++) name = `${layerName(layer, index)}_${n}`;
35678
35756
  taken.add(name);
35679
35757
  const speedY = layer.speedY ?? (climb > 0 ? layer.speed : 1);
35758
+ const repeat = layer.repeat ?? true;
35759
+ const finish = (picture, keepWidth) => finishPicture(picture, { foot: layer.foot, tint: layer.tint, palette, keepWidth }, `parallax ${setId}: ${name}`);
35680
35760
  let png;
35681
35761
  let source;
35682
35762
  if (layer.sky) {
35683
35763
  png = skyBands(viewW, viewH + Math.ceil(climb * speedY), layer.sky);
35684
35764
  source = { kind: "sky", colors: layer.sky };
35685
- } else if (layer.file) {
35686
- const file = path73.resolve(manifestDir, layer.file);
35687
- png = decodePng(await readFile50(file));
35688
- source = { kind: "file", path: file };
35765
+ } else if (layer.run) {
35766
+ const sprites = await Promise.all(layer.run.map((sprite) => readPicture(manifest, manifestDir, lock, setId, name, sprite, warnings)));
35767
+ const seed = layer.seed ?? seedFromName(name);
35768
+ const loop = layer.repeat ?? true;
35769
+ const width = layer.width ?? Math.max(1, viewW + Math.ceil(travel * layer.speed) - (loop ? 0 : layer.x ?? 0));
35770
+ png = layRun(sprites.map((sprite) => finish(sprite.png, false)), width, { seed, step: layer.step, gap: layer.gap, jitter: layer.jitter, loop });
35771
+ source = { kind: "run", seed, sprites: sprites.map((sprite) => sprite.source) };
35689
35772
  } else {
35690
- const assetId = layer.asset;
35691
- const style = layer.style ?? manifest.assets[assetId].styles[0];
35692
- const entry = lock.entries[lockKey(style, assetId)];
35693
- if (!entry) throw new Error(`parallax ${setId}: ${style}/${assetId} has not been generated; run gen first`);
35694
- const output = entry.outputs.find((candidate) => /\.png$/i.test(candidate.path)) ?? entry.outputs[0];
35695
- if (!output) throw new Error(`parallax ${setId}: ${style}/${assetId} has no output in the lockfile`);
35696
- const file = path73.resolve(manifestDir, output.path);
35697
- png = decodePng(await readFile50(file));
35698
- source = { kind: "asset", style, asset: assetId, path: file };
35699
- if (entry.outputs.length > 1) warnings.push(`${name}: ${style}/${assetId} has ${entry.outputs.length} outputs; using ${output.path}`);
35773
+ const picture = await readPicture(manifest, manifestDir, lock, setId, name, layer, warnings);
35774
+ png = finish(picture.png, repeat);
35775
+ source = picture.source;
35700
35776
  }
35701
- const repeat = layer.repeat ?? true;
35702
- let bottom = layer.bottom ?? viewH;
35777
+ let bottom = (layer.bottom ?? viewH) + (layer.run ? layer.jitter ?? 0 : 0);
35703
35778
  if (layer.extend) {
35704
35779
  const rows = layer.extend === true ? Math.max(0, viewH - bottom) : layer.extend;
35705
35780
  png = extendDown(png, rows);
@@ -35716,7 +35791,8 @@ async function resolveParallaxSet(manifest, manifestDir, lock, setId) {
35716
35791
  repeatY: layer.repeatY ?? false,
35717
35792
  source
35718
35793
  };
35719
- if (repeat && source.kind !== "sky") {
35794
+ if (layer.foot !== void 0 || layer.tint) image.finish = { foot: layer.foot, tint: layer.tint };
35795
+ if (repeat && source.kind !== "sky" && source.kind !== "run") {
35720
35796
  image.seamRatio = seamRatio(png);
35721
35797
  if (travel * layer.speed > 0 && image.seamRatio > SEAM_WARN_RATIO) {
35722
35798
  warnings.push(
@@ -35744,7 +35820,175 @@ async function resolveParallaxSet(manifest, manifestDir, lock, setId) {
35744
35820
  }
35745
35821
  layers.push(image);
35746
35822
  }
35747
- return { id: setId, view: [viewW, viewH], travel, climb, layers, warnings };
35823
+ return { id: setId, view: [viewW, viewH], travel, climb, ...palette ? { palette } : {}, layers, warnings };
35824
+ }
35825
+ function finishPicture(png, options, where = "picture") {
35826
+ let out = png;
35827
+ if (options.foot !== void 0) out = ditherFoot(trimOpaque(out, options.keepWidth ?? false, where), options.foot);
35828
+ if (options.tint) out = tintPicture(out, options.tint, options.palette);
35829
+ return out;
35830
+ }
35831
+ function trimOpaque(png, keepWidth, where = "picture") {
35832
+ let top = png.height;
35833
+ let bottom = -1;
35834
+ let left = png.width;
35835
+ let right = -1;
35836
+ for (let y = 0; y < png.height; y++) {
35837
+ for (let x = 0; x < png.width; x++) {
35838
+ if (png.pixels[(y * png.width + x) * 4 + 3] === 0) continue;
35839
+ top = Math.min(top, y);
35840
+ bottom = Math.max(bottom, y);
35841
+ left = Math.min(left, x);
35842
+ right = Math.max(right, x);
35843
+ }
35844
+ }
35845
+ if (bottom < 0) throw new Error(`${where}: the picture has no opaque pixel`);
35846
+ if (keepWidth) {
35847
+ left = 0;
35848
+ right = png.width - 1;
35849
+ }
35850
+ const width = right - left + 1;
35851
+ const height = bottom - top + 1;
35852
+ const pixels = Buffer.alloc(width * height * 4);
35853
+ for (let y = 0; y < height; y++) {
35854
+ png.pixels.copy(pixels, y * width * 4, ((top + y) * png.width + left) * 4, ((top + y) * png.width + right + 1) * 4);
35855
+ }
35856
+ return { width, height, pixels };
35857
+ }
35858
+ function ditherFoot(png, fraction) {
35859
+ const { width, height } = png;
35860
+ const pixels = Buffer.from(png.pixels);
35861
+ const band = Math.max(1, roundHalfEven(height * fraction));
35862
+ for (let y = Math.max(0, height - band); y < height; y++) {
35863
+ const keep = 1 - (y - (height - band) + 1) / (band + 1);
35864
+ for (let x = 0; x < width; x++) {
35865
+ if (BAYER4[y % 4][x % 4] >= keep * 16) pixels[(y * width + x) * 4 + 3] = 0;
35866
+ }
35867
+ }
35868
+ return { width, height, pixels };
35869
+ }
35870
+ function tintPicture(png, tint, palette) {
35871
+ const target = parseHex(tint.color);
35872
+ const t = tint.amount;
35873
+ const pixels = Buffer.from(png.pixels);
35874
+ let colours;
35875
+ if (palette) {
35876
+ colours = palette.map((hex2) => {
35877
+ const { r, g, b } = parseHex(hex2);
35878
+ return [r, g, b];
35879
+ });
35880
+ } else {
35881
+ const seen = /* @__PURE__ */ new Map();
35882
+ for (let p = 0; p < pixels.length; p += 4) {
35883
+ if (pixels[p + 3] !== 0) seen.set(pixels[p] << 16 | pixels[p + 1] << 8 | pixels[p + 2], [pixels[p], pixels[p + 1], pixels[p + 2]]);
35884
+ }
35885
+ colours = [...seen.values()];
35886
+ }
35887
+ colours.sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
35888
+ const snapped = /* @__PURE__ */ new Map();
35889
+ for (let p = 0; p < pixels.length; p += 4) {
35890
+ if (pixels[p + 3] === 0) continue;
35891
+ const mixed = [
35892
+ roundHalfEven(pixels[p] * (1 - t) + target.r * t),
35893
+ roundHalfEven(pixels[p + 1] * (1 - t) + target.g * t),
35894
+ roundHalfEven(pixels[p + 2] * (1 - t) + target.b * t)
35895
+ ];
35896
+ const key3 = mixed[0] << 16 | mixed[1] << 8 | mixed[2];
35897
+ let best = snapped.get(key3);
35898
+ if (!best) {
35899
+ let bestDistance = Infinity;
35900
+ for (const colour of colours) {
35901
+ const d = (mixed[0] - colour[0]) ** 2 + (mixed[1] - colour[1]) ** 2 + (mixed[2] - colour[2]) ** 2;
35902
+ if (d < bestDistance) {
35903
+ bestDistance = d;
35904
+ best = colour;
35905
+ }
35906
+ }
35907
+ snapped.set(key3, best);
35908
+ }
35909
+ pixels[p] = best[0];
35910
+ pixels[p + 1] = best[1];
35911
+ pixels[p + 2] = best[2];
35912
+ }
35913
+ return { width: png.width, height: png.height, pixels };
35914
+ }
35915
+ function roundHalfEven(value) {
35916
+ const floor = Math.floor(value);
35917
+ const rest = value - floor;
35918
+ if (rest > 0.5) return floor + 1;
35919
+ if (rest < 0.5) return floor;
35920
+ return floor % 2 === 0 ? floor : floor + 1;
35921
+ }
35922
+ async function readPicture(manifest, manifestDir, lock, setId, name, ref, warnings) {
35923
+ if (ref.file) {
35924
+ const file2 = path73.resolve(manifestDir, ref.file);
35925
+ return { png: decodePng(await readFile50(file2)), source: { kind: "file", path: file2 } };
35926
+ }
35927
+ const assetId = ref.asset;
35928
+ const style = ref.style ?? manifest.assets[assetId].styles[0];
35929
+ const entry = lock.entries[lockKey(style, assetId)];
35930
+ if (!entry) throw new Error(`parallax ${setId}: ${style}/${assetId} has not been generated; run gen first`);
35931
+ const output = entry.outputs.find((candidate) => /\.png$/i.test(candidate.path)) ?? entry.outputs[0];
35932
+ if (!output) throw new Error(`parallax ${setId}: ${style}/${assetId} has no output in the lockfile`);
35933
+ const file = path73.resolve(manifestDir, output.path);
35934
+ if (entry.outputs.length > 1) warnings.push(`${name}: ${style}/${assetId} has ${entry.outputs.length} outputs; using ${output.path}`);
35935
+ return { png: decodePng(await readFile50(file)), source: { kind: "asset", style, asset: assetId, path: file } };
35936
+ }
35937
+ function seedFromName(name) {
35938
+ return createHash9("sha256").update(name).digest().readUInt32BE(0);
35939
+ }
35940
+ function seededRandom(seed) {
35941
+ let a = seed >>> 0;
35942
+ return () => {
35943
+ a = a + 1831565813 >>> 0;
35944
+ let t = a;
35945
+ t = Math.imul(t ^ t >>> 15, t | 1);
35946
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
35947
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
35948
+ };
35949
+ }
35950
+ function layRun(sprites, width, options) {
35951
+ const step = options.step ?? 0.72;
35952
+ const gap = options.gap ?? 16;
35953
+ const jitter = options.jitter ?? 0;
35954
+ const random = seededRandom(options.seed);
35955
+ const tallest = Math.max(...sprites.map((sprite) => sprite.height));
35956
+ const height = tallest + 2 * jitter;
35957
+ if (options.loop) {
35958
+ const widest = Math.max(...sprites.map((sprite) => sprite.width));
35959
+ if (width < widest) throw new Error(`a looping run must be at least as wide as its widest sprite (${widest} px); it is ${width}`);
35960
+ }
35961
+ const placed = [];
35962
+ let x = options.loop ? 0 : -Math.floor(random() * 32);
35963
+ let last = -1;
35964
+ while (x < width) {
35965
+ let pick = Math.floor(random() * sprites.length);
35966
+ if (sprites.length > 1 && pick === last) pick = (pick + 1) % sprites.length;
35967
+ last = pick;
35968
+ const sprite = sprites[pick];
35969
+ const flip = random() < 0.5;
35970
+ const shift = jitter ? Math.floor(random() * (2 * jitter + 1)) - jitter : 0;
35971
+ placed.push({ sprite: pick, flip, x, y: height - jitter - sprite.height + shift });
35972
+ x += Math.max(1, Math.floor(sprite.width * step + random() * gap));
35973
+ }
35974
+ const copies = options.loop ? [-width, 0, width] : [0];
35975
+ const stamps = placed.flatMap((p) => copies.map((dx) => ({ ...p, x: p.x + dx }))).sort((a, b) => a.x - b.x);
35976
+ const pixels = Buffer.alloc(width * height * 4);
35977
+ for (const p of stamps) {
35978
+ const sprite = sprites[p.sprite];
35979
+ for (let sy = 0; sy < sprite.height; sy++) {
35980
+ const y = p.y + sy;
35981
+ if (y < 0 || y >= height) continue;
35982
+ for (let sx = 0; sx < sprite.width; sx++) {
35983
+ const tx = p.x + sx;
35984
+ if (tx < 0 || tx >= width) continue;
35985
+ const from = (sy * sprite.width + (p.flip ? sprite.width - 1 - sx : sx)) * 4;
35986
+ if (sprite.pixels[from + 3] === 0) continue;
35987
+ sprite.pixels.copy(pixels, (y * width + tx) * 4, from, from + 4);
35988
+ }
35989
+ }
35990
+ }
35991
+ return { width, height, pixels };
35748
35992
  }
35749
35993
  function extendDown(png, rows) {
35750
35994
  if (rows <= 0) return png;
@@ -36240,7 +36484,9 @@ async function runParallax(args) {
36240
36484
  await provenanceFile("$manifest", args.manifest),
36241
36485
  await provenanceFile("$lock", args.lock),
36242
36486
  ...await Promise.all(
36243
- set.layers.filter((layer) => layer.source.kind !== "sky").map((layer) => provenanceFile(`layer:${layer.name}`, layer.source.path))
36487
+ set.layers.flatMap(
36488
+ (layer) => layerFiles(layer).map((file, n, all) => provenanceFile(all.length > 1 || layer.source.kind === "run" ? `layer:${layer.name}:${n + 1}` : `layer:${layer.name}`, file))
36489
+ )
36244
36490
  )
36245
36491
  ];
36246
36492
  const describe2 = setOptions(set);
@@ -36297,8 +36543,11 @@ function setOptions(set) {
36297
36543
  y: layer.y,
36298
36544
  repeat: layer.repeat,
36299
36545
  repeatY: layer.repeatY,
36300
- ...layer.source.kind === "sky" ? { sky: layer.source.colors } : {}
36301
- }))
36546
+ ...layer.source.kind === "sky" ? { sky: layer.source.colors } : {},
36547
+ ...layer.source.kind === "run" ? { run: { seed: layer.source.seed, sprites: layer.source.sprites.length, width: layer.png.width } } : {},
36548
+ ...layer.finish ?? {}
36549
+ })),
36550
+ ...set.palette ? { palette: set.palette } : {}
36302
36551
  };
36303
36552
  }
36304
36553