pixelkiln 0.144.2 → 0.145.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 +191 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +31 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +349 -4
- package/dist/index.d.ts +349 -4
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +5 -2
- package/docs/MANIFEST.md +4 -2
- package/docs/PARALLAX.md +52 -17
- package/docs/RESEARCH_PARALLAX.md +3 -2
- package/package.json +1 -1
- package/schema/manifest.schema.json +35 -0
- package/skills/pixelkiln/references/parallax.md +7 -3
package/dist/cli.js
CHANGED
|
@@ -3638,6 +3638,13 @@ var ParallaxLayerSchema = z.object({
|
|
|
3638
3638
|
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["extend"], message: "extend repeats the bottom row, which foot thins out; use one or the other" });
|
|
3639
3639
|
}
|
|
3640
3640
|
});
|
|
3641
|
+
var ParallaxTimeSchema = z.object({
|
|
3642
|
+
/** A style id, for that style's palette, or a list of colours. */
|
|
3643
|
+
palette: z.union([z.string().min(1), z.array(HexColorSchema).min(2).max(256)]),
|
|
3644
|
+
/** Map only onto colours whose blue is at least their red, which leaves out a night palette's lamps and moon. */
|
|
3645
|
+
cool: z.boolean().optional()
|
|
3646
|
+
}).strict();
|
|
3647
|
+
var ParallaxTimeIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,31}$/, "a time is letters, digits, - and _, starting with a letter");
|
|
3641
3648
|
var ParallaxSetSchema = z.object({
|
|
3642
3649
|
/** The game's view in pixels, [width, height]. */
|
|
3643
3650
|
view: z.tuple([z.number().int().min(8).max(4096), z.number().int().min(8).max(4096)]),
|
|
@@ -3651,8 +3658,21 @@ var ParallaxSetSchema = z.object({
|
|
|
3651
3658
|
* the picture, so it adds none.
|
|
3652
3659
|
*/
|
|
3653
3660
|
palette: z.union([z.string().min(1), z.array(HexColorSchema).min(2).max(256)]).optional(),
|
|
3661
|
+
/**
|
|
3662
|
+
* Other times of day for the same set, by name: each swaps the set's
|
|
3663
|
+
* `palette` for another by luminance rank. Godot exports carry them in
|
|
3664
|
+
* one shader; Tiled and LDtk get a map per time.
|
|
3665
|
+
*/
|
|
3666
|
+
times: z.record(ParallaxTimeIdSchema, ParallaxTimeSchema).optional(),
|
|
3654
3667
|
layers: z.array(ParallaxLayerSchema).min(1).max(32)
|
|
3655
|
-
}).strict()
|
|
3668
|
+
}).strict().superRefine((set, ctx) => {
|
|
3669
|
+
if (set.times && Object.keys(set.times).length && set.palette === void 0) {
|
|
3670
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["times"], message: "times swap the set's palette, so the set needs a palette" });
|
|
3671
|
+
}
|
|
3672
|
+
if (set.times && Object.keys(set.times).length > 15) {
|
|
3673
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["times"], message: "at most 15 times" });
|
|
3674
|
+
}
|
|
3675
|
+
});
|
|
3656
3676
|
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");
|
|
3657
3677
|
var ManifestSchema = z.object({
|
|
3658
3678
|
$schema: z.string().optional(),
|
|
@@ -16779,6 +16799,12 @@ ${issues}`);
|
|
|
16779
16799
|
if (!style) unknownReferences.push(`parallax.${setId}.palette: unknown style "${set.palette}"`);
|
|
16780
16800
|
else if (style.palette.length < 2) unknownReferences.push(`parallax.${setId}.palette: style "${set.palette}" has no palette`);
|
|
16781
16801
|
}
|
|
16802
|
+
for (const [time, spec] of Object.entries(set.times ?? {})) {
|
|
16803
|
+
if (typeof spec.palette !== "string") continue;
|
|
16804
|
+
const style = parsed.data.styles[spec.palette];
|
|
16805
|
+
if (!style) unknownReferences.push(`parallax.${setId}.times.${time}.palette: unknown style "${spec.palette}"`);
|
|
16806
|
+
else if (style.palette.length < 2) unknownReferences.push(`parallax.${setId}.times.${time}.palette: style "${spec.palette}" has no palette`);
|
|
16807
|
+
}
|
|
16782
16808
|
set.layers.forEach((layer, index) => {
|
|
16783
16809
|
const at2 = `parallax.${setId}.layers.${index}`;
|
|
16784
16810
|
const checkAsset = (where, ref) => {
|
|
@@ -35975,7 +36001,14 @@ async function resolveParallaxSet(manifest, manifestDir, lock, setId) {
|
|
|
35975
36001
|
}
|
|
35976
36002
|
layers.push(image);
|
|
35977
36003
|
}
|
|
35978
|
-
|
|
36004
|
+
const times = Object.entries(set.times ?? {}).map(([name, time]) => {
|
|
36005
|
+
const colours = typeof time.palette === "string" ? manifest.styles[time.palette]?.palette : time.palette;
|
|
36006
|
+
if (!colours?.length) throw new Error(`parallax ${setId}: time ${name}: style "${time.palette}" has no palette`);
|
|
36007
|
+
const resolved = { name, palette: colours, cool: time.cool ?? false };
|
|
36008
|
+
paletteSwap(palette, resolved, `parallax ${setId}: time ${name}`);
|
|
36009
|
+
return resolved;
|
|
36010
|
+
});
|
|
36011
|
+
return { id: setId, view: [viewW, viewH], travel, climb, ...palette ? { palette } : {}, ...times.length ? { times } : {}, layers, warnings };
|
|
35979
36012
|
}
|
|
35980
36013
|
function finishPicture(png, options, where = "picture") {
|
|
35981
36014
|
let out = png;
|
|
@@ -36156,6 +36189,83 @@ function loopPicture(png, method, where = "picture") {
|
|
|
36156
36189
|
}
|
|
36157
36190
|
return { png: { width: w * 2, height: h, pixels }, loop: { method, from: w } };
|
|
36158
36191
|
}
|
|
36192
|
+
var rgbKey = (r, g, b) => r << 16 | g << 8 | b;
|
|
36193
|
+
function sortedRgb(hexes) {
|
|
36194
|
+
const seen = /* @__PURE__ */ new Map();
|
|
36195
|
+
for (const hex2 of hexes) {
|
|
36196
|
+
const { r, g, b } = parseHex(hex2);
|
|
36197
|
+
seen.set(rgbKey(r, g, b), [r, g, b]);
|
|
36198
|
+
}
|
|
36199
|
+
return [...seen.values()].sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
|
|
36200
|
+
}
|
|
36201
|
+
var luminance = (c) => c[0] * 0.2126 + c[1] * 0.7152 + c[2] * 0.0722;
|
|
36202
|
+
function paletteSwap(from, time, where = "palette swap") {
|
|
36203
|
+
const source = sortedRgb(from);
|
|
36204
|
+
let target = sortedRgb(time.palette);
|
|
36205
|
+
if (time.cool) target = target.filter((c) => c[2] >= c[0]);
|
|
36206
|
+
if (!target.length) throw new Error(`${where}: no colour of the palette has blue at least its red, so cool leaves nothing to map onto`);
|
|
36207
|
+
const rank = (colours) => colours.map((c, i) => [i, luminance(c)]).sort((a, b) => a[1] - b[1] || a[0] - b[0]).map(([i]) => i);
|
|
36208
|
+
const fromOrder = rank(source);
|
|
36209
|
+
const toOrder = rank(target);
|
|
36210
|
+
const table = /* @__PURE__ */ new Map();
|
|
36211
|
+
fromOrder.forEach((i, r) => {
|
|
36212
|
+
const c = source[i];
|
|
36213
|
+
table.set(rgbKey(c[0], c[1], c[2]), target[toOrder[roundHalfEven(r / Math.max(fromOrder.length - 1, 1) * (toOrder.length - 1))]]);
|
|
36214
|
+
});
|
|
36215
|
+
return { source, table };
|
|
36216
|
+
}
|
|
36217
|
+
function nearestRgb(colours, r, g, b) {
|
|
36218
|
+
let best = colours[0];
|
|
36219
|
+
let bestDistance = Infinity;
|
|
36220
|
+
for (const c of colours) {
|
|
36221
|
+
const d = (r - c[0]) ** 2 + (g - c[1]) ** 2 + (b - c[2]) ** 2;
|
|
36222
|
+
if (d < bestDistance) {
|
|
36223
|
+
bestDistance = d;
|
|
36224
|
+
best = c;
|
|
36225
|
+
}
|
|
36226
|
+
}
|
|
36227
|
+
return best;
|
|
36228
|
+
}
|
|
36229
|
+
function recolourPicture(png, swap) {
|
|
36230
|
+
const pixels = Buffer.from(png.pixels);
|
|
36231
|
+
const done = /* @__PURE__ */ new Map();
|
|
36232
|
+
for (let p = 0; p < pixels.length; p += 4) {
|
|
36233
|
+
if (pixels[p + 3] === 0) continue;
|
|
36234
|
+
const key3 = rgbKey(pixels[p], pixels[p + 1], pixels[p + 2]);
|
|
36235
|
+
let out = done.get(key3);
|
|
36236
|
+
if (!out) {
|
|
36237
|
+
const snapped = nearestRgb(swap.source, pixels[p], pixels[p + 1], pixels[p + 2]);
|
|
36238
|
+
out = swap.table.get(rgbKey(snapped[0], snapped[1], snapped[2]));
|
|
36239
|
+
done.set(key3, out);
|
|
36240
|
+
}
|
|
36241
|
+
pixels[p] = out[0];
|
|
36242
|
+
pixels[p + 1] = out[1];
|
|
36243
|
+
pixels[p + 2] = out[2];
|
|
36244
|
+
}
|
|
36245
|
+
return { width: png.width, height: png.height, pixels };
|
|
36246
|
+
}
|
|
36247
|
+
function setAtTime(set, time) {
|
|
36248
|
+
const spec = set.times?.find((t) => t.name === time);
|
|
36249
|
+
if (!spec) throw new Error(`parallax ${set.id}: no time "${time}". ${set.times?.length ? `Known: ${set.times.map((t) => t.name).join(", ")}` : "The set has no times."}`);
|
|
36250
|
+
const swap = paletteSwap(set.palette, spec);
|
|
36251
|
+
return { ...set, id: `${set.id}.${time}`, times: void 0, layers: set.layers.map((layer) => ({ ...layer, png: recolourPicture(layer.png, swap) })) };
|
|
36252
|
+
}
|
|
36253
|
+
function timeColours(set) {
|
|
36254
|
+
const used = /* @__PURE__ */ new Map();
|
|
36255
|
+
for (const layer of set.layers) {
|
|
36256
|
+
const px = layer.png.pixels;
|
|
36257
|
+
for (let p = 0; p < px.length; p += 4) if (px[p + 3] !== 0) used.set(rgbKey(px[p], px[p + 1], px[p + 2]), [px[p], px[p + 1], px[p + 2]]);
|
|
36258
|
+
}
|
|
36259
|
+
const columns = [...used.values()].sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
|
|
36260
|
+
const rows = [columns, ...(set.times ?? []).map((time) => {
|
|
36261
|
+
const swap = paletteSwap(set.palette, time);
|
|
36262
|
+
return columns.map((c) => swap.table.get(rgbKey(...nearestRgb(swap.source, c[0], c[1], c[2]))));
|
|
36263
|
+
})];
|
|
36264
|
+
const width = Math.max(1, columns.length);
|
|
36265
|
+
const pixels = Buffer.alloc(width * rows.length * 4);
|
|
36266
|
+
rows.forEach((row, y) => row.forEach((c, x) => pixels.set([c[0], c[1], c[2], 255], (y * width + x) * 4)));
|
|
36267
|
+
return { width, height: rows.length, pixels };
|
|
36268
|
+
}
|
|
36159
36269
|
async function readPicture(manifest, manifestDir, lock, setId, name, ref, warnings) {
|
|
36160
36270
|
if (ref.file) {
|
|
36161
36271
|
const file2 = path73.resolve(manifestDir, ref.file);
|
|
@@ -36346,11 +36456,23 @@ function godotNumber(value) {
|
|
|
36346
36456
|
function exportGodot(set, base) {
|
|
36347
36457
|
const [vw, vh] = set.view;
|
|
36348
36458
|
const pictures = layerPngs(set, base);
|
|
36349
|
-
const
|
|
36459
|
+
const name = path73.basename(base);
|
|
36460
|
+
const times = set.times ?? [];
|
|
36461
|
+
const lines = [`[gd_scene load_steps=${pictures.length + 1 + (times.length ? 3 : 0)} format=3]`, ""];
|
|
36350
36462
|
pictures.forEach(({ file }, index) => {
|
|
36351
36463
|
lines.push(`[ext_resource type="Texture2D" path=${JSON.stringify(`./${file}`)} id="${index + 1}_layer"]`);
|
|
36352
36464
|
});
|
|
36353
|
-
|
|
36465
|
+
const extra = [];
|
|
36466
|
+
if (times.length) {
|
|
36467
|
+
const colours = timeColours(set);
|
|
36468
|
+
extra.push({ path: `${base}.colours.png`, data: encodeRgbaPng(colours.width, colours.height, colours.pixels) });
|
|
36469
|
+
extra.push({ path: `${base}.gdshader`, data: GODOT_TIMES_SHADER });
|
|
36470
|
+
lines.push(`[ext_resource type="Shader" path=${JSON.stringify(`./${name}.gdshader`)} id="times_shader"]`);
|
|
36471
|
+
lines.push(`[ext_resource type="Texture2D" path=${JSON.stringify(`./${name}.colours.png`)} id="times_colours"]`);
|
|
36472
|
+
lines.push("", '[sub_resource type="ShaderMaterial" id="times"]', 'shader = ExtResource("times_shader")', 'shader_parameter/colours = ExtResource("times_colours")');
|
|
36473
|
+
}
|
|
36474
|
+
lines.push("", `[node name=${JSON.stringify(name)} type="Node2D"]`, "texture_filter = 1");
|
|
36475
|
+
if (times.length) lines.push(`metadata/times = PackedStringArray(${times.map((t) => JSON.stringify(t.name)).join(", ")})`);
|
|
36354
36476
|
pictures.forEach(({ layer }, index) => {
|
|
36355
36477
|
lines.push("", `[node name=${JSON.stringify(layer.name)} type="Parallax2D" parent="."]`);
|
|
36356
36478
|
lines.push(`scroll_scale = Vector2(${godotNumber(layer.speed)}, ${godotNumber(layer.speedY)})`);
|
|
@@ -36359,19 +36481,20 @@ function exportGodot(set, base) {
|
|
|
36359
36481
|
if (layer.repeat || layer.repeatY) {
|
|
36360
36482
|
lines.push(`repeat_size = Vector2(${layer.repeat ? layer.png.width : 0}, ${layer.repeatY ? layer.png.height : 0})`);
|
|
36361
36483
|
const reach = (view, size) => 2 * (Math.ceil(view / size) + 1) - 1;
|
|
36362
|
-
const
|
|
36363
|
-
lines.push(`repeat_times = ${
|
|
36484
|
+
const times2 = Math.max(layer.repeat ? reach(vw, layer.png.width) : 1, layer.repeatY ? reach(vh, layer.png.height) : 1);
|
|
36485
|
+
lines.push(`repeat_times = ${times2}`);
|
|
36364
36486
|
}
|
|
36365
36487
|
lines.push("", `[node name="Sprite2D" type="Sprite2D" parent=${JSON.stringify(layer.name)}]`);
|
|
36366
36488
|
lines.push(`texture = ExtResource("${index + 1}_layer")`, "centered = false");
|
|
36489
|
+
if (times.length) lines.push('material = SubResource("times")');
|
|
36367
36490
|
const mod = (value, size) => (value % size + size) % size;
|
|
36368
36491
|
const px = layer.repeat ? mod(layer.x, layer.png.width) : layer.x;
|
|
36369
36492
|
const py = layer.repeatY ? mod(layer.y + set.climb, layer.png.height) : layer.y + set.climb;
|
|
36370
36493
|
lines.push(`position = Vector2(${px}, ${py})`);
|
|
36371
36494
|
});
|
|
36372
36495
|
return {
|
|
36373
|
-
files: [{ path: `${base}.tscn`, data: lines.join("\n") + "\n" }, ...pictures.map((p) => ({ path: path73.join(path73.dirname(base), p.file), data: p.png }))],
|
|
36374
|
-
options: { format: "godot", start: [0, set.climb] }
|
|
36496
|
+
files: [{ path: `${base}.tscn`, data: lines.join("\n") + "\n" }, ...pictures.map((p) => ({ path: path73.join(path73.dirname(base), p.file), data: p.png })), ...extra],
|
|
36497
|
+
options: { format: "godot", start: [0, set.climb], ...times.length ? { shader: `${name}.gdshader` } : {} }
|
|
36375
36498
|
};
|
|
36376
36499
|
}
|
|
36377
36500
|
function uuid(...parts) {
|
|
@@ -36610,15 +36733,52 @@ function tileEmpty(png, x0, y0, grid) {
|
|
|
36610
36733
|
return true;
|
|
36611
36734
|
}
|
|
36612
36735
|
function exportParallax(set, format, base) {
|
|
36613
|
-
if (format === "tiled") return exportTiled(set, base);
|
|
36614
36736
|
if (format === "godot") return exportGodot(set, base);
|
|
36615
|
-
|
|
36737
|
+
const one = (s, b) => format === "tiled" ? exportTiled(s, b) : exportLdtk(s, b);
|
|
36738
|
+
const result = one({ ...set, times: void 0 }, base);
|
|
36739
|
+
if (!set.times?.length) return result;
|
|
36740
|
+
for (const time of set.times) {
|
|
36741
|
+
const timed = one(setAtTime(set, time.name), `${base}.${time.name}`);
|
|
36742
|
+
result.files.push(...timed.files);
|
|
36743
|
+
for (const warning of timed.options.warnings ?? []) {
|
|
36744
|
+
const warnings = result.options.warnings ?? [];
|
|
36745
|
+
if (!warnings.includes(warning)) result.options.warnings = [...warnings, warning];
|
|
36746
|
+
}
|
|
36747
|
+
}
|
|
36748
|
+
result.options.maps = [path73.basename(result.files[0].path), ...set.times.map((t) => `${path73.basename(base)}.${t.name}${path73.extname(result.files[0].path)}`)];
|
|
36749
|
+
return result;
|
|
36616
36750
|
}
|
|
36751
|
+
var GODOT_TIMES_SHADER = `// Written by pixelkiln parallax export. Recolours the set to one of its times of day.
|
|
36752
|
+
// time = 0 draws the pictures as they are; time = n draws them at the n-th name in the
|
|
36753
|
+
// scene root's metadata/times. blend (0 to 1) mixes toward blend_to, for a fade between
|
|
36754
|
+
// two times. Every layer shares one material, so setting a parameter on it sets all of them.
|
|
36755
|
+
shader_type canvas_item;
|
|
36756
|
+
|
|
36757
|
+
uniform sampler2D colours : filter_nearest, repeat_disable;
|
|
36758
|
+
uniform int time = 0;
|
|
36759
|
+
uniform int blend_to = 0;
|
|
36760
|
+
uniform float blend : hint_range(0.0, 1.0) = 0.0;
|
|
36761
|
+
|
|
36762
|
+
void fragment() {
|
|
36763
|
+
vec4 drawn = texture(TEXTURE, UV);
|
|
36764
|
+
COLOR = drawn;
|
|
36765
|
+
int columns = textureSize(colours, 0).x;
|
|
36766
|
+
for (int i = 0; i < columns; i++) {
|
|
36767
|
+
if (all(lessThan(abs(texelFetch(colours, ivec2(i, 0), 0).rgb - drawn.rgb), vec3(0.5 / 255.0)))) {
|
|
36768
|
+
vec3 now = texelFetch(colours, ivec2(i, time), 0).rgb;
|
|
36769
|
+
vec3 next = texelFetch(colours, ivec2(i, blend_to), 0).rgb;
|
|
36770
|
+
COLOR = vec4(mix(now, next, blend), drawn.a);
|
|
36771
|
+
break;
|
|
36772
|
+
}
|
|
36773
|
+
}
|
|
36774
|
+
}
|
|
36775
|
+
`;
|
|
36617
36776
|
function previewHtml(set, scale2 = 3) {
|
|
36618
36777
|
const [vw, vh] = set.view;
|
|
36619
|
-
const
|
|
36778
|
+
const timed = [set, ...(set.times ?? []).map((time) => setAtTime(set, time.name))];
|
|
36779
|
+
const layers = set.layers.map((layer, index) => ({
|
|
36620
36780
|
name: layer.name,
|
|
36621
|
-
|
|
36781
|
+
srcs: timed.map((s) => `data:image/png;base64,${encodeRgbaPng(s.layers[index].png.width, s.layers[index].png.height, s.layers[index].png.pixels).toString("base64")}`),
|
|
36622
36782
|
w: layer.png.width,
|
|
36623
36783
|
h: layer.png.height,
|
|
36624
36784
|
x: layer.x,
|
|
@@ -36628,7 +36788,8 @@ function previewHtml(set, scale2 = 3) {
|
|
|
36628
36788
|
repeat: layer.repeat,
|
|
36629
36789
|
repeatY: layer.repeatY
|
|
36630
36790
|
}));
|
|
36631
|
-
const
|
|
36791
|
+
const times = ["as drawn", ...(set.times ?? []).map((time) => time.name)];
|
|
36792
|
+
const data = JSON.stringify({ view: [vw, vh], travel: set.travel, climb: set.climb, times, layers }).replace(/</g, "\\u003c");
|
|
36632
36793
|
return `<!doctype html>
|
|
36633
36794
|
<html lang="en">
|
|
36634
36795
|
<head>
|
|
@@ -36650,13 +36811,17 @@ function previewHtml(set, scale2 = 3) {
|
|
|
36650
36811
|
<main>
|
|
36651
36812
|
<canvas id="view" width="${vw}" height="${vh}"></canvas>
|
|
36652
36813
|
<label><button id="play" type="button">Pause</button> camera <input id="cam" type="range" min="0" max="1000" value="0"> <output id="pos"></output></label>
|
|
36814
|
+
<label id="times" hidden>time <select id="time"></select></label>
|
|
36653
36815
|
<table><thead><tr><th>Layer</th><th>speed</th><th>speedY</th><th>repeat</th></tr></thead><tbody id="rows"></tbody></table>
|
|
36654
36816
|
</main>
|
|
36655
36817
|
<script>
|
|
36656
36818
|
const set = ${data};
|
|
36657
36819
|
const ctx = document.getElementById("view").getContext("2d");
|
|
36658
36820
|
ctx.imageSmoothingEnabled = false;
|
|
36659
|
-
const images = set.layers.map((layer) => Object.assign(new Image(), { src
|
|
36821
|
+
const images = set.layers.map((layer) => layer.srcs.map((src) => Object.assign(new Image(), { src })));
|
|
36822
|
+
const pick = document.getElementById("time");
|
|
36823
|
+
set.times.forEach((name, i) => pick.add(new Option(name, i)));
|
|
36824
|
+
document.getElementById("times").hidden = set.times.length < 2;
|
|
36660
36825
|
const rows = document.getElementById("rows");
|
|
36661
36826
|
for (const layer of set.layers) {
|
|
36662
36827
|
const tr = rows.insertRow();
|
|
@@ -36685,7 +36850,7 @@ function draw(u) {
|
|
|
36685
36850
|
if (layer.repeat) for (let x = ((left % layer.w) + layer.w) % layer.w - layer.w; x < set.view[0]; x += layer.w) xs.push(x);
|
|
36686
36851
|
const ys = layer.repeatY ? [] : [top];
|
|
36687
36852
|
if (layer.repeatY) for (let y = ((top % layer.h) + layer.h) % layer.h - layer.h; y < set.view[1]; y += layer.h) ys.push(y);
|
|
36688
|
-
for (const y of ys) for (const x of xs) ctx.drawImage(images[i], x, y);
|
|
36853
|
+
for (const y of ys) for (const x of xs) ctx.drawImage(images[i][pick.value | 0], x, y);
|
|
36689
36854
|
});
|
|
36690
36855
|
}
|
|
36691
36856
|
function frame(now) {
|
|
@@ -36697,7 +36862,7 @@ function frame(now) {
|
|
|
36697
36862
|
draw(slider.value / 1000);
|
|
36698
36863
|
requestAnimationFrame(frame);
|
|
36699
36864
|
}
|
|
36700
|
-
Promise.all(images.map((image) => image.decode())).then(() => requestAnimationFrame(frame));
|
|
36865
|
+
Promise.all(images.flat().map((image) => image.decode())).then(() => requestAnimationFrame(frame));
|
|
36701
36866
|
</script>
|
|
36702
36867
|
</body>
|
|
36703
36868
|
</html>
|
|
@@ -36738,27 +36903,30 @@ async function runParallax(args) {
|
|
|
36738
36903
|
sources,
|
|
36739
36904
|
options: { set: id, ...describe2, ...result.options }
|
|
36740
36905
|
}, { force: args.force });
|
|
36741
|
-
log(` ${id} (${format}): ${path74.relative(process.cwd(), result.files[0].path)} + ${result.files.length - 1}
|
|
36906
|
+
log(` ${id} (${format}): ${path74.relative(process.cwd(), result.files[0].path)} + ${result.files.length - 1} more file(s)`);
|
|
36742
36907
|
for (const warning of result.options.warnings ?? []) log(` warning: ${warning}`);
|
|
36743
36908
|
}
|
|
36744
36909
|
} else {
|
|
36745
36910
|
const frames = args.frames ?? 3;
|
|
36746
|
-
const strip = joinStripPng(
|
|
36747
|
-
cameraPath(
|
|
36748
|
-
const frame = composeParallaxFrame(
|
|
36911
|
+
const strip = (s) => joinStripPng(
|
|
36912
|
+
cameraPath(s, frames).map(([x, y]) => {
|
|
36913
|
+
const frame = composeParallaxFrame(s, x, y);
|
|
36749
36914
|
return encodeRgbaPng(frame.width, frame.height, frame.pixels);
|
|
36750
36915
|
})
|
|
36751
36916
|
);
|
|
36752
36917
|
const base = path74.join(root, `${id}.preview`);
|
|
36753
36918
|
await writeManagedArtifactBundle(`${base}.pixelkiln.json`, [
|
|
36754
36919
|
{ path: `${base}.html`, data: Buffer.from(previewHtml(set)) },
|
|
36755
|
-
{ path: `${base}.png`, data: strip }
|
|
36920
|
+
{ path: `${base}.png`, data: strip(set) },
|
|
36921
|
+
// A strip for each time of day too, the same frames recoloured.
|
|
36922
|
+
...(set.times ?? []).map((time) => ({ path: `${base}.${time.name}.png`, data: strip(setAtTime(set, time.name)) }))
|
|
36756
36923
|
], {
|
|
36757
36924
|
kind: "parallax",
|
|
36758
36925
|
sources,
|
|
36759
36926
|
options: { set: id, ...describe2, preview: { frames } }
|
|
36760
36927
|
}, { force: args.force });
|
|
36761
36928
|
log(` ${id}: ${path74.relative(process.cwd(), base)}.html (scrolls in a browser) + .png (${frames} frames, start to end)`);
|
|
36929
|
+
if (set.times?.length) log(` times: ${set.times.map((time) => `${time.name} (${path74.basename(base)}.${time.name}.png)`).join(", ")}`);
|
|
36762
36930
|
}
|
|
36763
36931
|
for (const layer of set.layers) {
|
|
36764
36932
|
const seam = (layer.seamRatio === void 0 ? "" : `, seam ${layer.seamRatio.toFixed(1)}`) + (layer.seamRatioY === void 0 ? "" : `, vertical seam ${layer.seamRatioY.toFixed(1)}`);
|
|
@@ -36785,7 +36953,8 @@ function setOptions(set) {
|
|
|
36785
36953
|
...layer.loop ? { loop: layer.loop } : {},
|
|
36786
36954
|
...layer.finish ?? {}
|
|
36787
36955
|
})),
|
|
36788
|
-
...set.palette ? { palette: set.palette } : {}
|
|
36956
|
+
...set.palette ? { palette: set.palette } : {},
|
|
36957
|
+
...set.times ? { times: Object.fromEntries(set.times.map((time) => [time.name, { palette: time.palette, cool: time.cool }])) } : {}
|
|
36789
36958
|
};
|
|
36790
36959
|
}
|
|
36791
36960
|
|