pixelkiln 0.139.2 → 0.140.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/README.md +1 -1
- package/dist/cli.js +876 -74
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +77 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +587 -43
- package/dist/index.d.ts +587 -43
- package/dist/index.js +74 -2
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +25 -0
- package/docs/MANIFEST.md +46 -0
- package/docs/PARALLAX.md +145 -8
- package/docs/README.md +2 -2
- package/docs/RESEARCH_PARALLAX.md +142 -36
- package/package.json +1 -1
- package/schema/manifest.schema.json +120 -0
- package/skills/pixelkiln/SKILL.md +3 -2
- package/skills/pixelkiln/references/parallax.md +44 -3
package/dist/cli.js
CHANGED
|
@@ -68,7 +68,7 @@ function exitCodeFor(err) {
|
|
|
68
68
|
|
|
69
69
|
// src/cli/main.ts
|
|
70
70
|
import { existsSync as existsSync59 } from "fs";
|
|
71
|
-
import { readFile as
|
|
71
|
+
import { readFile as readFile53 } from "fs/promises";
|
|
72
72
|
|
|
73
73
|
// src/cli/args.ts
|
|
74
74
|
import path from "path";
|
|
@@ -254,6 +254,7 @@ var COMMANDS = [
|
|
|
254
254
|
"ui",
|
|
255
255
|
"asset",
|
|
256
256
|
"talk",
|
|
257
|
+
"parallax",
|
|
257
258
|
"help",
|
|
258
259
|
"--help",
|
|
259
260
|
"-h",
|
|
@@ -273,6 +274,7 @@ var MUSIC_SUBCOMMANDS = ["make", "style", "lyrics"];
|
|
|
273
274
|
var TALK_SUBCOMMANDS = ["visemes", "gif", "plan"];
|
|
274
275
|
var ASSET_SUBCOMMANDS = ["canvas", "mirror", "import", "save", "expand", "review", "export"];
|
|
275
276
|
var UI_SUBCOMMANDS = ["show", "split", "states", "nine-slice", "pull"];
|
|
277
|
+
var PARALLAX_SUBCOMMANDS = ["preview", "export"];
|
|
276
278
|
function parseArgs(argv) {
|
|
277
279
|
const [command = "help"] = argv;
|
|
278
280
|
if (!COMMANDS.includes(command)) {
|
|
@@ -420,6 +422,14 @@ function parseArgs(argv) {
|
|
|
420
422
|
throw new UsageError(`Unknown music subcommand "${subcommand}". Known: ${MUSIC_SUBCOMMANDS.join(", ")}`);
|
|
421
423
|
}
|
|
422
424
|
if (rest[0] === subcommand) rest = rest.slice(1);
|
|
425
|
+
} else if (command === "parallax") {
|
|
426
|
+
subcommand = rest[0]?.startsWith("-") || rest[0] === void 0 ? "preview" : rest[0];
|
|
427
|
+
if (!PARALLAX_SUBCOMMANDS.includes(subcommand)) {
|
|
428
|
+
throw new UsageError(`Unknown parallax subcommand "${subcommand}". Known: ${PARALLAX_SUBCOMMANDS.join(", ")}`);
|
|
429
|
+
}
|
|
430
|
+
if (rest[0] === subcommand) rest = rest.slice(1);
|
|
431
|
+
target = rest[0]?.startsWith("-") ? void 0 : rest[0];
|
|
432
|
+
if (target !== void 0) rest = rest.slice(1);
|
|
423
433
|
} else if (command === "refine") {
|
|
424
434
|
subcommand = rest[0]?.startsWith("-") || rest[0] === void 0 ? "run" : rest[0];
|
|
425
435
|
if (!REFINE_SUBCOMMANDS.includes(subcommand)) {
|
|
@@ -511,7 +521,7 @@ function parseArgs(argv) {
|
|
|
511
521
|
}
|
|
512
522
|
const manifest = get("--manifest") ?? "pixelkiln.manifest.json";
|
|
513
523
|
const rawFormat = get("--format");
|
|
514
|
-
const formats = command === "export" ? ["generic", "tiled", "godot", "ldtk"] : command === "asset" ? ["zip", "spritesheet", "aseprite", "gif"] : ["generic", "aseprite", "godot"];
|
|
524
|
+
const formats = command === "export" ? ["generic", "tiled", "godot", "ldtk"] : command === "parallax" ? ["tiled", "godot", "ldtk"] : command === "asset" ? ["zip", "spritesheet", "aseprite", "gif"] : ["generic", "aseprite", "godot"];
|
|
515
525
|
if (rawFormat && !formats.includes(rawFormat)) {
|
|
516
526
|
throw new UsageError(`--format must be ${formats.slice(0, -1).join(", ")}, or ${formats.at(-1)}, got "${rawFormat}"`);
|
|
517
527
|
}
|
|
@@ -706,6 +716,10 @@ Commands
|
|
|
706
716
|
mount Write a style's sprites into their declared cells of an existing
|
|
707
717
|
sheet, leaving every other pixel untouched. Offline.
|
|
708
718
|
export Build a tile atlas, engine metadata, and offline provenance record.
|
|
719
|
+
parallax A manifest's parallax sets. parallax preview [set] writes a page
|
|
720
|
+
that scrolls the set and a strip of frames; parallax export [set]
|
|
721
|
+
writes a Tiled map, a Godot scene and an LDtk project (or one,
|
|
722
|
+
with --format) with the layer pictures. Offline.
|
|
709
723
|
purge Delete objects previously tagged discard. Irreversible; asks first.
|
|
710
724
|
prune Drop lock entries the manifest no longer declares. Offline; asks
|
|
711
725
|
first. Local art is untouched.
|
|
@@ -814,6 +828,7 @@ Options
|
|
|
814
828
|
--inputs <path> pack/quality snapshot: JSON input list; needs --out
|
|
815
829
|
--format <format> export: generic (default), tiled, godot (TileSet), or ldtk
|
|
816
830
|
pack/mount: generic (default), aseprite, or godot (SpriteFrames)
|
|
831
|
+
parallax export: tiled, godot, or ldtk (default: all three)
|
|
817
832
|
--output-role <r> pack: include only this output role (repeatable)
|
|
818
833
|
--primary-only pack: include only unambiguous primary/single outputs
|
|
819
834
|
--max-distance <n> audit: maximum palette distance
|
|
@@ -883,6 +898,7 @@ Options
|
|
|
883
898
|
--style-weight <n> music: how closely to follow the style, 0-1
|
|
884
899
|
--frames <n> estimate-skeleton: poses to scaffold, 3-15;
|
|
885
900
|
normal-map: equal frames in the --from strip, 1-32
|
|
901
|
+
parallax preview: frames in the strip, 3-15 (default 3)
|
|
886
902
|
--convention <c> normal-map: opengl (green up, default) or directx (green down)
|
|
887
903
|
--preset <name> vfx: start from a whole-effect preset (vfx presets lists them)
|
|
888
904
|
--recipe <file> vfx: render a recipe or an earlier run's .vfx.json record
|
|
@@ -1454,10 +1470,10 @@ function normalizeHex(value) {
|
|
|
1454
1470
|
function sha256(data) {
|
|
1455
1471
|
return createHash("sha256").update(data).digest("hex");
|
|
1456
1472
|
}
|
|
1457
|
-
async function sha256File(
|
|
1473
|
+
async function sha256File(path79) {
|
|
1458
1474
|
return new Promise((resolve, reject) => {
|
|
1459
1475
|
const hash = createHash("sha256");
|
|
1460
|
-
const stream = createReadStream(
|
|
1476
|
+
const stream = createReadStream(path79);
|
|
1461
1477
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1462
1478
|
stream.on("error", reject);
|
|
1463
1479
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -3191,7 +3207,7 @@ var AssetDeriveSchema = z.object({
|
|
|
3191
3207
|
/** key-skin: how far a pixel may sit from a `skin` colour. despeckle: how near a reference colour must be to vouch for a pixel. */
|
|
3192
3208
|
tolerance: z.number().min(0).max(442).optional()
|
|
3193
3209
|
}).strict().superRefine((derive, context) => {
|
|
3194
|
-
const issue = (message6,
|
|
3210
|
+
const issue = (message6, path79) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path79] });
|
|
3195
3211
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
3196
3212
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
3197
3213
|
}
|
|
@@ -3506,6 +3522,53 @@ var AssetSchema = z.object({
|
|
|
3506
3522
|
});
|
|
3507
3523
|
var DEFAULT_HISTORY_LIMIT = 5;
|
|
3508
3524
|
var HistoryLimitSchema = z.number().int().min(0).max(100);
|
|
3525
|
+
var ParallaxLayerSchema = z.object({
|
|
3526
|
+
/** Names the layer in exports; defaults to the asset id, the file name, or "sky". */
|
|
3527
|
+
name: z.string().regex(/^[A-Za-z][A-Za-z0-9_-]*$/, "letters, digits, - and _, starting with a letter").optional(),
|
|
3528
|
+
/** A manifest asset, read from the lockfile once generated. */
|
|
3529
|
+
asset: z.string().min(1).optional(),
|
|
3530
|
+
/** The style the asset was generated under, when it was generated under more than one. */
|
|
3531
|
+
style: z.string().min(1).optional(),
|
|
3532
|
+
/** A picture on disk, relative to the manifest: a layer finished by hand or by script. */
|
|
3533
|
+
file: z.string().min(1).optional(),
|
|
3534
|
+
/** Flat colour bands, top to bottom, with a dithered step between neighbours. */
|
|
3535
|
+
sky: z.array(HexColorSchema).min(1).max(64).optional(),
|
|
3536
|
+
speed: z.number().min(0).max(4),
|
|
3537
|
+
/** Vertical speed; 1, moving with the level, when the set does not climb. */
|
|
3538
|
+
speedY: z.number().min(0).max(4).optional(),
|
|
3539
|
+
/** Left edge on the set's canvas, whose origin is the view's top-left at the start. */
|
|
3540
|
+
x: z.number().int().min(-1e5).max(1e5).optional(),
|
|
3541
|
+
/** The canvas row the layer's bottom edge sits on; the view's height when absent. */
|
|
3542
|
+
bottom: z.number().int().min(-1e5).max(1e5).optional(),
|
|
3543
|
+
/**
|
|
3544
|
+
* Repeat the bottom row downward: true to the foot of the view, or this
|
|
3545
|
+
* many rows. A far range extended this way gives nearer
|
|
3546
|
+
* layers' feet distant land to dissolve into instead of floating.
|
|
3547
|
+
*/
|
|
3548
|
+
extend: z.union([z.boolean(), z.number().int().min(1).max(4096)]).optional(),
|
|
3549
|
+
/** Repeat sideways (the default) so the layer loops. */
|
|
3550
|
+
repeat: z.boolean().optional(),
|
|
3551
|
+
/** Repeat vertically, for an endless climb. */
|
|
3552
|
+
repeatY: z.boolean().optional()
|
|
3553
|
+
}).strict().superRefine((layer, ctx) => {
|
|
3554
|
+
const sources = [layer.asset, layer.file, layer.sky].filter((value) => value !== void 0).length;
|
|
3555
|
+
if (sources !== 1) {
|
|
3556
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "a layer needs exactly one of asset, file, or sky" });
|
|
3557
|
+
}
|
|
3558
|
+
if (layer.style !== void 0 && layer.asset === void 0) {
|
|
3559
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["style"], message: "style only applies to an asset layer" });
|
|
3560
|
+
}
|
|
3561
|
+
});
|
|
3562
|
+
var ParallaxSetSchema = z.object({
|
|
3563
|
+
/** The game's view in pixels, [width, height]. */
|
|
3564
|
+
view: z.tuple([z.number().int().min(8).max(4096), z.number().int().min(8).max(4096)]),
|
|
3565
|
+
/** How far the camera moves sideways across the level, in pixels. */
|
|
3566
|
+
travel: z.number().int().min(0).max(1e5).optional(),
|
|
3567
|
+
/** How far the camera climbs, in pixels. */
|
|
3568
|
+
climb: z.number().int().min(0).max(1e5).optional(),
|
|
3569
|
+
layers: z.array(ParallaxLayerSchema).min(1).max(32)
|
|
3570
|
+
}).strict();
|
|
3571
|
+
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");
|
|
3509
3572
|
var ManifestSchema = z.object({
|
|
3510
3573
|
$schema: z.string().optional(),
|
|
3511
3574
|
name: z.string(),
|
|
@@ -3514,7 +3577,9 @@ var ManifestSchema = z.object({
|
|
|
3514
3577
|
/** Replaced generations kept per asset for this project; overrides PIXELKILN_HISTORY. 0 keeps none. */
|
|
3515
3578
|
history: HistoryLimitSchema.optional(),
|
|
3516
3579
|
styles: z.record(StyleSchema),
|
|
3517
|
-
assets: z.record(AssetSchema)
|
|
3580
|
+
assets: z.record(AssetSchema),
|
|
3581
|
+
/** Parallax backgrounds built from the assets, by set id. */
|
|
3582
|
+
parallax: z.record(ParallaxSetIdSchema, ParallaxSetSchema).optional()
|
|
3518
3583
|
}).strict();
|
|
3519
3584
|
var ManifestInputSchema = z.object({
|
|
3520
3585
|
$schema: z.string().optional(),
|
|
@@ -3522,7 +3587,8 @@ var ManifestInputSchema = z.object({
|
|
|
3522
3587
|
provider: z.string().min(1).default("pixellab"),
|
|
3523
3588
|
history: HistoryLimitSchema.optional(),
|
|
3524
3589
|
styles: z.record(StyleInputSchema),
|
|
3525
|
-
assets: z.record(AssetSchema)
|
|
3590
|
+
assets: z.record(AssetSchema),
|
|
3591
|
+
parallax: z.record(ParallaxSetIdSchema, ParallaxSetSchema).optional()
|
|
3526
3592
|
}).strict();
|
|
3527
3593
|
var LockOutputSchema = z.object({
|
|
3528
3594
|
path: z.string(),
|
|
@@ -9197,9 +9263,9 @@ var PixelLabClient = class {
|
|
|
9197
9263
|
apiKey;
|
|
9198
9264
|
http;
|
|
9199
9265
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
9200
|
-
async request(
|
|
9266
|
+
async request(path79, init) {
|
|
9201
9267
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
9202
|
-
const res = await this.http(`${BASE}${
|
|
9268
|
+
const res = await this.http(`${BASE}${path79}`, {
|
|
9203
9269
|
...init,
|
|
9204
9270
|
headers: {
|
|
9205
9271
|
Authorization: auth,
|
|
@@ -9210,13 +9276,13 @@ var PixelLabClient = class {
|
|
|
9210
9276
|
const text = await res.text();
|
|
9211
9277
|
if (!res.ok) {
|
|
9212
9278
|
const hint = res.status === 500 && text.includes("Failed to start any animation jobs") ? '; a skeleton-v3 loop needs a character with a stored 3D skeleton (a v3 base), use mode: "template" on a standard one' : "";
|
|
9213
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
9279
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path79} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
9214
9280
|
}
|
|
9215
9281
|
if (!text) return {};
|
|
9216
9282
|
try {
|
|
9217
9283
|
return JSON.parse(text);
|
|
9218
9284
|
} catch {
|
|
9219
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
9285
|
+
throw new Error(`${init?.method ?? "GET"} ${path79} returned invalid JSON`);
|
|
9220
9286
|
}
|
|
9221
9287
|
}
|
|
9222
9288
|
async balance() {
|
|
@@ -9763,10 +9829,10 @@ var PixelLabClient = class {
|
|
|
9763
9829
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
9764
9830
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
9765
9831
|
const south = args.reference?.south;
|
|
9766
|
-
let
|
|
9832
|
+
let path79;
|
|
9767
9833
|
let body;
|
|
9768
9834
|
if (args.mode === "v3") {
|
|
9769
|
-
|
|
9835
|
+
path79 = "/create-character-v3";
|
|
9770
9836
|
body = {
|
|
9771
9837
|
description: args.description,
|
|
9772
9838
|
image_size: imageSize,
|
|
@@ -9780,7 +9846,7 @@ var PixelLabClient = class {
|
|
|
9780
9846
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
9781
9847
|
};
|
|
9782
9848
|
} else if (args.mode === "pro-flash") {
|
|
9783
|
-
|
|
9849
|
+
path79 = "/create-character-pro-flash";
|
|
9784
9850
|
const traits = args.styleTraits;
|
|
9785
9851
|
body = {
|
|
9786
9852
|
description: args.description,
|
|
@@ -9804,7 +9870,7 @@ var PixelLabClient = class {
|
|
|
9804
9870
|
} : {}
|
|
9805
9871
|
};
|
|
9806
9872
|
} else if (args.mode === "pro") {
|
|
9807
|
-
|
|
9873
|
+
path79 = "/create-character-pro";
|
|
9808
9874
|
body = {
|
|
9809
9875
|
description: args.description,
|
|
9810
9876
|
image_size: imageSize,
|
|
@@ -9818,7 +9884,7 @@ var PixelLabClient = class {
|
|
|
9818
9884
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
9819
9885
|
};
|
|
9820
9886
|
} else {
|
|
9821
|
-
|
|
9887
|
+
path79 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
9822
9888
|
body = {
|
|
9823
9889
|
description: args.description,
|
|
9824
9890
|
image_size: imageSize,
|
|
@@ -9836,8 +9902,8 @@ var PixelLabClient = class {
|
|
|
9836
9902
|
};
|
|
9837
9903
|
}
|
|
9838
9904
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
9839
|
-
const raw = await this.request(
|
|
9840
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
9905
|
+
const raw = await this.request(path79, { method: "POST", body: JSON.stringify(body) });
|
|
9906
|
+
return validateResponse(CharacterSubmitSchema, raw, path79.slice(1));
|
|
9841
9907
|
}
|
|
9842
9908
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
9843
9909
|
async createCharacterState(args) {
|
|
@@ -15233,9 +15299,9 @@ var RetroDiffusionClient = class {
|
|
|
15233
15299
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
15234
15300
|
return Buffer.from(await response.arrayBuffer());
|
|
15235
15301
|
}
|
|
15236
|
-
async call(
|
|
15302
|
+
async call(path79, init = {}) {
|
|
15237
15303
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
15238
|
-
const response = await this.request(`${this.baseUrl}${
|
|
15304
|
+
const response = await this.request(`${this.baseUrl}${path79}`, {
|
|
15239
15305
|
...init,
|
|
15240
15306
|
headers: {
|
|
15241
15307
|
"Content-Type": "application/json",
|
|
@@ -16517,6 +16583,25 @@ ${issues}`);
|
|
|
16517
16583
|
connectVisited.add(assetId);
|
|
16518
16584
|
};
|
|
16519
16585
|
for (const assetId of Object.keys(parsed.data.assets)) visitConnections(assetId);
|
|
16586
|
+
for (const [setId, set] of Object.entries(parsed.data.parallax ?? {})) {
|
|
16587
|
+
const names = /* @__PURE__ */ new Set();
|
|
16588
|
+
set.layers.forEach((layer, index) => {
|
|
16589
|
+
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`);
|
|
16597
|
+
}
|
|
16598
|
+
}
|
|
16599
|
+
if (layer.name !== void 0) {
|
|
16600
|
+
if (names.has(layer.name)) unknownReferences.push(`${at2}.name: "${layer.name}" is used twice`);
|
|
16601
|
+
names.add(layer.name);
|
|
16602
|
+
}
|
|
16603
|
+
});
|
|
16604
|
+
}
|
|
16520
16605
|
if (unknownReferences.length) {
|
|
16521
16606
|
throw new ProjectError(`Manifest at ${abs} is invalid:
|
|
16522
16607
|
${unknownReferences.map((i) => ` ${i}`).join("\n")}`);
|
|
@@ -18546,10 +18631,10 @@ function isSha256Hash(value) {
|
|
|
18546
18631
|
function parseCache(value) {
|
|
18547
18632
|
return HashCacheSchema.parse(value);
|
|
18548
18633
|
}
|
|
18549
|
-
async function loadCache(
|
|
18550
|
-
if (!existsSync18(
|
|
18634
|
+
async function loadCache(path79) {
|
|
18635
|
+
if (!existsSync18(path79)) return { version: 1, hashes: {} };
|
|
18551
18636
|
try {
|
|
18552
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(
|
|
18637
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path79, "utf8")));
|
|
18553
18638
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
18554
18639
|
return {
|
|
18555
18640
|
version: 1,
|
|
@@ -18561,18 +18646,18 @@ async function loadCache(path77) {
|
|
|
18561
18646
|
return { version: 1, hashes: {} };
|
|
18562
18647
|
}
|
|
18563
18648
|
}
|
|
18564
|
-
async function saveCache(
|
|
18649
|
+
async function saveCache(path79, cache) {
|
|
18565
18650
|
const sorted = {};
|
|
18566
18651
|
for (const key3 of Object.keys(cache.hashes).sort()) {
|
|
18567
18652
|
const hash = cache.hashes[key3];
|
|
18568
18653
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key3}`);
|
|
18569
18654
|
sorted[key3] = hash;
|
|
18570
18655
|
}
|
|
18571
|
-
await mkdir9(pathModule.dirname(pathModule.resolve(
|
|
18572
|
-
const tmp = `${
|
|
18656
|
+
await mkdir9(pathModule.dirname(pathModule.resolve(path79)), { recursive: true });
|
|
18657
|
+
const tmp = `${path79}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18573
18658
|
try {
|
|
18574
18659
|
await writeFile9(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
18575
|
-
await rename7(tmp,
|
|
18660
|
+
await rename7(tmp, path79);
|
|
18576
18661
|
} finally {
|
|
18577
18662
|
await rm5(tmp, { force: true });
|
|
18578
18663
|
}
|
|
@@ -22847,13 +22932,13 @@ function poseNodes(document, pose) {
|
|
|
22847
22932
|
const posed = /* @__PURE__ */ new Map();
|
|
22848
22933
|
for (const channel of animation.channels) {
|
|
22849
22934
|
const node = channel.target.node;
|
|
22850
|
-
const
|
|
22851
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
22935
|
+
const path79 = channel.target.path;
|
|
22936
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path79)) continue;
|
|
22852
22937
|
const sampler = animation.samplers[channel.sampler];
|
|
22853
22938
|
if (!sampler) continue;
|
|
22854
22939
|
const times = readAccessor(document, sampler.input).data;
|
|
22855
22940
|
const values = readAccessor(document, sampler.output);
|
|
22856
|
-
const width =
|
|
22941
|
+
const width = path79 === "rotation" ? 4 : 3;
|
|
22857
22942
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
22858
22943
|
const valueAt = (key4) => Array.from(values.data.subarray((cubic ? key4 * 3 + 1 : key4) * width, (cubic ? key4 * 3 + 1 : key4) * width + width));
|
|
22859
22944
|
const last = times.length - 1;
|
|
@@ -22865,16 +22950,16 @@ function poseNodes(document, pose) {
|
|
|
22865
22950
|
const span = times[key3 + 1] - times[key3];
|
|
22866
22951
|
const f = span > 0 ? (time - times[key3]) / span : 0;
|
|
22867
22952
|
const next = valueAt(key3 + 1);
|
|
22868
|
-
const sign =
|
|
22953
|
+
const sign = path79 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
22869
22954
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
22870
22955
|
}
|
|
22871
|
-
if (
|
|
22956
|
+
if (path79 === "rotation") {
|
|
22872
22957
|
const length = Math.hypot(...value) || 1;
|
|
22873
22958
|
value = value.map((v) => v / length);
|
|
22874
22959
|
}
|
|
22875
22960
|
const base = posed.get(node) ?? { ...document.json.nodes?.[node] ?? {} };
|
|
22876
22961
|
if (base.matrix) delete base.matrix;
|
|
22877
|
-
base[
|
|
22962
|
+
base[path79] = value;
|
|
22878
22963
|
posed.set(node, base);
|
|
22879
22964
|
}
|
|
22880
22965
|
return posed;
|
|
@@ -35501,13 +35586,729 @@ async function runAnchors(args) {
|
|
|
35501
35586
|
}
|
|
35502
35587
|
}
|
|
35503
35588
|
|
|
35504
|
-
// src/cli/commands/
|
|
35589
|
+
// src/cli/commands/parallax.ts
|
|
35505
35590
|
import path74 from "path";
|
|
35506
35591
|
|
|
35592
|
+
// src/pipeline/parallax.ts
|
|
35593
|
+
import { createHash as createHash9 } from "crypto";
|
|
35594
|
+
import { readFile as readFile50 } from "fs/promises";
|
|
35595
|
+
import path73 from "path";
|
|
35596
|
+
var PARALLAX_FORMATS = ["tiled", "godot", "ldtk"];
|
|
35597
|
+
var SEAM_WARN_RATIO = 2;
|
|
35598
|
+
var BAYER4 = [
|
|
35599
|
+
[0, 8, 2, 10],
|
|
35600
|
+
[12, 4, 14, 6],
|
|
35601
|
+
[3, 11, 1, 9],
|
|
35602
|
+
[15, 7, 13, 5]
|
|
35603
|
+
];
|
|
35604
|
+
function skyBands(width, height, colors, blend = 8) {
|
|
35605
|
+
const rgb = colors.map((color) => parseHex(color));
|
|
35606
|
+
const n = rgb.length;
|
|
35607
|
+
const pixels = Buffer.alloc(width * height * 4);
|
|
35608
|
+
for (let y = 0; y < height; y++) {
|
|
35609
|
+
const band = Math.min(Math.floor(y / height * n), n - 1);
|
|
35610
|
+
const rowsLeft = (band + 1) * height / n - y;
|
|
35611
|
+
const share = band < n - 1 && rowsLeft <= blend ? 1 - rowsLeft / (blend + 1) : 0;
|
|
35612
|
+
for (let x = 0; x < width; x++) {
|
|
35613
|
+
const next = share > 0 && BAYER4[y % 4][x % 4] < share * 16;
|
|
35614
|
+
const color = rgb[next ? band + 1 : band];
|
|
35615
|
+
const at2 = (y * width + x) * 4;
|
|
35616
|
+
pixels[at2] = color.r;
|
|
35617
|
+
pixels[at2 + 1] = color.g;
|
|
35618
|
+
pixels[at2 + 2] = color.b;
|
|
35619
|
+
pixels[at2 + 3] = 255;
|
|
35620
|
+
}
|
|
35621
|
+
}
|
|
35622
|
+
return { width, height, pixels };
|
|
35623
|
+
}
|
|
35624
|
+
function transpose(png) {
|
|
35625
|
+
const pixels = Buffer.alloc(png.pixels.length);
|
|
35626
|
+
for (let y = 0; y < png.height; y++) {
|
|
35627
|
+
for (let x = 0; x < png.width; x++) png.pixels.copy(pixels, (x * png.height + y) * 4, (y * png.width + x) * 4, (y * png.width + x) * 4 + 4);
|
|
35628
|
+
}
|
|
35629
|
+
return { width: png.height, height: png.width, pixels };
|
|
35630
|
+
}
|
|
35631
|
+
function columnDiff(png, a, b) {
|
|
35632
|
+
let sum = 0;
|
|
35633
|
+
for (let y = 0; y < png.height; y++) {
|
|
35634
|
+
const pa = (y * png.width + a) * 4;
|
|
35635
|
+
const pb = (y * png.width + b) * 4;
|
|
35636
|
+
const alphaA = png.pixels[pa + 3];
|
|
35637
|
+
const alphaB = png.pixels[pb + 3];
|
|
35638
|
+
for (let c = 0; c < 3; c++) {
|
|
35639
|
+
sum += Math.abs(Math.floor(png.pixels[pa + c] * alphaA / 255) - Math.floor(png.pixels[pb + c] * alphaB / 255));
|
|
35640
|
+
}
|
|
35641
|
+
sum += Math.abs(alphaA - alphaB);
|
|
35642
|
+
}
|
|
35643
|
+
return sum / (png.height * 4);
|
|
35644
|
+
}
|
|
35645
|
+
function seamRatio(png) {
|
|
35646
|
+
if (png.width < 3) return 0;
|
|
35647
|
+
const inner = [];
|
|
35648
|
+
for (let x = 0; x < png.width - 1; x++) {
|
|
35649
|
+
const step = columnDiff(png, x, x + 1);
|
|
35650
|
+
if (step > 0) inner.push(step);
|
|
35651
|
+
}
|
|
35652
|
+
const seam = columnDiff(png, png.width - 1, 0);
|
|
35653
|
+
if (!inner.length) return seam > 0 ? Infinity : 0;
|
|
35654
|
+
inner.sort((a, b) => a - b);
|
|
35655
|
+
return seam / inner[Math.floor(inner.length / 2)];
|
|
35656
|
+
}
|
|
35657
|
+
function layerName(layer, index) {
|
|
35658
|
+
if (layer.name) return layer.name;
|
|
35659
|
+
const base = layer.asset ?? (layer.file ? path73.basename(layer.file, path73.extname(layer.file)) : "sky");
|
|
35660
|
+
const slug3 = base.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[^A-Za-z]+/, "");
|
|
35661
|
+
return slug3 || `layer${index + 1}`;
|
|
35662
|
+
}
|
|
35663
|
+
async function resolveParallaxSet(manifest, manifestDir, lock, setId) {
|
|
35664
|
+
const set = manifest.parallax?.[setId];
|
|
35665
|
+
if (!set) {
|
|
35666
|
+
const known = Object.keys(manifest.parallax ?? {});
|
|
35667
|
+
throw new Error(`No parallax set "${setId}". ${known.length ? `Known: ${known.join(", ")}` : "The manifest has no parallax sets."}`);
|
|
35668
|
+
}
|
|
35669
|
+
const [viewW, viewH] = set.view;
|
|
35670
|
+
const travel = set.travel ?? viewW * 2;
|
|
35671
|
+
const climb = set.climb ?? 0;
|
|
35672
|
+
const warnings = [];
|
|
35673
|
+
const layers = [];
|
|
35674
|
+
const taken = /* @__PURE__ */ new Set();
|
|
35675
|
+
for (const [index, layer] of set.layers.entries()) {
|
|
35676
|
+
let name = layerName(layer, index);
|
|
35677
|
+
for (let n = 2; taken.has(name); n++) name = `${layerName(layer, index)}_${n}`;
|
|
35678
|
+
taken.add(name);
|
|
35679
|
+
const speedY = layer.speedY ?? (climb > 0 ? layer.speed : 1);
|
|
35680
|
+
let png;
|
|
35681
|
+
let source;
|
|
35682
|
+
if (layer.sky) {
|
|
35683
|
+
png = skyBands(viewW, viewH + Math.ceil(climb * speedY), layer.sky);
|
|
35684
|
+
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 };
|
|
35689
|
+
} 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}`);
|
|
35700
|
+
}
|
|
35701
|
+
const repeat = layer.repeat ?? true;
|
|
35702
|
+
let bottom = layer.bottom ?? viewH;
|
|
35703
|
+
if (layer.extend) {
|
|
35704
|
+
const rows = layer.extend === true ? Math.max(0, viewH - bottom) : layer.extend;
|
|
35705
|
+
png = extendDown(png, rows);
|
|
35706
|
+
bottom += rows;
|
|
35707
|
+
}
|
|
35708
|
+
const image = {
|
|
35709
|
+
name,
|
|
35710
|
+
png,
|
|
35711
|
+
speed: layer.speed,
|
|
35712
|
+
speedY,
|
|
35713
|
+
x: layer.x ?? 0,
|
|
35714
|
+
y: bottom - png.height,
|
|
35715
|
+
repeat,
|
|
35716
|
+
repeatY: layer.repeatY ?? false,
|
|
35717
|
+
source
|
|
35718
|
+
};
|
|
35719
|
+
if (repeat && source.kind !== "sky") {
|
|
35720
|
+
image.seamRatio = seamRatio(png);
|
|
35721
|
+
if (travel * layer.speed > 0 && image.seamRatio > SEAM_WARN_RATIO) {
|
|
35722
|
+
warnings.push(
|
|
35723
|
+
`${name}: its sideways join is ${image.seamRatio.toFixed(1)} times rougher than the picture's own steps; loop it first (research/scripts/parallax.py loop) or set repeat: false`
|
|
35724
|
+
);
|
|
35725
|
+
}
|
|
35726
|
+
}
|
|
35727
|
+
if (image.repeatY && source.kind !== "sky") {
|
|
35728
|
+
image.seamRatioY = seamRatio(transpose(png));
|
|
35729
|
+
if (climb * speedY > 0 && image.seamRatioY > SEAM_WARN_RATIO) {
|
|
35730
|
+
warnings.push(`${name}: its vertical join is ${image.seamRatioY.toFixed(1)} times rougher than the picture's own steps`);
|
|
35731
|
+
}
|
|
35732
|
+
}
|
|
35733
|
+
if (climb > 0 && !image.repeatY && png.width >= viewW && image.y <= 0) {
|
|
35734
|
+
const shown2 = Math.round(climb * speedY);
|
|
35735
|
+
if (image.y + shown2 > 0) {
|
|
35736
|
+
warnings.push(`${name}: fills the top of the view at the start, but ${image.y + shown2} empty row(s) show above it at the top of the climb; draw it taller or set repeatY`);
|
|
35737
|
+
}
|
|
35738
|
+
}
|
|
35739
|
+
if (!repeat && png.width >= viewW) {
|
|
35740
|
+
const needed = viewW + Math.ceil(travel * layer.speed);
|
|
35741
|
+
if (image.x > 0 || image.x + png.width < needed) {
|
|
35742
|
+
warnings.push(`${name}: does not repeat and covers columns ${image.x}..${image.x + png.width}; the camera shows 0..${needed} of it`);
|
|
35743
|
+
}
|
|
35744
|
+
}
|
|
35745
|
+
layers.push(image);
|
|
35746
|
+
}
|
|
35747
|
+
return { id: setId, view: [viewW, viewH], travel, climb, layers, warnings };
|
|
35748
|
+
}
|
|
35749
|
+
function extendDown(png, rows) {
|
|
35750
|
+
if (rows <= 0) return png;
|
|
35751
|
+
const height = png.height + rows;
|
|
35752
|
+
const pixels = Buffer.alloc(png.width * height * 4);
|
|
35753
|
+
png.pixels.copy(pixels, 0);
|
|
35754
|
+
const last = png.pixels.subarray((png.height - 1) * png.width * 4, png.height * png.width * 4);
|
|
35755
|
+
for (let y = png.height; y < height; y++) last.copy(pixels, y * png.width * 4);
|
|
35756
|
+
return { width: png.width, height, pixels };
|
|
35757
|
+
}
|
|
35758
|
+
function layerScreenOffset(layer, camX, camY) {
|
|
35759
|
+
return { dx: Math.round(-Math.round(camX) * layer.speed), dy: Math.round(Math.round(camY) * layer.speedY) };
|
|
35760
|
+
}
|
|
35761
|
+
function composeParallaxFrame(set, camX, camY) {
|
|
35762
|
+
const [w, h] = set.view;
|
|
35763
|
+
const out = { width: w, height: h, pixels: Buffer.alloc(w * h * 4) };
|
|
35764
|
+
for (const layer of set.layers) {
|
|
35765
|
+
const { dx, dy } = layerScreenOffset(layer, camX, camY);
|
|
35766
|
+
drawLayer(out, layer, layer.x + dx, layer.y + dy);
|
|
35767
|
+
}
|
|
35768
|
+
return out;
|
|
35769
|
+
}
|
|
35770
|
+
function drawLayer(out, layer, left, top) {
|
|
35771
|
+
const { width: w, height: h } = out;
|
|
35772
|
+
const lw = layer.png.width;
|
|
35773
|
+
const lh = layer.png.height;
|
|
35774
|
+
for (let sy = 0; sy < h; sy++) {
|
|
35775
|
+
let ly = sy - top;
|
|
35776
|
+
if (layer.repeatY) ly = (ly % lh + lh) % lh;
|
|
35777
|
+
else if (ly < 0 || ly >= lh) continue;
|
|
35778
|
+
for (let sx = 0; sx < w; sx++) {
|
|
35779
|
+
let lx = sx - left;
|
|
35780
|
+
if (layer.repeat) lx = (lx % lw + lw) % lw;
|
|
35781
|
+
else if (lx < 0 || lx >= lw) continue;
|
|
35782
|
+
const src = (ly * lw + lx) * 4;
|
|
35783
|
+
const alpha = layer.png.pixels[src + 3] / 255;
|
|
35784
|
+
if (alpha === 0) continue;
|
|
35785
|
+
const dst = (sy * w + sx) * 4;
|
|
35786
|
+
const below = out.pixels[dst + 3] / 255;
|
|
35787
|
+
const outAlpha = alpha + below * (1 - alpha);
|
|
35788
|
+
for (let c = 0; c < 3; c++) {
|
|
35789
|
+
out.pixels[dst + c] = Math.round((layer.png.pixels[src + c] * alpha + out.pixels[dst + c] * below * (1 - alpha)) / outAlpha);
|
|
35790
|
+
}
|
|
35791
|
+
out.pixels[dst + 3] = Math.round(outAlpha * 255);
|
|
35792
|
+
}
|
|
35793
|
+
}
|
|
35794
|
+
}
|
|
35795
|
+
function cameraPath(set, frames) {
|
|
35796
|
+
return Array.from({ length: frames }, (_, i) => {
|
|
35797
|
+
const t = frames === 1 ? 0 : i / (frames - 1);
|
|
35798
|
+
const e = (1 - Math.cos(t * Math.PI)) / 2;
|
|
35799
|
+
return [Math.round(e * set.travel), Math.round(e * set.climb)];
|
|
35800
|
+
});
|
|
35801
|
+
}
|
|
35802
|
+
function layerPngs(set, base) {
|
|
35803
|
+
return set.layers.map((layer) => ({
|
|
35804
|
+
layer,
|
|
35805
|
+
file: `${path73.basename(base)}-${layer.name}.png`,
|
|
35806
|
+
png: encodeRgbaPng(layer.png.width, layer.png.height, layer.png.pixels)
|
|
35807
|
+
}));
|
|
35808
|
+
}
|
|
35809
|
+
function exportTiled(set, base) {
|
|
35810
|
+
const [vw, vh] = set.view;
|
|
35811
|
+
const grid = 16;
|
|
35812
|
+
const mapW = vw + set.travel;
|
|
35813
|
+
const mapH = vh + set.climb;
|
|
35814
|
+
const pictures = layerPngs(set, base);
|
|
35815
|
+
const layers = pictures.map(({ layer, file }, index) => ({
|
|
35816
|
+
id: index + 1,
|
|
35817
|
+
name: layer.name,
|
|
35818
|
+
type: "imagelayer",
|
|
35819
|
+
image: file,
|
|
35820
|
+
imagewidth: layer.png.width,
|
|
35821
|
+
imageheight: layer.png.height,
|
|
35822
|
+
offsetx: tiledNumber(layer.x - (1 - layer.speed) * (vw / 2)),
|
|
35823
|
+
offsety: tiledNumber(layer.y + set.climb - (1 - layer.speedY) * (set.climb + vh / 2)),
|
|
35824
|
+
parallaxx: layer.speed,
|
|
35825
|
+
parallaxy: layer.speedY,
|
|
35826
|
+
repeatx: layer.repeat,
|
|
35827
|
+
repeaty: layer.repeatY,
|
|
35828
|
+
opacity: 1,
|
|
35829
|
+
visible: true,
|
|
35830
|
+
x: 0,
|
|
35831
|
+
y: 0
|
|
35832
|
+
}));
|
|
35833
|
+
const map = {
|
|
35834
|
+
type: "map",
|
|
35835
|
+
version: "1.10",
|
|
35836
|
+
tiledversion: "1.11.0",
|
|
35837
|
+
orientation: "orthogonal",
|
|
35838
|
+
renderorder: "right-down",
|
|
35839
|
+
infinite: false,
|
|
35840
|
+
width: Math.ceil(mapW / grid),
|
|
35841
|
+
height: Math.ceil(mapH / grid),
|
|
35842
|
+
tilewidth: grid,
|
|
35843
|
+
tileheight: grid,
|
|
35844
|
+
nextlayerid: layers.length + 1,
|
|
35845
|
+
nextobjectid: 1,
|
|
35846
|
+
compressionlevel: -1,
|
|
35847
|
+
tilesets: [],
|
|
35848
|
+
layers,
|
|
35849
|
+
properties: [
|
|
35850
|
+
{ name: "pixelkiln_view", type: "string", value: `${vw}x${vh}` },
|
|
35851
|
+
{ name: "pixelkiln_start", type: "string", value: `0,${set.climb}` }
|
|
35852
|
+
]
|
|
35853
|
+
};
|
|
35854
|
+
return {
|
|
35855
|
+
files: [{ path: `${base}.tmj`, data: JSON.stringify(map, null, 2) + "\n" }, ...pictures.map((p) => ({ path: path73.join(path73.dirname(base), p.file), data: p.png }))],
|
|
35856
|
+
options: { format: "tiled", start: [0, set.climb] }
|
|
35857
|
+
};
|
|
35858
|
+
}
|
|
35859
|
+
function tiledNumber(value) {
|
|
35860
|
+
return Number(value.toFixed(6));
|
|
35861
|
+
}
|
|
35862
|
+
function godotNumber(value) {
|
|
35863
|
+
return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(6)));
|
|
35864
|
+
}
|
|
35865
|
+
function exportGodot(set, base) {
|
|
35866
|
+
const [vw, vh] = set.view;
|
|
35867
|
+
const pictures = layerPngs(set, base);
|
|
35868
|
+
const lines = [`[gd_scene load_steps=${pictures.length + 1} format=3]`, ""];
|
|
35869
|
+
pictures.forEach(({ file }, index) => {
|
|
35870
|
+
lines.push(`[ext_resource type="Texture2D" path=${JSON.stringify(`./${file}`)} id="${index + 1}_layer"]`);
|
|
35871
|
+
});
|
|
35872
|
+
lines.push("", `[node name=${JSON.stringify(path73.basename(base))} type="Node2D"]`, "texture_filter = 1");
|
|
35873
|
+
pictures.forEach(({ layer }, index) => {
|
|
35874
|
+
lines.push("", `[node name=${JSON.stringify(layer.name)} type="Parallax2D" parent="."]`);
|
|
35875
|
+
lines.push(`scroll_scale = Vector2(${godotNumber(layer.speed)}, ${godotNumber(layer.speedY)})`);
|
|
35876
|
+
const offsetY = -set.climb * (1 - layer.speedY);
|
|
35877
|
+
if (offsetY !== 0) lines.push(`scroll_offset = Vector2(0, ${godotNumber(offsetY)})`);
|
|
35878
|
+
if (layer.repeat || layer.repeatY) {
|
|
35879
|
+
lines.push(`repeat_size = Vector2(${layer.repeat ? layer.png.width : 0}, ${layer.repeatY ? layer.png.height : 0})`);
|
|
35880
|
+
const reach = (view, size) => 2 * (Math.ceil(view / size) + 1) - 1;
|
|
35881
|
+
const times = Math.max(layer.repeat ? reach(vw, layer.png.width) : 1, layer.repeatY ? reach(vh, layer.png.height) : 1);
|
|
35882
|
+
lines.push(`repeat_times = ${times}`);
|
|
35883
|
+
}
|
|
35884
|
+
lines.push("", `[node name="Sprite2D" type="Sprite2D" parent=${JSON.stringify(layer.name)}]`);
|
|
35885
|
+
lines.push(`texture = ExtResource("${index + 1}_layer")`, "centered = false");
|
|
35886
|
+
const mod = (value, size) => (value % size + size) % size;
|
|
35887
|
+
const px = layer.repeat ? mod(layer.x, layer.png.width) : layer.x;
|
|
35888
|
+
const py = layer.repeatY ? mod(layer.y + set.climb, layer.png.height) : layer.y + set.climb;
|
|
35889
|
+
lines.push(`position = Vector2(${px}, ${py})`);
|
|
35890
|
+
});
|
|
35891
|
+
return {
|
|
35892
|
+
files: [{ path: `${base}.tscn`, data: lines.join("\n") + "\n" }, ...pictures.map((p) => ({ path: path73.join(path73.dirname(base), p.file), data: p.png }))],
|
|
35893
|
+
options: { format: "godot", start: [0, set.climb] }
|
|
35894
|
+
};
|
|
35895
|
+
}
|
|
35896
|
+
function uuid(...parts) {
|
|
35897
|
+
const hex2 = createHash9("sha256").update(parts.join("\0")).digest("hex");
|
|
35898
|
+
return `${hex2.slice(0, 8)}-${hex2.slice(8, 12)}-4${hex2.slice(13, 16)}-8${hex2.slice(17, 20)}-${hex2.slice(20, 32)}`;
|
|
35899
|
+
}
|
|
35900
|
+
var LDTK_GRID = 16;
|
|
35901
|
+
function exportLdtk(set, base) {
|
|
35902
|
+
const [vw, vh] = set.view;
|
|
35903
|
+
const grid = LDTK_GRID;
|
|
35904
|
+
const levelW = vw + set.travel;
|
|
35905
|
+
const levelH = vh + set.climb;
|
|
35906
|
+
const name = path73.basename(base);
|
|
35907
|
+
const files = [];
|
|
35908
|
+
const warnings = [];
|
|
35909
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
35910
|
+
const layerDefs = [];
|
|
35911
|
+
const tilesets = [];
|
|
35912
|
+
const layerInstances = [];
|
|
35913
|
+
const levelUid = 1e3;
|
|
35914
|
+
let uid = 1;
|
|
35915
|
+
for (const [index, layer] of set.layers.entries()) {
|
|
35916
|
+
const factorX = 1 - layer.speed;
|
|
35917
|
+
const factorY = 1 - layer.speedY;
|
|
35918
|
+
const x0 = 0;
|
|
35919
|
+
const x1 = vw + Math.ceil(set.travel * layer.speed);
|
|
35920
|
+
const y0 = -Math.ceil(set.climb * layer.speedY);
|
|
35921
|
+
const y1 = vh;
|
|
35922
|
+
const place = (canvas, start, extent2, factor) => {
|
|
35923
|
+
let best = { off: 0, rounded: 0, frac: Infinity };
|
|
35924
|
+
for (let off = 0; off < grid; off++) {
|
|
35925
|
+
const shift = off + (start - (extent2 - off) / 2) * factor;
|
|
35926
|
+
const frac = Math.abs(shift - Math.round(shift));
|
|
35927
|
+
if (frac < best.frac - 1e-9) best = { off, rounded: Math.round(shift), frac };
|
|
35928
|
+
}
|
|
35929
|
+
const pad = ((canvas - best.rounded) % grid + grid) % grid;
|
|
35930
|
+
return { off: best.off, pad, cell: (canvas - best.rounded - pad) / grid, cells: Math.ceil((extent2 - best.off) / grid) };
|
|
35931
|
+
};
|
|
35932
|
+
const px = place(x0, vw / 2, levelW, factorX);
|
|
35933
|
+
const py = place(y0 + set.climb, levelH - vh / 2, levelH, factorY);
|
|
35934
|
+
const offX = px.off;
|
|
35935
|
+
const offY = py.off;
|
|
35936
|
+
const cols = Math.ceil((px.pad + x1 - x0) / grid);
|
|
35937
|
+
const rows = Math.ceil((py.pad + y1 - y0) / grid);
|
|
35938
|
+
const span = { width: cols * grid, height: rows * grid, pixels: Buffer.alloc(cols * grid * rows * grid * 4) };
|
|
35939
|
+
drawLayer(span, layer, px.pad + layer.x - x0, py.pad + layer.y - y0);
|
|
35940
|
+
const file = `${name}-${layer.name}.png`;
|
|
35941
|
+
files.push({ path: path73.join(path73.dirname(base), file), data: encodeRgbaPng(span.width, span.height, span.pixels) });
|
|
35942
|
+
const tilesetUid = uid++;
|
|
35943
|
+
const layerUid = uid++;
|
|
35944
|
+
let identifier2 = layer.name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
35945
|
+
for (let n = 2; identifiers.has(identifier2); n++) identifier2 = `${layer.name.replace(/[^A-Za-z0-9_]/g, "_")}_${n}`;
|
|
35946
|
+
identifiers.add(identifier2);
|
|
35947
|
+
tilesets.push({
|
|
35948
|
+
__cWid: cols,
|
|
35949
|
+
__cHei: rows,
|
|
35950
|
+
identifier: `${identifier2}_tiles`,
|
|
35951
|
+
uid: tilesetUid,
|
|
35952
|
+
relPath: file,
|
|
35953
|
+
embedAtlas: null,
|
|
35954
|
+
pxWid: span.width,
|
|
35955
|
+
pxHei: span.height,
|
|
35956
|
+
tileGridSize: grid,
|
|
35957
|
+
spacing: 0,
|
|
35958
|
+
padding: 0,
|
|
35959
|
+
tags: [],
|
|
35960
|
+
tagsSourceEnumUid: null,
|
|
35961
|
+
enumTags: [],
|
|
35962
|
+
customData: [],
|
|
35963
|
+
savedSelections: [],
|
|
35964
|
+
cachedPixelData: null
|
|
35965
|
+
});
|
|
35966
|
+
layerDefs.push({
|
|
35967
|
+
__type: "Tiles",
|
|
35968
|
+
identifier: identifier2,
|
|
35969
|
+
type: "Tiles",
|
|
35970
|
+
uid: layerUid,
|
|
35971
|
+
doc: `Moves ${layer.speed} of the camera's speed sideways and ${layer.speedY} vertically.`,
|
|
35972
|
+
uiColor: null,
|
|
35973
|
+
gridSize: grid,
|
|
35974
|
+
guideGridWid: 0,
|
|
35975
|
+
guideGridHei: 0,
|
|
35976
|
+
displayOpacity: 1,
|
|
35977
|
+
inactiveOpacity: 1,
|
|
35978
|
+
hideInList: false,
|
|
35979
|
+
hideFieldsWhenInactive: true,
|
|
35980
|
+
canSelectWhenInactive: true,
|
|
35981
|
+
renderInWorldView: true,
|
|
35982
|
+
pxOffsetX: 0,
|
|
35983
|
+
pxOffsetY: 0,
|
|
35984
|
+
parallaxFactorX: Number(factorX.toFixed(6)),
|
|
35985
|
+
parallaxFactorY: Number(factorY.toFixed(6)),
|
|
35986
|
+
parallaxScaling: false,
|
|
35987
|
+
requiredTags: [],
|
|
35988
|
+
excludedTags: [],
|
|
35989
|
+
autoTilesKilledByOtherLayerUid: null,
|
|
35990
|
+
uiFilterTags: [],
|
|
35991
|
+
useAsyncRender: false,
|
|
35992
|
+
intGridValues: [],
|
|
35993
|
+
intGridValuesGroups: [],
|
|
35994
|
+
autoRuleGroups: [],
|
|
35995
|
+
autoSourceLayerDefUid: null,
|
|
35996
|
+
tilesetDefUid: tilesetUid,
|
|
35997
|
+
tilePivotX: 0,
|
|
35998
|
+
tilePivotY: 0,
|
|
35999
|
+
biomeFieldUid: null
|
|
36000
|
+
});
|
|
36001
|
+
const cellsWide = px.cells;
|
|
36002
|
+
const cellsHigh = py.cells;
|
|
36003
|
+
const gridTiles = [];
|
|
36004
|
+
let dropped = 0;
|
|
36005
|
+
for (let r = 0; r < rows; r++) {
|
|
36006
|
+
for (let c = 0; c < cols; c++) {
|
|
36007
|
+
const cx = px.cell + c;
|
|
36008
|
+
const cy = py.cell + r;
|
|
36009
|
+
if (tileEmpty(span, c * grid, r * grid, grid)) continue;
|
|
36010
|
+
if (cx < 0 || cy < 0 || cx >= cellsWide || cy >= cellsHigh) {
|
|
36011
|
+
dropped++;
|
|
36012
|
+
continue;
|
|
36013
|
+
}
|
|
36014
|
+
gridTiles.push({ px: [cx * grid, cy * grid], src: [c * grid, r * grid], f: 0, t: r * cols + c, d: [cy * cellsWide + cx], a: 1 });
|
|
36015
|
+
}
|
|
36016
|
+
}
|
|
36017
|
+
if (dropped) {
|
|
36018
|
+
warnings.push(
|
|
36019
|
+
`${layer.name}: ${dropped} tile(s) fall past the level's edge, which LDtk does not draw` + (layer.speed > 1 || layer.speedY > 1 ? "; a layer faster than the camera shows more than the level holds" : "")
|
|
36020
|
+
);
|
|
36021
|
+
}
|
|
36022
|
+
layerInstances.unshift({
|
|
36023
|
+
__identifier: identifier2,
|
|
36024
|
+
__type: "Tiles",
|
|
36025
|
+
__cWid: cellsWide,
|
|
36026
|
+
__cHei: cellsHigh,
|
|
36027
|
+
__gridSize: grid,
|
|
36028
|
+
__opacity: 1,
|
|
36029
|
+
__pxTotalOffsetX: offX,
|
|
36030
|
+
__pxTotalOffsetY: offY,
|
|
36031
|
+
__tilesetDefUid: tilesetUid,
|
|
36032
|
+
__tilesetRelPath: file,
|
|
36033
|
+
iid: uuid(name, "layer", index),
|
|
36034
|
+
levelId: levelUid,
|
|
36035
|
+
layerDefUid: layerUid,
|
|
36036
|
+
pxOffsetX: offX,
|
|
36037
|
+
pxOffsetY: offY,
|
|
36038
|
+
visible: true,
|
|
36039
|
+
optionalRules: [],
|
|
36040
|
+
intGridCsv: [],
|
|
36041
|
+
autoLayerTiles: [],
|
|
36042
|
+
seed: 1e3 + index,
|
|
36043
|
+
overrideTilesetUid: null,
|
|
36044
|
+
gridTiles,
|
|
36045
|
+
entityInstances: []
|
|
36046
|
+
});
|
|
36047
|
+
}
|
|
36048
|
+
layerDefs.reverse();
|
|
36049
|
+
const project2 = {
|
|
36050
|
+
__header__: {
|
|
36051
|
+
fileType: "LDtk Project JSON",
|
|
36052
|
+
app: "LDtk",
|
|
36053
|
+
doc: "https://ldtk.io/json",
|
|
36054
|
+
schema: "https://ldtk.io/files/JSON_SCHEMA.json",
|
|
36055
|
+
appAuthor: "Sebastien 'deepnight' Benard",
|
|
36056
|
+
appVersion: LDTK_JSON_VERSION,
|
|
36057
|
+
url: "https://ldtk.io"
|
|
36058
|
+
},
|
|
36059
|
+
iid: uuid(name, "project"),
|
|
36060
|
+
jsonVersion: LDTK_JSON_VERSION,
|
|
36061
|
+
appBuildId: 473702,
|
|
36062
|
+
nextUid: Math.max(uid, levelUid + 1),
|
|
36063
|
+
identifierStyle: "Capitalize",
|
|
36064
|
+
toc: [],
|
|
36065
|
+
worldLayout: "Free",
|
|
36066
|
+
worldGridWidth: 256,
|
|
36067
|
+
worldGridHeight: 256,
|
|
36068
|
+
defaultLevelWidth: levelW,
|
|
36069
|
+
defaultLevelHeight: levelH,
|
|
36070
|
+
defaultPivotX: 0,
|
|
36071
|
+
defaultPivotY: 0,
|
|
36072
|
+
defaultGridSize: grid,
|
|
36073
|
+
defaultEntityWidth: grid,
|
|
36074
|
+
defaultEntityHeight: grid,
|
|
36075
|
+
bgColor: "#40465B",
|
|
36076
|
+
defaultLevelBgColor: "#000000",
|
|
36077
|
+
minifyJson: false,
|
|
36078
|
+
externalLevels: false,
|
|
36079
|
+
exportTiled: false,
|
|
36080
|
+
simplifiedExport: false,
|
|
36081
|
+
imageExportMode: "None",
|
|
36082
|
+
exportLevelBg: true,
|
|
36083
|
+
pngFilePattern: null,
|
|
36084
|
+
backupOnSave: false,
|
|
36085
|
+
backupLimit: 10,
|
|
36086
|
+
backupRelPath: null,
|
|
36087
|
+
levelNamePattern: "Level_%idx",
|
|
36088
|
+
tutorialDesc: null,
|
|
36089
|
+
customCommands: [],
|
|
36090
|
+
flags: ["ExportOldTableOfContentData", "UseMultilinesType"],
|
|
36091
|
+
defs: { layers: layerDefs, entities: [], tilesets, enums: [], externalEnums: [], levelFields: [] },
|
|
36092
|
+
levels: [{
|
|
36093
|
+
identifier: "Parallax",
|
|
36094
|
+
iid: uuid(name, "level"),
|
|
36095
|
+
uid: levelUid,
|
|
36096
|
+
worldX: 0,
|
|
36097
|
+
worldY: 0,
|
|
36098
|
+
worldDepth: 0,
|
|
36099
|
+
pxWid: levelW,
|
|
36100
|
+
pxHei: levelH,
|
|
36101
|
+
__bgColor: "#000000",
|
|
36102
|
+
bgColor: null,
|
|
36103
|
+
useAutoIdentifier: false,
|
|
36104
|
+
bgRelPath: null,
|
|
36105
|
+
bgPos: null,
|
|
36106
|
+
bgPivotX: 0.5,
|
|
36107
|
+
bgPivotY: 0.5,
|
|
36108
|
+
__smartColor: "#ADADB5",
|
|
36109
|
+
__bgPos: null,
|
|
36110
|
+
externalRelPath: null,
|
|
36111
|
+
fieldInstances: [],
|
|
36112
|
+
layerInstances,
|
|
36113
|
+
__neighbours: []
|
|
36114
|
+
}],
|
|
36115
|
+
worlds: [],
|
|
36116
|
+
dummyWorldIid: uuid(name, "world")
|
|
36117
|
+
};
|
|
36118
|
+
return {
|
|
36119
|
+
files: [{ path: `${base}.ldtk`, data: JSON.stringify(project2, null, 2) + "\n" }, ...files],
|
|
36120
|
+
options: { format: "ldtk", grid, start: [0, set.climb], warnings }
|
|
36121
|
+
};
|
|
36122
|
+
}
|
|
36123
|
+
function tileEmpty(png, x0, y0, grid) {
|
|
36124
|
+
for (let y = y0; y < y0 + grid; y++) {
|
|
36125
|
+
for (let x = x0; x < x0 + grid; x++) {
|
|
36126
|
+
if (png.pixels[(y * png.width + x) * 4 + 3] !== 0) return false;
|
|
36127
|
+
}
|
|
36128
|
+
}
|
|
36129
|
+
return true;
|
|
36130
|
+
}
|
|
36131
|
+
function exportParallax(set, format, base) {
|
|
36132
|
+
if (format === "tiled") return exportTiled(set, base);
|
|
36133
|
+
if (format === "godot") return exportGodot(set, base);
|
|
36134
|
+
return exportLdtk(set, base);
|
|
36135
|
+
}
|
|
36136
|
+
function previewHtml(set, scale2 = 3) {
|
|
36137
|
+
const [vw, vh] = set.view;
|
|
36138
|
+
const layers = set.layers.map((layer) => ({
|
|
36139
|
+
name: layer.name,
|
|
36140
|
+
src: `data:image/png;base64,${encodeRgbaPng(layer.png.width, layer.png.height, layer.png.pixels).toString("base64")}`,
|
|
36141
|
+
w: layer.png.width,
|
|
36142
|
+
h: layer.png.height,
|
|
36143
|
+
x: layer.x,
|
|
36144
|
+
y: layer.y,
|
|
36145
|
+
speed: layer.speed,
|
|
36146
|
+
speedY: layer.speedY,
|
|
36147
|
+
repeat: layer.repeat,
|
|
36148
|
+
repeatY: layer.repeatY
|
|
36149
|
+
}));
|
|
36150
|
+
const data = JSON.stringify({ view: [vw, vh], travel: set.travel, climb: set.climb, layers }).replace(/</g, "\\u003c");
|
|
36151
|
+
return `<!doctype html>
|
|
36152
|
+
<html lang="en">
|
|
36153
|
+
<head>
|
|
36154
|
+
<meta charset="utf-8">
|
|
36155
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
36156
|
+
<title>${set.id.replace(/[&<>"]/g, (c) => `&#${c.charCodeAt(0)};`)} parallax</title>
|
|
36157
|
+
<style>
|
|
36158
|
+
:root { color-scheme: dark; }
|
|
36159
|
+
body { margin: 0; background: #111318; color: #d8dae0; font: 14px/1.4 system-ui, sans-serif; display: grid; place-items: center; min-height: 100vh; }
|
|
36160
|
+
main { display: grid; gap: 12px; padding: 16px; max-width: 100%; }
|
|
36161
|
+
canvas { image-rendering: pixelated; width: ${vw * scale2}px; max-width: 100%; height: auto; background: #000; }
|
|
36162
|
+
label { display: flex; gap: 8px; align-items: center; }
|
|
36163
|
+
input[type=range] { flex: 1; }
|
|
36164
|
+
table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
|
|
36165
|
+
td, th { padding: 2px 10px 2px 0; text-align: left; }
|
|
36166
|
+
</style>
|
|
36167
|
+
</head>
|
|
36168
|
+
<body>
|
|
36169
|
+
<main>
|
|
36170
|
+
<canvas id="view" width="${vw}" height="${vh}"></canvas>
|
|
36171
|
+
<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>
|
|
36172
|
+
<table><thead><tr><th>Layer</th><th>speed</th><th>speedY</th><th>repeat</th></tr></thead><tbody id="rows"></tbody></table>
|
|
36173
|
+
</main>
|
|
36174
|
+
<script>
|
|
36175
|
+
const set = ${data};
|
|
36176
|
+
const ctx = document.getElementById("view").getContext("2d");
|
|
36177
|
+
ctx.imageSmoothingEnabled = false;
|
|
36178
|
+
const images = set.layers.map((layer) => Object.assign(new Image(), { src: layer.src }));
|
|
36179
|
+
const rows = document.getElementById("rows");
|
|
36180
|
+
for (const layer of set.layers) {
|
|
36181
|
+
const tr = rows.insertRow();
|
|
36182
|
+
for (const value of [layer.name, layer.speed, layer.speedY, [layer.repeat && "x", layer.repeatY && "y"].filter(Boolean).join(" ") || "no"]) tr.insertCell().textContent = value;
|
|
36183
|
+
}
|
|
36184
|
+
const slider = document.getElementById("cam");
|
|
36185
|
+
const pos = document.getElementById("pos");
|
|
36186
|
+
let playing = true;
|
|
36187
|
+
let t0 = performance.now();
|
|
36188
|
+
document.getElementById("play").onclick = (event) => {
|
|
36189
|
+
playing = !playing;
|
|
36190
|
+
event.target.textContent = playing ? "Pause" : "Play";
|
|
36191
|
+
t0 = performance.now() - (slider.value / 1000) * 6000;
|
|
36192
|
+
};
|
|
36193
|
+
slider.oninput = () => { playing = false; document.getElementById("play").textContent = "Play"; };
|
|
36194
|
+
function draw(u) {
|
|
36195
|
+
const e = (1 - Math.cos(u * Math.PI)) / 2;
|
|
36196
|
+
const camX = Math.round(e * set.travel);
|
|
36197
|
+
const camY = Math.round(e * set.climb);
|
|
36198
|
+
pos.textContent = camX + ", " + camY;
|
|
36199
|
+
ctx.clearRect(0, 0, set.view[0], set.view[1]);
|
|
36200
|
+
set.layers.forEach((layer, i) => {
|
|
36201
|
+
const left = layer.x + Math.round(-camX * layer.speed);
|
|
36202
|
+
const top = layer.y + Math.round(camY * layer.speedY);
|
|
36203
|
+
const xs = layer.repeat ? [] : [left];
|
|
36204
|
+
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);
|
|
36205
|
+
const ys = layer.repeatY ? [] : [top];
|
|
36206
|
+
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);
|
|
36207
|
+
for (const y of ys) for (const x of xs) ctx.drawImage(images[i], x, y);
|
|
36208
|
+
});
|
|
36209
|
+
}
|
|
36210
|
+
function frame(now) {
|
|
36211
|
+
if (playing) {
|
|
36212
|
+
const u = ((now - t0) % 12000) / 6000;
|
|
36213
|
+
const v = u <= 1 ? u : 2 - u;
|
|
36214
|
+
slider.value = Math.round(v * 1000);
|
|
36215
|
+
}
|
|
36216
|
+
draw(slider.value / 1000);
|
|
36217
|
+
requestAnimationFrame(frame);
|
|
36218
|
+
}
|
|
36219
|
+
Promise.all(images.map((image) => image.decode())).then(() => requestAnimationFrame(frame));
|
|
36220
|
+
</script>
|
|
36221
|
+
</body>
|
|
36222
|
+
</html>
|
|
36223
|
+
`;
|
|
36224
|
+
}
|
|
36225
|
+
|
|
36226
|
+
// src/cli/commands/parallax.ts
|
|
36227
|
+
async function runParallax(args) {
|
|
36228
|
+
const { loaded, lock } = await openProject2(args);
|
|
36229
|
+
const manifestDir = path74.dirname(path74.resolve(args.manifest));
|
|
36230
|
+
const ids = Object.keys(loaded.manifest.parallax ?? {});
|
|
36231
|
+
if (!ids.length) throw new Error('The manifest has no parallax sets. Add one under "parallax"; see docs/PARALLAX.md.');
|
|
36232
|
+
const wanted = args.target ? [args.target] : ids;
|
|
36233
|
+
if (args.out && wanted.length > 1) {
|
|
36234
|
+
throw new Error(`--out names one set; this manifest has ${ids.length} (${ids.join(", ")}). Name the set: pixelkiln parallax ${args.subcommand} <set>`);
|
|
36235
|
+
}
|
|
36236
|
+
for (const id of wanted) {
|
|
36237
|
+
const set = await resolveParallaxSet(loaded.manifest, manifestDir, lock, id);
|
|
36238
|
+
const root = path74.resolve(args.out ?? path74.join(manifestDir, "parallax", id));
|
|
36239
|
+
const sources = [
|
|
36240
|
+
await provenanceFile("$manifest", args.manifest),
|
|
36241
|
+
await provenanceFile("$lock", args.lock),
|
|
36242
|
+
...await Promise.all(
|
|
36243
|
+
set.layers.filter((layer) => layer.source.kind !== "sky").map((layer) => provenanceFile(`layer:${layer.name}`, layer.source.path))
|
|
36244
|
+
)
|
|
36245
|
+
];
|
|
36246
|
+
const describe2 = setOptions(set);
|
|
36247
|
+
if (args.subcommand === "export") {
|
|
36248
|
+
const formats = args.format ? [args.format] : [...PARALLAX_FORMATS];
|
|
36249
|
+
for (const format of formats) {
|
|
36250
|
+
const base = path74.join(root, format, id);
|
|
36251
|
+
const result = exportParallax(set, format, base);
|
|
36252
|
+
const outputs = result.files.map((file) => ({ path: file.path, data: typeof file.data === "string" ? Buffer.from(file.data) : file.data }));
|
|
36253
|
+
await writeManagedArtifactBundle(`${base}.pixelkiln.json`, outputs, {
|
|
36254
|
+
kind: "parallax",
|
|
36255
|
+
sources,
|
|
36256
|
+
options: { set: id, ...describe2, ...result.options }
|
|
36257
|
+
}, { force: args.force });
|
|
36258
|
+
log(` ${id} (${format}): ${path74.relative(process.cwd(), result.files[0].path)} + ${result.files.length - 1} picture(s)`);
|
|
36259
|
+
for (const warning of result.options.warnings ?? []) log(` warning: ${warning}`);
|
|
36260
|
+
}
|
|
36261
|
+
} else {
|
|
36262
|
+
const frames = args.frames ?? 3;
|
|
36263
|
+
const strip = joinStripPng(
|
|
36264
|
+
cameraPath(set, frames).map(([x, y]) => {
|
|
36265
|
+
const frame = composeParallaxFrame(set, x, y);
|
|
36266
|
+
return encodeRgbaPng(frame.width, frame.height, frame.pixels);
|
|
36267
|
+
})
|
|
36268
|
+
);
|
|
36269
|
+
const base = path74.join(root, `${id}.preview`);
|
|
36270
|
+
await writeManagedArtifactBundle(`${base}.pixelkiln.json`, [
|
|
36271
|
+
{ path: `${base}.html`, data: Buffer.from(previewHtml(set)) },
|
|
36272
|
+
{ path: `${base}.png`, data: strip }
|
|
36273
|
+
], {
|
|
36274
|
+
kind: "parallax",
|
|
36275
|
+
sources,
|
|
36276
|
+
options: { set: id, ...describe2, preview: { frames } }
|
|
36277
|
+
}, { force: args.force });
|
|
36278
|
+
log(` ${id}: ${path74.relative(process.cwd(), base)}.html (scrolls in a browser) + .png (${frames} frames, start to end)`);
|
|
36279
|
+
}
|
|
36280
|
+
for (const layer of set.layers) {
|
|
36281
|
+
const seam = (layer.seamRatio === void 0 ? "" : `, seam ${layer.seamRatio.toFixed(1)}`) + (layer.seamRatioY === void 0 ? "" : `, vertical seam ${layer.seamRatioY.toFixed(1)}`);
|
|
36282
|
+
log(` ${layer.name}: ${layer.png.width}x${layer.png.height} at ${layer.x},${layer.y}, speed ${layer.speed}/${layer.speedY}${seam}`);
|
|
36283
|
+
}
|
|
36284
|
+
for (const warning of set.warnings) log(` warning: ${warning}`);
|
|
36285
|
+
}
|
|
36286
|
+
}
|
|
36287
|
+
function setOptions(set) {
|
|
36288
|
+
return {
|
|
36289
|
+
view: set.view,
|
|
36290
|
+
travel: set.travel,
|
|
36291
|
+
climb: set.climb,
|
|
36292
|
+
layers: set.layers.map((layer) => ({
|
|
36293
|
+
name: layer.name,
|
|
36294
|
+
speed: layer.speed,
|
|
36295
|
+
speedY: layer.speedY,
|
|
36296
|
+
x: layer.x,
|
|
36297
|
+
y: layer.y,
|
|
36298
|
+
repeat: layer.repeat,
|
|
36299
|
+
repeatY: layer.repeatY,
|
|
36300
|
+
...layer.source.kind === "sky" ? { sky: layer.source.colors } : {}
|
|
36301
|
+
}))
|
|
36302
|
+
};
|
|
36303
|
+
}
|
|
36304
|
+
|
|
36305
|
+
// src/cli/commands/redraw.ts
|
|
36306
|
+
import path76 from "path";
|
|
36307
|
+
|
|
35507
36308
|
// src/pipeline/redraw.ts
|
|
35508
36309
|
import { existsSync as existsSync56 } from "fs";
|
|
35509
|
-
import { mkdir as mkdir26, readFile as
|
|
35510
|
-
import
|
|
36310
|
+
import { mkdir as mkdir26, readFile as readFile51, rename as rename15, writeFile as writeFile31 } from "fs/promises";
|
|
36311
|
+
import path75 from "path";
|
|
35511
36312
|
function redrawRoles(spec, lock) {
|
|
35512
36313
|
return (lock.entries[lockKey(spec.styleId, spec.assetId)]?.outputs ?? []).map((output) => output.role ?? "");
|
|
35513
36314
|
}
|
|
@@ -35549,7 +36350,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
35549
36350
|
const still = source.spec.character?.kind !== "animation";
|
|
35550
36351
|
for (const [index, output] of sourceEntry.outputs.entries()) {
|
|
35551
36352
|
if (!still && !owners.includes(source.assetId)) continue;
|
|
35552
|
-
const png = await
|
|
36353
|
+
const png = await readFile51(currentEntryOutputPath(sourceEntry, source.spec, index));
|
|
35553
36354
|
if (still) stills.push(png);
|
|
35554
36355
|
if (!owners.includes(source.assetId)) continue;
|
|
35555
36356
|
const role = output.role ?? String(index).padStart(2, "0");
|
|
@@ -35588,18 +36389,18 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
35588
36389
|
continue;
|
|
35589
36390
|
}
|
|
35590
36391
|
const pair = offset?.per && offset.per[source.assetId] || offset;
|
|
35591
|
-
const png = await
|
|
36392
|
+
const png = await readFile51(file);
|
|
35592
36393
|
layers.push(pair ? shiftPixels(png, -pair.x, -pair.y).png : png);
|
|
35593
36394
|
}
|
|
35594
36395
|
const prepared = redrawSheet(built, layers, redraw);
|
|
35595
36396
|
const size = decodePng(prepared.keyed);
|
|
35596
36397
|
const cost = proTierCost(size.width, size.height);
|
|
35597
|
-
const workDir =
|
|
36398
|
+
const workDir = path75.join(layerWorkDir(spec), "redraw");
|
|
35598
36399
|
const result = { roles, guides, sheet: { width: size.width, height: size.height }, cost, billed: null, written: [], workDir };
|
|
35599
36400
|
if (opts.dryRun) return result;
|
|
35600
36401
|
await mkdir26(workDir, { recursive: true });
|
|
35601
|
-
await writeFile31(
|
|
35602
|
-
await writeFile31(
|
|
36402
|
+
await writeFile31(path75.join(workDir, "keyed.png"), prepared.keyed);
|
|
36403
|
+
await writeFile31(path75.join(workDir, "mask.png"), prepared.mask);
|
|
35603
36404
|
const count = roles.length;
|
|
35604
36405
|
const description = `${spec.prompt}. Every figure but ${count === 1 ? "one" : count} already wears it. Dress the unfinished figure${count === 1 ? "" : "s"} in exactly the same thing, the same colours and details, seen from the side ${count === 1 ? "that figure faces" : "each of those figures faces"}.`;
|
|
35605
36406
|
const jobId = await painter.paintSheet({ description, keyed: prepared.keyed, mask: prepared.mask, seed: opts.seed ?? spec.seed });
|
|
@@ -35617,13 +36418,13 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
35617
36418
|
if (Date.now() > deadline) throw new Error(`${label}: redraw job ${jobId} did not finish in time; nothing was changed`);
|
|
35618
36419
|
await new Promise((resolve) => setTimeout(resolve, opts.pollMs ?? 3e3));
|
|
35619
36420
|
}
|
|
35620
|
-
await writeFile31(
|
|
36421
|
+
await writeFile31(path75.join(workDir, "result.png"), painted);
|
|
35621
36422
|
const returned = decodePng(painted);
|
|
35622
36423
|
if (returned.width !== size.width || returned.height !== size.height) {
|
|
35623
36424
|
throw new Error(`${label}: redraw job ${jobId} returned a ${returned.width}x${returned.height} image for a ${size.width}x${size.height} sheet`);
|
|
35624
36425
|
}
|
|
35625
36426
|
const cut = cutLayerFrames(painted, { keyed: prepared.keyed, mask: prepared.mask, frames: built.frames }, { key: layer.key, region: layer.region });
|
|
35626
|
-
const cacheDir =
|
|
36427
|
+
const cacheDir = path75.resolve(opts.cacheDir ?? path75.join(path75.dirname(opts.lockPath), ".pixelkiln", "cache"));
|
|
35627
36428
|
const outputs = [...entry.outputs];
|
|
35628
36429
|
const renames = [];
|
|
35629
36430
|
for (const [index, at2] of targets) {
|
|
@@ -35632,7 +36433,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
35632
36433
|
const empty = !decodePng(raw).pixels.some((value, i) => i % 4 === 3 && value > 0);
|
|
35633
36434
|
if (empty) throw new Error(`${label}: the redraw of ${role} came back with nothing drawn; nothing was changed. Run it again, or with another --seed`);
|
|
35634
36435
|
const target = currentEntryOutputPath(entry, spec, at2);
|
|
35635
|
-
if (existsSync56(target)) await cacheMedia(cacheDir, await
|
|
36436
|
+
if (existsSync56(target)) await cacheMedia(cacheDir, await readFile51(target), MediaType.PNG);
|
|
35636
36437
|
await cacheMedia(cacheDir, raw, MediaType.PNG);
|
|
35637
36438
|
const processed = applyPostprocess(raw, MediaType.PNG, entry.postprocess, [], role);
|
|
35638
36439
|
await cacheMedia(cacheDir, processed.bytes, MediaType.PNG);
|
|
@@ -35681,7 +36482,7 @@ async function runRedraw(args) {
|
|
|
35681
36482
|
const painter = args.dryRun ? { paintSheet: never, paintedSheet: never } : new PixelLabProvider(clientFromEnv());
|
|
35682
36483
|
const result = await redrawLayerFrames(spec, project2.lock, painter, {
|
|
35683
36484
|
frames: args.redrawFrames,
|
|
35684
|
-
lockPath:
|
|
36485
|
+
lockPath: path76.resolve(args.lock),
|
|
35685
36486
|
seed: args.seed,
|
|
35686
36487
|
dryRun: args.dryRun,
|
|
35687
36488
|
onProgress: log
|
|
@@ -35692,16 +36493,16 @@ async function runRedraw(args) {
|
|
|
35692
36493
|
log(` would redraw ${frames} (${result.roles.join(", ")}) beside ${result.guides} dressed, on a ${sheet} sheet: about ${result.cost} generations`);
|
|
35693
36494
|
return;
|
|
35694
36495
|
}
|
|
35695
|
-
for (const file of result.written) log(` wrote ${
|
|
36496
|
+
for (const file of result.written) log(` wrote ${path76.relative(process.cwd(), file)}`);
|
|
35696
36497
|
const billed = result.billed ? `${result.billed.amount} ${result.billed.unit} billed` : `about ${result.cost} generations`;
|
|
35697
|
-
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${
|
|
36498
|
+
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${path76.relative(process.cwd(), result.workDir)}`);
|
|
35698
36499
|
log(` look at ${result.written.length === 1 ? "it" : "them"}, then run pixelkiln gen to rebuild anything made from this layer`);
|
|
35699
36500
|
}
|
|
35700
36501
|
|
|
35701
36502
|
// src/cli/commands/skeleton.ts
|
|
35702
|
-
import
|
|
36503
|
+
import path77 from "path";
|
|
35703
36504
|
import { existsSync as existsSync57 } from "fs";
|
|
35704
|
-
import { readFile as
|
|
36505
|
+
import { readFile as readFile52, writeFile as writeFile32 } from "fs/promises";
|
|
35705
36506
|
|
|
35706
36507
|
// src/skeleton-preview.ts
|
|
35707
36508
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -35822,12 +36623,12 @@ var Canvas = class {
|
|
|
35822
36623
|
async function runEstimateSkeleton(args) {
|
|
35823
36624
|
const image = args.target;
|
|
35824
36625
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
35825
|
-
if (args.out && existsSync57(
|
|
36626
|
+
if (args.out && existsSync57(path77.resolve(args.out)) && !args.force) {
|
|
35826
36627
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
35827
36628
|
}
|
|
35828
|
-
loadEnvFiles(
|
|
36629
|
+
loadEnvFiles(path77.dirname(path77.resolve(args.manifest)));
|
|
35829
36630
|
loadEnvFiles(process.cwd());
|
|
35830
|
-
const bytes = await
|
|
36631
|
+
const bytes = await readFile52(path77.resolve(image));
|
|
35831
36632
|
const metadata = imageMetadata(bytes);
|
|
35832
36633
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
35833
36634
|
if (args.custom) return estimateCustom(args, image, bytes, metadata);
|
|
@@ -35840,7 +36641,7 @@ async function runEstimateSkeleton(args) {
|
|
|
35840
36641
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
35841
36642
|
const json2 = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
35842
36643
|
if (args.out) {
|
|
35843
|
-
await writeFile32(
|
|
36644
|
+
await writeFile32(path77.resolve(args.out), json2 + "\n");
|
|
35844
36645
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
35845
36646
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
35846
36647
|
} else {
|
|
@@ -35875,7 +36676,7 @@ async function estimateCustom(args, image, bytes, metadata) {
|
|
|
35875
36676
|
const json2 = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames, { rig: res.rig, kind: res.kind }), null, 2);
|
|
35876
36677
|
const extra = res.rig.filter((joint) => !joint.estimate).map((joint) => joint.name);
|
|
35877
36678
|
if (args.out) {
|
|
35878
|
-
await writeFile32(
|
|
36679
|
+
await writeFile32(path77.resolve(args.out), json2 + "\n");
|
|
35879
36680
|
log(` wrote ${args.out}: a ${res.kind ?? "custom"} rig of ${res.rig.length} joints and ${frames} frames to edit`);
|
|
35880
36681
|
if (extra.length) log(` joints beyond the 18: ${extra.slice(0, 12).join(", ")}${extra.length > 12 ? ", \u2026" : ""}`);
|
|
35881
36682
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
@@ -35889,8 +36690,8 @@ async function runSkeletonPreview(args) {
|
|
|
35889
36690
|
let sourceFile;
|
|
35890
36691
|
let label;
|
|
35891
36692
|
if (target.endsWith(".json")) {
|
|
35892
|
-
keypointsFile =
|
|
35893
|
-
sourceFile = args.from ?
|
|
36693
|
+
keypointsFile = path77.resolve(target);
|
|
36694
|
+
sourceFile = args.from ? path77.resolve(args.from) : void 0;
|
|
35894
36695
|
label = target;
|
|
35895
36696
|
} else {
|
|
35896
36697
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -35902,13 +36703,13 @@ async function runSkeletonPreview(args) {
|
|
|
35902
36703
|
);
|
|
35903
36704
|
}
|
|
35904
36705
|
keypointsFile = spec.revision.keypointsFile;
|
|
35905
|
-
sourceFile = args.from ?
|
|
36706
|
+
sourceFile = args.from ? path77.resolve(args.from) : spec.revision.sourceFile;
|
|
35906
36707
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
35907
36708
|
}
|
|
35908
36709
|
if (!existsSync57(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
35909
36710
|
let json2;
|
|
35910
36711
|
try {
|
|
35911
|
-
json2 = JSON.parse(await
|
|
36712
|
+
json2 = JSON.parse(await readFile52(keypointsFile, "utf8"));
|
|
35912
36713
|
} catch (error) {
|
|
35913
36714
|
throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
35914
36715
|
}
|
|
@@ -35918,15 +36719,15 @@ async function runSkeletonPreview(args) {
|
|
|
35918
36719
|
if (!existsSync57(sourceFile)) {
|
|
35919
36720
|
log(` source image does not exist yet, drawing on a plain ground: ${sourceFile}`);
|
|
35920
36721
|
} else {
|
|
35921
|
-
const bytes = await
|
|
36722
|
+
const bytes = await readFile52(sourceFile);
|
|
35922
36723
|
if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile} must be a PNG to preview over`);
|
|
35923
36724
|
source = decodePng(bytes);
|
|
35924
36725
|
}
|
|
35925
36726
|
}
|
|
35926
|
-
const out =
|
|
36727
|
+
const out = path77.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
35927
36728
|
await writeFile32(out, renderSkeletonSheet(set, { source }));
|
|
35928
36729
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
35929
|
-
const shown2 =
|
|
36730
|
+
const shown2 = path77.relative(process.cwd(), out);
|
|
35930
36731
|
log(` wrote ${shown2.startsWith("..") ? out : shown2}`);
|
|
35931
36732
|
}
|
|
35932
36733
|
|
|
@@ -35972,15 +36773,15 @@ async function runTools(args) {
|
|
|
35972
36773
|
}
|
|
35973
36774
|
|
|
35974
36775
|
// src/cli/commands/workspace.ts
|
|
35975
|
-
import
|
|
36776
|
+
import path78 from "path";
|
|
35976
36777
|
import { existsSync as existsSync58 } from "fs";
|
|
35977
36778
|
async function runWorkspace(args) {
|
|
35978
|
-
const workspacePath =
|
|
35979
|
-
const dir =
|
|
36779
|
+
const workspacePath = path78.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
36780
|
+
const dir = path78.dirname(workspacePath);
|
|
35980
36781
|
if (args.subcommand === "add") {
|
|
35981
|
-
const manifestPath =
|
|
36782
|
+
const manifestPath = path78.resolve(args.target);
|
|
35982
36783
|
const loadedTarget = await loadManifest(manifestPath);
|
|
35983
|
-
const lockPath = args.explicitLock ?
|
|
36784
|
+
const lockPath = args.explicitLock ? path78.resolve(args.explicitLock) : path78.join(path78.dirname(manifestPath), "pixelkiln.lock.json");
|
|
35984
36785
|
const ws = await loadWorkspace(workspacePath);
|
|
35985
36786
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
35986
36787
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -36000,7 +36801,7 @@ async function runWorkspace(args) {
|
|
|
36000
36801
|
...args.account ? { account: args.account } : {}
|
|
36001
36802
|
};
|
|
36002
36803
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project2] });
|
|
36003
|
-
log(` registered "${id}" in ${
|
|
36804
|
+
log(` registered "${id}" in ${path78.relative(process.cwd(), workspacePath)}`);
|
|
36004
36805
|
log(` manifest: ${project2.manifest}`);
|
|
36005
36806
|
log(` lock: ${project2.lock}`);
|
|
36006
36807
|
if (!existsSync58(lockPath)) {
|
|
@@ -36012,7 +36813,7 @@ async function runWorkspace(args) {
|
|
|
36012
36813
|
}
|
|
36013
36814
|
if (args.subcommand === "remove") {
|
|
36014
36815
|
const ws = await loadWorkspace(workspacePath);
|
|
36015
|
-
const resolvedTarget =
|
|
36816
|
+
const resolvedTarget = path78.resolve(args.target);
|
|
36016
36817
|
const match = ws.projects.find(
|
|
36017
36818
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
36018
36819
|
);
|
|
@@ -36023,7 +36824,7 @@ async function runWorkspace(args) {
|
|
|
36023
36824
|
version: 1,
|
|
36024
36825
|
projects: ws.projects.filter((p) => p !== match)
|
|
36025
36826
|
});
|
|
36026
|
-
log(` removed "${match.id}" from ${
|
|
36827
|
+
log(` removed "${match.id}" from ${path78.relative(process.cwd(), workspacePath)}`);
|
|
36027
36828
|
return;
|
|
36028
36829
|
}
|
|
36029
36830
|
if (args.subcommand === "list") {
|
|
@@ -36035,9 +36836,9 @@ async function runWorkspace(args) {
|
|
|
36035
36836
|
if (args.json) {
|
|
36036
36837
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
36037
36838
|
} else if (!ws.projects.length) {
|
|
36038
|
-
log(` no projects registered in ${
|
|
36839
|
+
log(` no projects registered in ${path78.relative(process.cwd(), workspacePath)}`);
|
|
36039
36840
|
} else {
|
|
36040
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
36841
|
+
log(` ${ws.projects.length} project(s) in ${path78.relative(process.cwd(), workspacePath)}:`);
|
|
36041
36842
|
for (const p of ws.projects) {
|
|
36042
36843
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
36043
36844
|
}
|
|
@@ -36055,7 +36856,7 @@ async function runWorkspace(args) {
|
|
|
36055
36856
|
if (args.json) {
|
|
36056
36857
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
36057
36858
|
} else {
|
|
36058
|
-
log(` workspace: ${
|
|
36859
|
+
log(` workspace: ${path78.relative(process.cwd(), workspacePath)}`);
|
|
36059
36860
|
for (const p of report.projects) {
|
|
36060
36861
|
if (p.error) {
|
|
36061
36862
|
log(`
|
|
@@ -36110,7 +36911,7 @@ async function runVersion() {
|
|
|
36110
36911
|
for (const up of ["../package.json", "../../package.json"]) {
|
|
36111
36912
|
const url = new URL(up, import.meta.url);
|
|
36112
36913
|
if (!existsSync59(url)) continue;
|
|
36113
|
-
const pkg = JSON.parse(await
|
|
36914
|
+
const pkg = JSON.parse(await readFile53(url, "utf8"));
|
|
36114
36915
|
if (pkg.name === "pixelkiln") {
|
|
36115
36916
|
log(`${pkg.name} ${pkg.version}`);
|
|
36116
36917
|
return;
|
|
@@ -36169,7 +36970,8 @@ var RUNNERS = {
|
|
|
36169
36970
|
sfx: runSfx,
|
|
36170
36971
|
ui: runUi,
|
|
36171
36972
|
asset: runAsset,
|
|
36172
|
-
talk: runTalk
|
|
36973
|
+
talk: runTalk,
|
|
36974
|
+
parallax: runParallax
|
|
36173
36975
|
};
|
|
36174
36976
|
async function main(argv = process.argv.slice(2)) {
|
|
36175
36977
|
const args = parseArgs(argv);
|