pixelkiln 0.110.0 → 0.112.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 +1214 -366
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1236 -523
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +281 -22
- package/dist/index.d.ts +281 -22
- package/dist/index.js +1156 -460
- package/dist/index.js.map +1 -1
- package/docs/ARCHITECTURE.md +10 -0
- package/docs/CLI.md +90 -10
- package/docs/LIBRARY.md +32 -0
- package/docs/THIRD_PARTY.md +20 -0
- package/docs/TILES.md +47 -3
- package/package.json +2 -1
- package/skills/pixelkiln/references/models.md +15 -3
- package/skills/pixelkiln/references/vfx.md +48 -21
package/dist/cli.js
CHANGED
|
@@ -67,8 +67,8 @@ function exitCodeFor(err) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/cli/main.ts
|
|
70
|
-
import { existsSync as
|
|
71
|
-
import { readFile as
|
|
70
|
+
import { existsSync as existsSync58 } from "fs";
|
|
71
|
+
import { readFile as readFile51 } from "fs/promises";
|
|
72
72
|
|
|
73
73
|
// src/cli/args.ts
|
|
74
74
|
import path from "path";
|
|
@@ -126,6 +126,10 @@ var VALUE_FLAGS = [
|
|
|
126
126
|
"--fps",
|
|
127
127
|
"--lib",
|
|
128
128
|
"--margin",
|
|
129
|
+
"--camera",
|
|
130
|
+
"--hue",
|
|
131
|
+
"--param",
|
|
132
|
+
"--tune",
|
|
129
133
|
"--sprite-frames",
|
|
130
134
|
"--sprite-fps",
|
|
131
135
|
"--artist",
|
|
@@ -257,7 +261,7 @@ var REFINE_SUBCOMMANDS = ["run", "approve", "check"];
|
|
|
257
261
|
var RECIPE_SUBCOMMANDS = ["list", "inspect", "install", "verify"];
|
|
258
262
|
var QUALITY_SUBCOMMANDS = ["snapshot", "check"];
|
|
259
263
|
var EDIT_SUBCOMMANDS = ["start", "detach"];
|
|
260
|
-
var MODEL_SUBCOMMANDS = ["list", "export", "import", "blender", "adopt", "normal-map"];
|
|
264
|
+
var MODEL_SUBCOMMANDS = ["list", "resolve", "export", "import", "blender", "adopt", "normal-map"];
|
|
261
265
|
var TOOLS_SUBCOMMANDS = ["status", "install"];
|
|
262
266
|
var TOOLS = ["editor"];
|
|
263
267
|
var VFX_SUBCOMMANDS = ["make", "presets", "parts", "effects"];
|
|
@@ -336,8 +340,8 @@ function parseArgs(argv) {
|
|
|
336
340
|
if (rest[0] === subcommand) rest = rest.slice(1);
|
|
337
341
|
if (subcommand !== "list") {
|
|
338
342
|
target = rest[0]?.startsWith("-") ? void 0 : rest[0];
|
|
339
|
-
if (target === void 0) throw new UsageError(`model ${subcommand} needs a model: its path, its file name, or its gallery id`);
|
|
340
|
-
rest = rest.slice(1);
|
|
343
|
+
if (target === void 0 && subcommand !== "resolve") throw new UsageError(`model ${subcommand} needs a model: its path, its file name, or its gallery id`);
|
|
344
|
+
if (target !== void 0) rest = rest.slice(1);
|
|
341
345
|
}
|
|
342
346
|
} else if (command === "tools") {
|
|
343
347
|
subcommand = rest[0]?.startsWith("-") || rest[0] === void 0 ? "status" : rest[0];
|
|
@@ -503,7 +507,7 @@ function parseArgs(argv) {
|
|
|
503
507
|
}
|
|
504
508
|
const manifest = get("--manifest") ?? "pixelkiln.manifest.json";
|
|
505
509
|
const rawFormat = get("--format");
|
|
506
|
-
const formats = command === "export" ? ["generic", "tiled", "godot"] : command === "asset" ? ["zip", "spritesheet", "aseprite", "gif"] : ["generic", "aseprite", "godot"];
|
|
510
|
+
const formats = command === "export" ? ["generic", "tiled", "godot", "ldtk"] : command === "asset" ? ["zip", "spritesheet", "aseprite", "gif"] : ["generic", "aseprite", "godot"];
|
|
507
511
|
if (rawFormat && !formats.includes(rawFormat)) {
|
|
508
512
|
throw new UsageError(`--format must be ${formats.slice(0, -1).join(", ")}, or ${formats.at(-1)}, got "${rawFormat}"`);
|
|
509
513
|
}
|
|
@@ -601,6 +605,10 @@ function parseArgs(argv) {
|
|
|
601
605
|
sprite: get("--sprite"),
|
|
602
606
|
fps: numberOption("--fps", { min: 1, max: 60, integer: true }),
|
|
603
607
|
lib: get("--lib"),
|
|
608
|
+
camera: get("--camera"),
|
|
609
|
+
hue: numberOption("--hue", { min: -360, max: 360 }),
|
|
610
|
+
param: list("--param"),
|
|
611
|
+
tune: list("--tune"),
|
|
604
612
|
margin: numberOption("--margin", { min: 0, max: 256, integer: true }),
|
|
605
613
|
spriteFrames: numberOption("--sprite-frames", { min: 1, max: 32, integer: true }),
|
|
606
614
|
spriteFps: numberOption("--sprite-fps", { min: 1, max: 60, integer: true }),
|
|
@@ -731,6 +739,8 @@ Commands
|
|
|
731
739
|
with its region guide to paint anywhere, import it into an edited
|
|
732
740
|
copy under edits/, open the model in Blender, adopt its export,
|
|
733
741
|
or add PixelLab normal map detail (normal-map; priced, 0.1 a call).
|
|
742
|
+
model resolve [model] prints the file a game should load: the
|
|
743
|
+
edited copy when it is current, else the model as built.
|
|
734
744
|
tools status/install editor: the in-browser editor (Pixelorama) is a
|
|
735
745
|
46 MB web build fetched once per release into a user cache and
|
|
736
746
|
verified against pinned hashes. Offline once installed.
|
|
@@ -758,6 +768,9 @@ Commands
|
|
|
758
768
|
the pixelfx library on this machine instead (free, nothing
|
|
759
769
|
sent; install it with: npm i github:patch-gg/pixelfx); vfx
|
|
760
770
|
effects lists them.
|
|
771
|
+
With --lib codex, renders an --effect <id> from pixel-vfx-codex
|
|
772
|
+
the same way (npm i github:888wing/pixel-vfx-codex), through a
|
|
773
|
+
--camera 2d, 25d or 3d; vfx effects --lib codex lists them.
|
|
761
774
|
font PixelLab: generate a pixel font (--description, --out); writes a
|
|
762
775
|
.ttf and a glyph atlas PNG. 15 generations; asks first.
|
|
763
776
|
music PixelLab: a song from a style (--description, --out); writes two
|
|
@@ -790,7 +803,7 @@ Options
|
|
|
790
803
|
--columns <n> pack/export: sprites or tiles per row (default: near-square)
|
|
791
804
|
--port <n> Local review/gallery server port (default: choose a free port)
|
|
792
805
|
--inputs <path> pack/quality snapshot: JSON input list; needs --out
|
|
793
|
-
--format <format> export: generic (default), tiled,
|
|
806
|
+
--format <format> export: generic (default), tiled, godot (TileSet), or ldtk
|
|
794
807
|
pack/mount: generic (default), aseprite, or godot (SpriteFrames)
|
|
795
808
|
--output-role <r> pack: include only this output role (repeatable)
|
|
796
809
|
--primary-only pack: include only unambiguous primary/single outputs
|
|
@@ -865,12 +878,16 @@ Options
|
|
|
865
878
|
--preset <name> vfx: start from a whole-effect preset (vfx presets lists them)
|
|
866
879
|
--recipe <file> vfx: render a recipe or an earlier run's .vfx.json record
|
|
867
880
|
--effect <id> vfx: start from a saved My effects id and export over it;
|
|
868
|
-
with --lib pixelfx, the effect to render (fire/torch)
|
|
881
|
+
with --lib pixelfx or codex, the effect to render (fire/torch, fireball)
|
|
869
882
|
--part <name> vfx: add a part (repeatable; vfx parts lists them)
|
|
870
883
|
--sprite <ref> vfx: build around a sprite: a file, a URL, or character:<id>:<dir>
|
|
871
884
|
--fps <n> vfx: frames per second, 1-60
|
|
872
|
-
--lib <name> vfx: pixellab (default) or pixelfx,
|
|
873
|
-
--margin <px> vfx --lib pixelfx: transparent pixels around the effect
|
|
885
|
+
--lib <name> vfx: pixellab (default), or pixelfx or codex, local effects libraries
|
|
886
|
+
--margin <px> vfx --lib pixelfx or codex: transparent pixels around the effect
|
|
887
|
+
--camera <view> vfx --lib codex: 2d (default), 25d or 3d
|
|
888
|
+
--hue <degrees> vfx --lib codex: turn the effect's colors, -360 to 360
|
|
889
|
+
--param <name=n> vfx --lib codex: an effect's own parameter (repeatable)
|
|
890
|
+
--tune <name=n> vfx --lib codex: a shared knob such as size or density
|
|
874
891
|
--sprite-frames <n> vfx --description: --sprite is a strip of n equal frames (2-32)
|
|
875
892
|
--sprite-fps <n> vfx --description: how fast the sprite animation plays (default 12)
|
|
876
893
|
--game-pack vfx: also download the game-pack ZIP
|
|
@@ -1426,10 +1443,10 @@ function normalizeHex(value) {
|
|
|
1426
1443
|
function sha256(data) {
|
|
1427
1444
|
return createHash("sha256").update(data).digest("hex");
|
|
1428
1445
|
}
|
|
1429
|
-
async function sha256File(
|
|
1446
|
+
async function sha256File(path76) {
|
|
1430
1447
|
return new Promise((resolve, reject) => {
|
|
1431
1448
|
const hash = createHash("sha256");
|
|
1432
|
-
const stream = createReadStream(
|
|
1449
|
+
const stream = createReadStream(path76);
|
|
1433
1450
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1434
1451
|
stream.on("error", reject);
|
|
1435
1452
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -3142,7 +3159,7 @@ var AssetDeriveSchema = z.object({
|
|
|
3142
3159
|
/** 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. */
|
|
3143
3160
|
tolerance: z.number().min(0).max(442).optional()
|
|
3144
3161
|
}).strict().superRefine((derive, context) => {
|
|
3145
|
-
const issue = (message6,
|
|
3162
|
+
const issue = (message6, path76) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path76] });
|
|
3146
3163
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
3147
3164
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
3148
3165
|
}
|
|
@@ -9055,9 +9072,9 @@ var PixelLabClient = class {
|
|
|
9055
9072
|
apiKey;
|
|
9056
9073
|
http;
|
|
9057
9074
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
9058
|
-
async request(
|
|
9075
|
+
async request(path76, init) {
|
|
9059
9076
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
9060
|
-
const res = await this.http(`${BASE}${
|
|
9077
|
+
const res = await this.http(`${BASE}${path76}`, {
|
|
9061
9078
|
...init,
|
|
9062
9079
|
headers: {
|
|
9063
9080
|
Authorization: auth,
|
|
@@ -9068,13 +9085,13 @@ var PixelLabClient = class {
|
|
|
9068
9085
|
const text = await res.text();
|
|
9069
9086
|
if (!res.ok) {
|
|
9070
9087
|
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' : "";
|
|
9071
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
9088
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path76} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
9072
9089
|
}
|
|
9073
9090
|
if (!text) return {};
|
|
9074
9091
|
try {
|
|
9075
9092
|
return JSON.parse(text);
|
|
9076
9093
|
} catch {
|
|
9077
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
9094
|
+
throw new Error(`${init?.method ?? "GET"} ${path76} returned invalid JSON`);
|
|
9078
9095
|
}
|
|
9079
9096
|
}
|
|
9080
9097
|
async balance() {
|
|
@@ -9621,10 +9638,10 @@ var PixelLabClient = class {
|
|
|
9621
9638
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
9622
9639
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
9623
9640
|
const south = args.reference?.south;
|
|
9624
|
-
let
|
|
9641
|
+
let path76;
|
|
9625
9642
|
let body;
|
|
9626
9643
|
if (args.mode === "v3") {
|
|
9627
|
-
|
|
9644
|
+
path76 = "/create-character-v3";
|
|
9628
9645
|
body = {
|
|
9629
9646
|
description: args.description,
|
|
9630
9647
|
image_size: imageSize,
|
|
@@ -9638,7 +9655,7 @@ var PixelLabClient = class {
|
|
|
9638
9655
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
9639
9656
|
};
|
|
9640
9657
|
} else if (args.mode === "pro-flash") {
|
|
9641
|
-
|
|
9658
|
+
path76 = "/create-character-pro-flash";
|
|
9642
9659
|
const traits = args.styleTraits;
|
|
9643
9660
|
body = {
|
|
9644
9661
|
description: args.description,
|
|
@@ -9662,7 +9679,7 @@ var PixelLabClient = class {
|
|
|
9662
9679
|
} : {}
|
|
9663
9680
|
};
|
|
9664
9681
|
} else if (args.mode === "pro") {
|
|
9665
|
-
|
|
9682
|
+
path76 = "/create-character-pro";
|
|
9666
9683
|
body = {
|
|
9667
9684
|
description: args.description,
|
|
9668
9685
|
image_size: imageSize,
|
|
@@ -9676,7 +9693,7 @@ var PixelLabClient = class {
|
|
|
9676
9693
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
9677
9694
|
};
|
|
9678
9695
|
} else {
|
|
9679
|
-
|
|
9696
|
+
path76 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
9680
9697
|
body = {
|
|
9681
9698
|
description: args.description,
|
|
9682
9699
|
image_size: imageSize,
|
|
@@ -9694,8 +9711,8 @@ var PixelLabClient = class {
|
|
|
9694
9711
|
};
|
|
9695
9712
|
}
|
|
9696
9713
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
9697
|
-
const raw = await this.request(
|
|
9698
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
9714
|
+
const raw = await this.request(path76, { method: "POST", body: JSON.stringify(body) });
|
|
9715
|
+
return validateResponse(CharacterSubmitSchema, raw, path76.slice(1));
|
|
9699
9716
|
}
|
|
9700
9717
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
9701
9718
|
async createCharacterState(args) {
|
|
@@ -15021,9 +15038,9 @@ var RetroDiffusionClient = class {
|
|
|
15021
15038
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
15022
15039
|
return Buffer.from(await response.arrayBuffer());
|
|
15023
15040
|
}
|
|
15024
|
-
async call(
|
|
15041
|
+
async call(path76, init = {}) {
|
|
15025
15042
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
15026
|
-
const response = await this.request(`${this.baseUrl}${
|
|
15043
|
+
const response = await this.request(`${this.baseUrl}${path76}`, {
|
|
15027
15044
|
...init,
|
|
15028
15045
|
headers: {
|
|
15029
15046
|
"Content-Type": "application/json",
|
|
@@ -18319,10 +18336,10 @@ function isSha256Hash(value) {
|
|
|
18319
18336
|
function parseCache(value) {
|
|
18320
18337
|
return HashCacheSchema.parse(value);
|
|
18321
18338
|
}
|
|
18322
|
-
async function loadCache(
|
|
18323
|
-
if (!existsSync18(
|
|
18339
|
+
async function loadCache(path76) {
|
|
18340
|
+
if (!existsSync18(path76)) return { version: 1, hashes: {} };
|
|
18324
18341
|
try {
|
|
18325
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(
|
|
18342
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path76, "utf8")));
|
|
18326
18343
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
18327
18344
|
return {
|
|
18328
18345
|
version: 1,
|
|
@@ -18334,18 +18351,18 @@ async function loadCache(path74) {
|
|
|
18334
18351
|
return { version: 1, hashes: {} };
|
|
18335
18352
|
}
|
|
18336
18353
|
}
|
|
18337
|
-
async function saveCache(
|
|
18354
|
+
async function saveCache(path76, cache) {
|
|
18338
18355
|
const sorted = {};
|
|
18339
18356
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
18340
18357
|
const hash = cache.hashes[key2];
|
|
18341
18358
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
18342
18359
|
sorted[key2] = hash;
|
|
18343
18360
|
}
|
|
18344
|
-
await mkdir9(pathModule.dirname(pathModule.resolve(
|
|
18345
|
-
const tmp = `${
|
|
18361
|
+
await mkdir9(pathModule.dirname(pathModule.resolve(path76)), { recursive: true });
|
|
18362
|
+
const tmp = `${path76}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18346
18363
|
try {
|
|
18347
18364
|
await writeFile9(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
18348
|
-
await rename7(tmp,
|
|
18365
|
+
await rename7(tmp, path76);
|
|
18349
18366
|
} finally {
|
|
18350
18367
|
await rm5(tmp, { force: true });
|
|
18351
18368
|
}
|
|
@@ -22160,6 +22177,18 @@ async function readModelCompanion(editFile) {
|
|
|
22160
22177
|
return null;
|
|
22161
22178
|
}
|
|
22162
22179
|
}
|
|
22180
|
+
function modelEditStatus(companion, builtSha256) {
|
|
22181
|
+
if (!companion) return "unrecorded";
|
|
22182
|
+
return companion.outputs[0].basedOn === builtSha256 ? "edited" : "rebuilt-since";
|
|
22183
|
+
}
|
|
22184
|
+
async function modelLoadPath(model) {
|
|
22185
|
+
const base = { styleId: model.styleId, file: model.file };
|
|
22186
|
+
if (!existsSync26(model.editFile)) return { ...base, load: model.file, from: "built", edit: null, status: null };
|
|
22187
|
+
const companion = await readModelCompanion(model.editFile);
|
|
22188
|
+
const status = companion ? modelEditStatus(companion, sha256(await readFile22(model.file))) : "unrecorded";
|
|
22189
|
+
const useEdit = status !== "rebuilt-since";
|
|
22190
|
+
return { ...base, load: useEdit ? model.editFile : model.file, from: useEdit ? "edit" : "built", edit: model.editFile, status };
|
|
22191
|
+
}
|
|
22163
22192
|
async function replaceFile2(file, bytes) {
|
|
22164
22193
|
await mkdir14(path34.dirname(file), { recursive: true });
|
|
22165
22194
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
@@ -22566,13 +22595,13 @@ function poseNodes(document, pose) {
|
|
|
22566
22595
|
const posed = /* @__PURE__ */ new Map();
|
|
22567
22596
|
for (const channel of animation.channels) {
|
|
22568
22597
|
const node = channel.target.node;
|
|
22569
|
-
const
|
|
22570
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
22598
|
+
const path76 = channel.target.path;
|
|
22599
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path76)) continue;
|
|
22571
22600
|
const sampler = animation.samplers[channel.sampler];
|
|
22572
22601
|
if (!sampler) continue;
|
|
22573
22602
|
const times = readAccessor(document, sampler.input).data;
|
|
22574
22603
|
const values = readAccessor(document, sampler.output);
|
|
22575
|
-
const width =
|
|
22604
|
+
const width = path76 === "rotation" ? 4 : 3;
|
|
22576
22605
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
22577
22606
|
const valueAt = (key3) => Array.from(values.data.subarray((cubic ? key3 * 3 + 1 : key3) * width, (cubic ? key3 * 3 + 1 : key3) * width + width));
|
|
22578
22607
|
const last = times.length - 1;
|
|
@@ -22584,16 +22613,16 @@ function poseNodes(document, pose) {
|
|
|
22584
22613
|
const span = times[key2 + 1] - times[key2];
|
|
22585
22614
|
const f = span > 0 ? (time - times[key2]) / span : 0;
|
|
22586
22615
|
const next = valueAt(key2 + 1);
|
|
22587
|
-
const sign =
|
|
22616
|
+
const sign = path76 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
22588
22617
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
22589
22618
|
}
|
|
22590
|
-
if (
|
|
22619
|
+
if (path76 === "rotation") {
|
|
22591
22620
|
const length = Math.hypot(...value) || 1;
|
|
22592
22621
|
value = value.map((v) => v / length);
|
|
22593
22622
|
}
|
|
22594
22623
|
const base = posed.get(node) ?? { ...document.json.nodes?.[node] ?? {} };
|
|
22595
22624
|
if (base.matrix) delete base.matrix;
|
|
22596
|
-
base[
|
|
22625
|
+
base[path76] = value;
|
|
22597
22626
|
posed.set(node, base);
|
|
22598
22627
|
}
|
|
22599
22628
|
return posed;
|
|
@@ -23443,7 +23472,7 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
23443
23472
|
});
|
|
23444
23473
|
edit = {
|
|
23445
23474
|
...described,
|
|
23446
|
-
status:
|
|
23475
|
+
status: modelEditStatus(companion, file.sha256),
|
|
23447
23476
|
editor: companion?.editor ?? null,
|
|
23448
23477
|
savedAt: companion?.savedAt ?? null,
|
|
23449
23478
|
changedSince: companion ? companion.outputs[0].sha256 !== described.sha256 : false,
|
|
@@ -24885,6 +24914,42 @@ async function runModel(args) {
|
|
|
24885
24914
|
}
|
|
24886
24915
|
return;
|
|
24887
24916
|
}
|
|
24917
|
+
if (sub === "resolve") {
|
|
24918
|
+
const models = args.target ? [await resolveModel(loaded, args.target, styles)] : await discoverModels(loaded, styles);
|
|
24919
|
+
const resolved = await Promise.all(models.map(modelLoadPath));
|
|
24920
|
+
const portable = (file) => portableOutputPath(file, loaded.root);
|
|
24921
|
+
if (args.json) {
|
|
24922
|
+
const rows = resolved.map((entry) => ({
|
|
24923
|
+
styleId: entry.styleId,
|
|
24924
|
+
file: portable(entry.file),
|
|
24925
|
+
load: portable(entry.load),
|
|
24926
|
+
from: entry.from,
|
|
24927
|
+
edit: entry.edit ? portable(entry.edit) : null,
|
|
24928
|
+
status: entry.status,
|
|
24929
|
+
absolute: entry.load
|
|
24930
|
+
}));
|
|
24931
|
+
log(JSON.stringify(args.target ? rows[0] : rows, null, 2));
|
|
24932
|
+
return;
|
|
24933
|
+
}
|
|
24934
|
+
for (const entry of resolved) {
|
|
24935
|
+
if (entry.status === "rebuilt-since") {
|
|
24936
|
+
console.error(` ${portable(entry.file)}: the edit at ${portable(entry.edit)} was made before the model was rebuilt, so the model as built is named; fix the new build or look at both in the gallery`);
|
|
24937
|
+
}
|
|
24938
|
+
}
|
|
24939
|
+
if (args.target) {
|
|
24940
|
+
log(portable(resolved[0].load));
|
|
24941
|
+
return;
|
|
24942
|
+
}
|
|
24943
|
+
if (!resolved.length) {
|
|
24944
|
+
log(" no models: put a .glb under a style's outDir");
|
|
24945
|
+
return;
|
|
24946
|
+
}
|
|
24947
|
+
for (const entry of resolved) {
|
|
24948
|
+
const why = entry.from === "edit" ? `edited copy, ${entry.status}` : entry.status ? `as built; edit is ${entry.status}` : "as built, no edit";
|
|
24949
|
+
log(` ${portable(entry.file)} -> ${portable(entry.load)} (${why})`);
|
|
24950
|
+
}
|
|
24951
|
+
return;
|
|
24952
|
+
}
|
|
24888
24953
|
const ref = args.target;
|
|
24889
24954
|
if (!ref) throw new Error(`model ${sub} needs a model: its path, its file name, or its gallery id. pixelkiln model list shows them.`);
|
|
24890
24955
|
const model = await resolveModel(loaded, ref, styles);
|
|
@@ -29009,6 +29074,374 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
29009
29074
|
};
|
|
29010
29075
|
}
|
|
29011
29076
|
|
|
29077
|
+
// src/pipeline/ldtk-export.ts
|
|
29078
|
+
import { createHash as createHash7 } from "crypto";
|
|
29079
|
+
var LDTK_JSON_VERSION = "1.5.3";
|
|
29080
|
+
var FIRST = 1;
|
|
29081
|
+
var SECOND = 2;
|
|
29082
|
+
var DEMO_WIDTH = 12;
|
|
29083
|
+
var DEMO_HEIGHT = 9;
|
|
29084
|
+
function ldtkRuleMatches(rule, grid, cx, cy) {
|
|
29085
|
+
const radius = Math.floor(rule.size / 2);
|
|
29086
|
+
for (let py = 0; py < rule.size; py++) {
|
|
29087
|
+
for (let px = 0; px < rule.size; px++) {
|
|
29088
|
+
const wanted = rule.pattern[px + py * rule.size];
|
|
29089
|
+
if (wanted === 0) continue;
|
|
29090
|
+
const x = cx + px - radius;
|
|
29091
|
+
const y = cy + py - radius;
|
|
29092
|
+
const inside2 = x >= 0 && y >= 0 && x < grid.width && y < grid.height;
|
|
29093
|
+
const value = inside2 ? grid.cells[y * grid.width + x] : rule.outOfBoundsValue;
|
|
29094
|
+
if (wanted > 0 && value !== wanted) return false;
|
|
29095
|
+
if (wanted < 0 && value === -wanted) return false;
|
|
29096
|
+
}
|
|
29097
|
+
}
|
|
29098
|
+
return true;
|
|
29099
|
+
}
|
|
29100
|
+
function iid(...parts) {
|
|
29101
|
+
const hex2 = createHash7("sha256").update(parts.join("\0")).digest("hex");
|
|
29102
|
+
return `${hex2.slice(0, 8)}-${hex2.slice(8, 12)}-4${hex2.slice(13, 16)}-8${hex2.slice(17, 20)}-${hex2.slice(20, 32)}`;
|
|
29103
|
+
}
|
|
29104
|
+
function identifier(text, fallback) {
|
|
29105
|
+
const slug3 = text.replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
29106
|
+
return /^[A-Za-z]/.test(slug3) ? slug3 : slug3 ? `${fallback}_${slug3}` : fallback;
|
|
29107
|
+
}
|
|
29108
|
+
function dominantValue(mask) {
|
|
29109
|
+
const first = [0, 1, 2, 3].filter((bit) => (mask & 1 << bit) !== 0).length;
|
|
29110
|
+
return first * 2 >= 4 ? FIRST : SECOND;
|
|
29111
|
+
}
|
|
29112
|
+
function ldtkPattern(rules, mask) {
|
|
29113
|
+
const value = (bit) => (mask & 1 << bit) !== 0 ? FIRST : SECOND;
|
|
29114
|
+
const pattern = new Array(9).fill(0);
|
|
29115
|
+
if (rules.ruleType === "corner") {
|
|
29116
|
+
pattern[4] = value(3);
|
|
29117
|
+
pattern[5] = value(2);
|
|
29118
|
+
pattern[7] = value(1);
|
|
29119
|
+
pattern[8] = value(0);
|
|
29120
|
+
return pattern;
|
|
29121
|
+
}
|
|
29122
|
+
pattern[4] = dominantValue(mask);
|
|
29123
|
+
pattern[1] = value(0);
|
|
29124
|
+
pattern[5] = value(1);
|
|
29125
|
+
pattern[7] = value(2);
|
|
29126
|
+
pattern[3] = value(3);
|
|
29127
|
+
return pattern;
|
|
29128
|
+
}
|
|
29129
|
+
function resolveLdtkTiles(rules, grid) {
|
|
29130
|
+
const out = [];
|
|
29131
|
+
for (let cy = 0; cy < grid.height; cy++) {
|
|
29132
|
+
for (let cx = 0; cx < grid.width; cx++) {
|
|
29133
|
+
const rule = rules.find((candidate) => ldtkRuleMatches(candidate, grid, cx, cy));
|
|
29134
|
+
if (rule) out.push({ cx, cy, rule, tile: rule.tileRectsIds[(cx * 7 + cy * 13) % rule.tileRectsIds.length][0] });
|
|
29135
|
+
}
|
|
29136
|
+
}
|
|
29137
|
+
return out;
|
|
29138
|
+
}
|
|
29139
|
+
function demoGrid(rules, wanted) {
|
|
29140
|
+
let best = null;
|
|
29141
|
+
let bestCovered = -1;
|
|
29142
|
+
for (let seed = 1; seed <= 400; seed++) {
|
|
29143
|
+
let state = seed * 2654435761 >>> 0;
|
|
29144
|
+
const cells = Array.from({ length: DEMO_WIDTH * DEMO_HEIGHT }, () => {
|
|
29145
|
+
state = Math.imul(state, 1664525) + 1013904223 >>> 0;
|
|
29146
|
+
return (state >>> 16) % 100 < 52 ? FIRST : SECOND;
|
|
29147
|
+
});
|
|
29148
|
+
const grid = { width: DEMO_WIDTH, height: DEMO_HEIGHT, cells };
|
|
29149
|
+
const covered = new Set(resolveLdtkTiles(rules, grid).map((hit) => hit.rule.uid)).size;
|
|
29150
|
+
if (covered > bestCovered) {
|
|
29151
|
+
best = grid;
|
|
29152
|
+
bestCovered = covered;
|
|
29153
|
+
}
|
|
29154
|
+
if (covered >= wanted) break;
|
|
29155
|
+
}
|
|
29156
|
+
return best;
|
|
29157
|
+
}
|
|
29158
|
+
var TERRAIN_COLORS = ["#5AB552", "#4C78A8"];
|
|
29159
|
+
function buildLdtk(generic, tileType) {
|
|
29160
|
+
const rules = generic.rules;
|
|
29161
|
+
if (!rules || rules.ruleType === "outline") {
|
|
29162
|
+
throw new Error("ldtk export needs recognized corner or edge adjacency rules; use --format generic");
|
|
29163
|
+
}
|
|
29164
|
+
if (tileType === void 0 || tileType === "isometric" || tileType === "oblique" || tileType === "hex" || tileType === "hex_pointy") {
|
|
29165
|
+
throw new Error(
|
|
29166
|
+
`ldtk export needs square tiles on an orthogonal grid, and this set is ${tileType ?? "isometric"}; use --format generic or --format tiled`
|
|
29167
|
+
);
|
|
29168
|
+
}
|
|
29169
|
+
const grid = generic.tile.width;
|
|
29170
|
+
if (generic.tile.width !== generic.tile.height) {
|
|
29171
|
+
throw new Error(`ldtk grids are square; these tiles are ${generic.tile.width}x${generic.tile.height}`);
|
|
29172
|
+
}
|
|
29173
|
+
const corner = rules.ruleType === "corner";
|
|
29174
|
+
const base = identifier(generic.name.replace("/", "_"), "Tileset");
|
|
29175
|
+
const name = base.charAt(0).toUpperCase() + base.slice(1);
|
|
29176
|
+
const terrainNames = [rules.terrains[0] ?? "feature", rules.terrains[1] ?? "background"];
|
|
29177
|
+
const columns = generic.sheet.columns;
|
|
29178
|
+
const rows = Math.ceil(generic.tiles.length / columns);
|
|
29179
|
+
const byMask = /* @__PURE__ */ new Map();
|
|
29180
|
+
for (const tile of generic.tiles) {
|
|
29181
|
+
if (tile.bitmask === void 0) continue;
|
|
29182
|
+
byMask.set(tile.bitmask, [...byMask.get(tile.bitmask) ?? [], tile.id]);
|
|
29183
|
+
}
|
|
29184
|
+
if (!byMask.size) throw new Error("ldtk export found no tiles with adjacency masks; use --format generic");
|
|
29185
|
+
const tilesetUid = 1;
|
|
29186
|
+
const sourceUid = 2;
|
|
29187
|
+
const autoUid = 3;
|
|
29188
|
+
const groupUid = 4;
|
|
29189
|
+
const ruleList = [...byMask.entries()].map(([mask, ids], index) => ({
|
|
29190
|
+
uid: 5 + index,
|
|
29191
|
+
active: true,
|
|
29192
|
+
size: 3,
|
|
29193
|
+
tileRectsIds: ids.map((id) => [id]),
|
|
29194
|
+
alpha: 1,
|
|
29195
|
+
chance: 1,
|
|
29196
|
+
breakOnMatch: true,
|
|
29197
|
+
pattern: ldtkPattern(rules, mask),
|
|
29198
|
+
flipX: false,
|
|
29199
|
+
flipY: false,
|
|
29200
|
+
xModulo: 1,
|
|
29201
|
+
yModulo: 1,
|
|
29202
|
+
xOffset: 0,
|
|
29203
|
+
yOffset: 0,
|
|
29204
|
+
tileXOffset: 0,
|
|
29205
|
+
tileYOffset: 0,
|
|
29206
|
+
tileRandomXMin: 0,
|
|
29207
|
+
tileRandomXMax: 0,
|
|
29208
|
+
tileRandomYMin: 0,
|
|
29209
|
+
tileRandomYMax: 0,
|
|
29210
|
+
checker: "None",
|
|
29211
|
+
tileMode: "Single",
|
|
29212
|
+
pivotX: 0,
|
|
29213
|
+
pivotY: 0,
|
|
29214
|
+
outOfBoundsValue: SECOND,
|
|
29215
|
+
invalidated: false,
|
|
29216
|
+
perlinActive: false,
|
|
29217
|
+
perlinSeed: 1,
|
|
29218
|
+
perlinScale: 0.2,
|
|
29219
|
+
perlinOctaves: 2
|
|
29220
|
+
}));
|
|
29221
|
+
const levelUid = 5 + ruleList.length;
|
|
29222
|
+
const nextUid = levelUid + 1;
|
|
29223
|
+
const tileRect = (id) => {
|
|
29224
|
+
const tile = generic.tiles.find((candidate) => candidate.id === id);
|
|
29225
|
+
return tile ? { tilesetUid, x: tile.x, y: tile.y, w: tile.width, h: tile.height } : null;
|
|
29226
|
+
};
|
|
29227
|
+
const full = (1 << rules.arity) - 1;
|
|
29228
|
+
const representative = (terrain) => generic.tiles.find((tile) => tile.bitmask === (terrain === 0 ? full : 0))?.id;
|
|
29229
|
+
const shift = corner ? -Math.floor(grid / 2) : 0;
|
|
29230
|
+
const sourceName = `${name}_${corner ? "corners" : "cells"}`;
|
|
29231
|
+
const autoName = name;
|
|
29232
|
+
const layerBase = {
|
|
29233
|
+
guideGridWid: 0,
|
|
29234
|
+
guideGridHei: 0,
|
|
29235
|
+
displayOpacity: 1,
|
|
29236
|
+
inactiveOpacity: 1,
|
|
29237
|
+
hideInList: false,
|
|
29238
|
+
hideFieldsWhenInactive: false,
|
|
29239
|
+
canSelectWhenInactive: true,
|
|
29240
|
+
parallaxFactorX: 0,
|
|
29241
|
+
parallaxFactorY: 0,
|
|
29242
|
+
parallaxScaling: true,
|
|
29243
|
+
requiredTags: [],
|
|
29244
|
+
excludedTags: [],
|
|
29245
|
+
autoTilesKilledByOtherLayerUid: null,
|
|
29246
|
+
uiFilterTags: [],
|
|
29247
|
+
useAsyncRender: false,
|
|
29248
|
+
tilePivotX: 0,
|
|
29249
|
+
tilePivotY: 0,
|
|
29250
|
+
biomeFieldUid: null,
|
|
29251
|
+
gridSize: grid,
|
|
29252
|
+
tilesetDefUid: tilesetUid
|
|
29253
|
+
};
|
|
29254
|
+
const sourceLayer = {
|
|
29255
|
+
__type: "IntGrid",
|
|
29256
|
+
identifier: sourceName,
|
|
29257
|
+
type: "IntGrid",
|
|
29258
|
+
uid: sourceUid,
|
|
29259
|
+
doc: corner ? `Paint ${terrainNames[0]} (1) and ${terrainNames[1]} (2). Each cell is a corner where four tiles meet, so it is drawn half a tile up and left of the tiles it controls.` : `Paint ${terrainNames[0]} (1) and ${terrainNames[1]} (2). Each tile looks at its own cell and the four around it.`,
|
|
29260
|
+
uiColor: TERRAIN_COLORS[0],
|
|
29261
|
+
...layerBase,
|
|
29262
|
+
renderInWorldView: true,
|
|
29263
|
+
pxOffsetX: shift,
|
|
29264
|
+
pxOffsetY: shift,
|
|
29265
|
+
intGridValues: [FIRST, SECOND].map((value, index) => ({
|
|
29266
|
+
value,
|
|
29267
|
+
identifier: identifier(terrainNames[index], `terrain${value}`),
|
|
29268
|
+
color: TERRAIN_COLORS[index],
|
|
29269
|
+
tile: tileRect(representative(index)),
|
|
29270
|
+
groupUid: 0
|
|
29271
|
+
})),
|
|
29272
|
+
intGridValuesGroups: [],
|
|
29273
|
+
autoRuleGroups: [],
|
|
29274
|
+
autoSourceLayerDefUid: null
|
|
29275
|
+
};
|
|
29276
|
+
const autoLayer = {
|
|
29277
|
+
__type: "AutoLayer",
|
|
29278
|
+
identifier: autoName,
|
|
29279
|
+
type: "AutoLayer",
|
|
29280
|
+
uid: autoUid,
|
|
29281
|
+
doc: `Drawn by rules from ${sourceName}: one rule for each way the two terrains can meet.`,
|
|
29282
|
+
uiColor: TERRAIN_COLORS[1],
|
|
29283
|
+
...layerBase,
|
|
29284
|
+
renderInWorldView: true,
|
|
29285
|
+
pxOffsetX: 0,
|
|
29286
|
+
pxOffsetY: 0,
|
|
29287
|
+
intGridValues: [],
|
|
29288
|
+
intGridValuesGroups: [],
|
|
29289
|
+
autoRuleGroups: [{
|
|
29290
|
+
uid: groupUid,
|
|
29291
|
+
name: "Borders",
|
|
29292
|
+
color: null,
|
|
29293
|
+
icon: null,
|
|
29294
|
+
active: true,
|
|
29295
|
+
isOptional: false,
|
|
29296
|
+
rules: ruleList,
|
|
29297
|
+
usesWizard: false,
|
|
29298
|
+
requiredBiomeValues: [],
|
|
29299
|
+
biomeRequirementMode: 0
|
|
29300
|
+
}],
|
|
29301
|
+
autoSourceLayerDefUid: sourceUid
|
|
29302
|
+
};
|
|
29303
|
+
const level = demoGrid(ruleList, ruleList.length);
|
|
29304
|
+
const hits = resolveLdtkTiles(ruleList, level);
|
|
29305
|
+
const tileAt = (id) => ({ x: id % columns * grid, y: Math.floor(id / columns) * grid });
|
|
29306
|
+
const instanceBase = (layerDef, offset) => ({
|
|
29307
|
+
__identifier: layerDef.identifier,
|
|
29308
|
+
__type: layerDef.__type,
|
|
29309
|
+
__cWid: DEMO_WIDTH,
|
|
29310
|
+
__cHei: DEMO_HEIGHT,
|
|
29311
|
+
__gridSize: grid,
|
|
29312
|
+
__opacity: 1,
|
|
29313
|
+
__pxTotalOffsetX: offset,
|
|
29314
|
+
__pxTotalOffsetY: offset,
|
|
29315
|
+
__tilesetDefUid: tilesetUid,
|
|
29316
|
+
__tilesetRelPath: generic.image,
|
|
29317
|
+
iid: iid(generic.name, "layer", layerDef.uid),
|
|
29318
|
+
levelId: levelUid,
|
|
29319
|
+
layerDefUid: layerDef.uid,
|
|
29320
|
+
pxOffsetX: 0,
|
|
29321
|
+
pxOffsetY: 0,
|
|
29322
|
+
visible: true,
|
|
29323
|
+
optionalRules: [],
|
|
29324
|
+
seed: 1e3 + layerDef.uid,
|
|
29325
|
+
overrideTilesetUid: null,
|
|
29326
|
+
gridTiles: [],
|
|
29327
|
+
entityInstances: []
|
|
29328
|
+
});
|
|
29329
|
+
const project2 = {
|
|
29330
|
+
__header__: {
|
|
29331
|
+
fileType: "LDtk Project JSON",
|
|
29332
|
+
app: "LDtk",
|
|
29333
|
+
doc: "https://ldtk.io/json",
|
|
29334
|
+
schema: "https://ldtk.io/files/JSON_SCHEMA.json",
|
|
29335
|
+
appAuthor: "Sebastien 'deepnight' Benard",
|
|
29336
|
+
appVersion: LDTK_JSON_VERSION,
|
|
29337
|
+
url: "https://ldtk.io"
|
|
29338
|
+
},
|
|
29339
|
+
iid: iid(generic.name, "project"),
|
|
29340
|
+
jsonVersion: LDTK_JSON_VERSION,
|
|
29341
|
+
appBuildId: 473702,
|
|
29342
|
+
nextUid,
|
|
29343
|
+
identifierStyle: "Capitalize",
|
|
29344
|
+
toc: [],
|
|
29345
|
+
worldLayout: "LinearHorizontal",
|
|
29346
|
+
worldGridWidth: 256,
|
|
29347
|
+
worldGridHeight: 256,
|
|
29348
|
+
defaultLevelWidth: DEMO_WIDTH * grid,
|
|
29349
|
+
defaultLevelHeight: DEMO_HEIGHT * grid,
|
|
29350
|
+
defaultPivotX: 0,
|
|
29351
|
+
defaultPivotY: 0,
|
|
29352
|
+
defaultGridSize: grid,
|
|
29353
|
+
defaultEntityWidth: grid,
|
|
29354
|
+
defaultEntityHeight: grid,
|
|
29355
|
+
bgColor: "#4A5066",
|
|
29356
|
+
defaultLevelBgColor: "#474B67",
|
|
29357
|
+
minifyJson: false,
|
|
29358
|
+
externalLevels: false,
|
|
29359
|
+
exportTiled: false,
|
|
29360
|
+
simplifiedExport: false,
|
|
29361
|
+
imageExportMode: "None",
|
|
29362
|
+
exportLevelBg: true,
|
|
29363
|
+
pngFilePattern: null,
|
|
29364
|
+
backupOnSave: false,
|
|
29365
|
+
backupLimit: 10,
|
|
29366
|
+
backupRelPath: null,
|
|
29367
|
+
levelNamePattern: "%world_Level_%idx",
|
|
29368
|
+
tutorialDesc: null,
|
|
29369
|
+
customCommands: [],
|
|
29370
|
+
flags: ["ExportOldTableOfContentData", "UseMultilinesType"],
|
|
29371
|
+
defs: {
|
|
29372
|
+
layers: [autoLayer, sourceLayer],
|
|
29373
|
+
entities: [],
|
|
29374
|
+
tilesets: [{
|
|
29375
|
+
__cWid: columns,
|
|
29376
|
+
__cHei: rows,
|
|
29377
|
+
identifier: `${name}_tiles`,
|
|
29378
|
+
uid: tilesetUid,
|
|
29379
|
+
relPath: generic.image,
|
|
29380
|
+
embedAtlas: null,
|
|
29381
|
+
pxWid: generic.sheet.width,
|
|
29382
|
+
pxHei: generic.sheet.height,
|
|
29383
|
+
tileGridSize: grid,
|
|
29384
|
+
spacing: 0,
|
|
29385
|
+
padding: 0,
|
|
29386
|
+
tags: [],
|
|
29387
|
+
tagsSourceEnumUid: null,
|
|
29388
|
+
enumTags: [],
|
|
29389
|
+
customData: generic.tiles.filter((tile) => tile.bitmask !== void 0).map((tile) => ({ tileId: tile.id, data: `mask=${tile.bitmask}` })),
|
|
29390
|
+
savedSelections: [],
|
|
29391
|
+
cachedPixelData: null
|
|
29392
|
+
}],
|
|
29393
|
+
enums: [],
|
|
29394
|
+
externalEnums: [],
|
|
29395
|
+
levelFields: []
|
|
29396
|
+
},
|
|
29397
|
+
levels: [{
|
|
29398
|
+
identifier: "Preview",
|
|
29399
|
+
iid: iid(generic.name, "level"),
|
|
29400
|
+
uid: levelUid,
|
|
29401
|
+
// A linear world ignores the position; LDtk itself writes -1 for it.
|
|
29402
|
+
worldX: -1,
|
|
29403
|
+
worldY: -1,
|
|
29404
|
+
worldDepth: 0,
|
|
29405
|
+
pxWid: DEMO_WIDTH * grid,
|
|
29406
|
+
pxHei: DEMO_HEIGHT * grid,
|
|
29407
|
+
__bgColor: "#474B67",
|
|
29408
|
+
bgColor: null,
|
|
29409
|
+
useAutoIdentifier: false,
|
|
29410
|
+
bgRelPath: null,
|
|
29411
|
+
bgPos: null,
|
|
29412
|
+
bgPivotX: 0.5,
|
|
29413
|
+
bgPivotY: 0.5,
|
|
29414
|
+
__smartColor: "#9A9CAB",
|
|
29415
|
+
__bgPos: null,
|
|
29416
|
+
externalRelPath: null,
|
|
29417
|
+
fieldInstances: [],
|
|
29418
|
+
layerInstances: [
|
|
29419
|
+
{
|
|
29420
|
+
...instanceBase(autoLayer, 0),
|
|
29421
|
+
intGridCsv: [],
|
|
29422
|
+
autoLayerTiles: hits.map((hit) => ({
|
|
29423
|
+
px: [hit.cx * grid, hit.cy * grid],
|
|
29424
|
+
src: [tileAt(hit.tile).x, tileAt(hit.tile).y],
|
|
29425
|
+
f: 0,
|
|
29426
|
+
t: hit.tile,
|
|
29427
|
+
d: [hit.rule.uid, hit.cy * DEMO_WIDTH + hit.cx],
|
|
29428
|
+
a: 1
|
|
29429
|
+
}))
|
|
29430
|
+
},
|
|
29431
|
+
{
|
|
29432
|
+
...instanceBase(sourceLayer, shift),
|
|
29433
|
+
intGridCsv: level.cells,
|
|
29434
|
+
autoLayerTiles: []
|
|
29435
|
+
}
|
|
29436
|
+
],
|
|
29437
|
+
__neighbours: []
|
|
29438
|
+
}],
|
|
29439
|
+
worlds: [],
|
|
29440
|
+
dummyWorldIid: iid(generic.name, "world")
|
|
29441
|
+
};
|
|
29442
|
+
return JSON.stringify(project2, null, 2) + "\n";
|
|
29443
|
+
}
|
|
29444
|
+
|
|
29012
29445
|
// src/pipeline/tileset-export.ts
|
|
29013
29446
|
function normalizeTileRules(raw) {
|
|
29014
29447
|
if (!isRecord2(raw)) return null;
|
|
@@ -29125,6 +29558,15 @@ function exportTileset(entry, spec, options) {
|
|
|
29125
29558
|
sources: packed.sources
|
|
29126
29559
|
};
|
|
29127
29560
|
}
|
|
29561
|
+
if (options.format === "ldtk") {
|
|
29562
|
+
return {
|
|
29563
|
+
png: packed.png,
|
|
29564
|
+
extension: ".ldtk",
|
|
29565
|
+
document: buildLdtk(generic, spec.tileType),
|
|
29566
|
+
generic,
|
|
29567
|
+
sources: packed.sources
|
|
29568
|
+
};
|
|
29569
|
+
}
|
|
29128
29570
|
return {
|
|
29129
29571
|
png: packed.png,
|
|
29130
29572
|
extension: ".tres",
|
|
@@ -29584,7 +30026,7 @@ async function runExport(args) {
|
|
|
29584
30026
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
29585
30027
|
const style = loaded.manifest.styles[spec.styleId];
|
|
29586
30028
|
const defaultBase = path53.resolve(manifestDir, style.outDir, `${spec.assetId}-tileset`);
|
|
29587
|
-
const base = args.out ? path53.resolve(args.out.replace(/\.(?:png|json|tsj|tres)$/i, "")) : defaultBase;
|
|
30029
|
+
const base = args.out ? path53.resolve(args.out.replace(/\.(?:png|json|tsj|tres|ldtk)$/i, "")) : defaultBase;
|
|
29588
30030
|
const result = exportTileset(entry, spec, {
|
|
29589
30031
|
format,
|
|
29590
30032
|
manifestDir,
|
|
@@ -29629,15 +30071,383 @@ function sheetFormat(args) {
|
|
|
29629
30071
|
}
|
|
29630
30072
|
|
|
29631
30073
|
// src/cli/commands/pixellab-utils.ts
|
|
29632
|
-
import { readFile as
|
|
29633
|
-
import
|
|
30074
|
+
import { readFile as readFile40 } from "fs/promises";
|
|
30075
|
+
import path57 from "path";
|
|
29634
30076
|
|
|
29635
|
-
// src/
|
|
29636
|
-
import {
|
|
29637
|
-
import {
|
|
30077
|
+
// src/codex-vfx.ts
|
|
30078
|
+
import { createHash as createHash8 } from "crypto";
|
|
30079
|
+
import { existsSync as existsSync46, readFileSync as readFileSync9, readdirSync as readdirSync2 } from "fs";
|
|
30080
|
+
import { readFile as readFile38 } from "fs/promises";
|
|
29638
30081
|
import { createRequire as createRequire2 } from "module";
|
|
29639
|
-
import
|
|
30082
|
+
import path55 from "path";
|
|
29640
30083
|
import { pathToFileURL } from "url";
|
|
30084
|
+
import vm from "vm";
|
|
30085
|
+
|
|
30086
|
+
// src/local-vfx.ts
|
|
30087
|
+
import { existsSync as existsSync45 } from "fs";
|
|
30088
|
+
import { mkdir as mkdir19, writeFile as writeFile24 } from "fs/promises";
|
|
30089
|
+
import path54 from "path";
|
|
30090
|
+
function localSheet(render) {
|
|
30091
|
+
const { width, height, frames } = render;
|
|
30092
|
+
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
30093
|
+
const rows = Math.ceil(frames.length / columns);
|
|
30094
|
+
const sheet = Buffer.alloc(columns * width * rows * height * 4);
|
|
30095
|
+
const rects = frames.map((rgba, index) => {
|
|
30096
|
+
const x = index % columns * width;
|
|
30097
|
+
const y = Math.floor(index / columns) * height;
|
|
30098
|
+
for (let row = 0; row < height; row++) {
|
|
30099
|
+
rgba.copy(sheet, ((y + row) * columns * width + x) * 4, row * width * 4, (row + 1) * width * 4);
|
|
30100
|
+
}
|
|
30101
|
+
return { x, y, w: width, h: height };
|
|
30102
|
+
});
|
|
30103
|
+
return { png: encodeRgbaPng(columns * width, rows * height, sheet), columns, rows, rects };
|
|
30104
|
+
}
|
|
30105
|
+
function assertFreshOutputs(out, force) {
|
|
30106
|
+
const paths = vfxOutputPaths(out);
|
|
30107
|
+
if (!force) {
|
|
30108
|
+
for (const file of [paths.sheet, paths.atlas, paths.provenance]) {
|
|
30109
|
+
if (existsSync45(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
30110
|
+
}
|
|
30111
|
+
}
|
|
30112
|
+
return paths;
|
|
30113
|
+
}
|
|
30114
|
+
async function writeLocalVfx(opts) {
|
|
30115
|
+
const { paths, render } = opts;
|
|
30116
|
+
const sheet = localSheet(render);
|
|
30117
|
+
const clip = path54.basename(paths.sheet, ".png");
|
|
30118
|
+
const anchor = { kind: "origin", ...render.anchor };
|
|
30119
|
+
const size = { w: render.width, h: render.height };
|
|
30120
|
+
const atlas = {
|
|
30121
|
+
frames: sheet.rects.map((frame, index) => ({
|
|
30122
|
+
filename: `${clip} ${index}`,
|
|
30123
|
+
frame,
|
|
30124
|
+
rotated: false,
|
|
30125
|
+
trimmed: false,
|
|
30126
|
+
spriteSourceSize: { x: 0, y: 0, ...size },
|
|
30127
|
+
sourceSize: size,
|
|
30128
|
+
duration: Math.round(1e3 / render.fps)
|
|
30129
|
+
})),
|
|
30130
|
+
meta: {
|
|
30131
|
+
app: "pixelkiln",
|
|
30132
|
+
version: "1",
|
|
30133
|
+
image: path54.basename(paths.sheet),
|
|
30134
|
+
format: "RGBA8888",
|
|
30135
|
+
size: { w: sheet.columns * render.width, h: sheet.rows * render.height },
|
|
30136
|
+
scale: "1",
|
|
30137
|
+
frameTags: [{ name: clip, from: 0, to: render.frames.length - 1, direction: "forward" }],
|
|
30138
|
+
anchor,
|
|
30139
|
+
[opts.atlasKey]: {
|
|
30140
|
+
id: opts.effect,
|
|
30141
|
+
name: opts.name,
|
|
30142
|
+
...opts.atlasFacts,
|
|
30143
|
+
fps: render.fps,
|
|
30144
|
+
loop: render.loop,
|
|
30145
|
+
frames: render.frames.length,
|
|
30146
|
+
frameSize: [render.width, render.height],
|
|
30147
|
+
pivot: [anchor.x, anchor.y],
|
|
30148
|
+
columns: sheet.columns
|
|
30149
|
+
}
|
|
30150
|
+
}
|
|
30151
|
+
};
|
|
30152
|
+
const sheetSha256 = sha256(sheet.png);
|
|
30153
|
+
const facts = {
|
|
30154
|
+
name: opts.name,
|
|
30155
|
+
effect: opts.effect,
|
|
30156
|
+
width: render.width,
|
|
30157
|
+
height: render.height,
|
|
30158
|
+
frames: render.frames.length,
|
|
30159
|
+
fps: render.fps,
|
|
30160
|
+
loop: render.loop,
|
|
30161
|
+
anchor
|
|
30162
|
+
};
|
|
30163
|
+
const record = {
|
|
30164
|
+
version: 1,
|
|
30165
|
+
...opts.record,
|
|
30166
|
+
...facts,
|
|
30167
|
+
files: { sheet: path54.basename(paths.sheet), atlas: path54.basename(paths.atlas) },
|
|
30168
|
+
sheetSha256,
|
|
30169
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30170
|
+
recipe: opts.recipe
|
|
30171
|
+
};
|
|
30172
|
+
await mkdir19(path54.dirname(paths.sheet), { recursive: true });
|
|
30173
|
+
await writeFile24(paths.sheet, sheet.png);
|
|
30174
|
+
await writeFile24(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
30175
|
+
`);
|
|
30176
|
+
await writeFile24(paths.provenance, `${JSON.stringify(record, null, 2)}
|
|
30177
|
+
`);
|
|
30178
|
+
return { facts, columns: sheet.columns, sheetSha256, paths: { sheet: paths.sheet, atlas: paths.atlas, provenance: paths.provenance } };
|
|
30179
|
+
}
|
|
30180
|
+
|
|
30181
|
+
// src/codex-vfx.ts
|
|
30182
|
+
var CODEX_ID = "codex";
|
|
30183
|
+
var CODEX_PACKAGE = "pixel-vfx-codex";
|
|
30184
|
+
var CODEX_REPOSITORY = "https://github.com/888wing/pixel-vfx-codex";
|
|
30185
|
+
var CODEX_INSTALL = "npm i github:888wing/pixel-vfx-codex";
|
|
30186
|
+
var CODEX_CAMERAS = ["2d", "25d", "3d"];
|
|
30187
|
+
var CANVAS = { "2d": [160, 100], "25d": [240, 150], "3d": [240, 150] };
|
|
30188
|
+
var CODEX_TUNE_KEYS = ["size", "gain", "density", "dither", "outline", "hitstop", "shake", "flash", "snap"];
|
|
30189
|
+
function missingCodex(cause) {
|
|
30190
|
+
return new PixelKilnError(
|
|
30191
|
+
"pixel-vfx-codex is not installed, so there is nothing to render these effects with",
|
|
30192
|
+
"capability",
|
|
30193
|
+
{ hint: `Install it beside your project: ${CODEX_INSTALL} (${CODEX_REPOSITORY}, MIT; it is not on the npm registry)`, cause }
|
|
30194
|
+
);
|
|
30195
|
+
}
|
|
30196
|
+
function findCodexRoot(from) {
|
|
30197
|
+
const bases = from?.map((base) => pathToFileURL(path55.resolve(base, "package.json")).href) ?? [
|
|
30198
|
+
pathToFileURL(path55.join(process.cwd(), "package.json")).href,
|
|
30199
|
+
import.meta.url
|
|
30200
|
+
];
|
|
30201
|
+
let failure;
|
|
30202
|
+
for (const base of bases) {
|
|
30203
|
+
try {
|
|
30204
|
+
return path55.dirname(createRequire2(base).resolve(`${CODEX_PACKAGE}/package.json`));
|
|
30205
|
+
} catch (error) {
|
|
30206
|
+
failure = error;
|
|
30207
|
+
}
|
|
30208
|
+
}
|
|
30209
|
+
throw missingCodex(failure);
|
|
30210
|
+
}
|
|
30211
|
+
function loadCodex(from) {
|
|
30212
|
+
const root = findCodexRoot(from);
|
|
30213
|
+
const read = (...parts) => readFileSync9(path55.join(root, ...parts), "utf8");
|
|
30214
|
+
const pkg = JSON.parse(read("package.json"));
|
|
30215
|
+
const version = typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
30216
|
+
for (const required of ["engine/pxfx.js", "engine/kit.js", "fx", "data/meta.json"]) {
|
|
30217
|
+
if (!existsSync46(path55.join(root, required))) {
|
|
30218
|
+
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) has no ${required}; PixelKiln was written against its 1.0.0 layout`, "capability");
|
|
30219
|
+
}
|
|
30220
|
+
}
|
|
30221
|
+
const sources = [read("engine", "pxfx.js"), read("engine", "kit.js")];
|
|
30222
|
+
const context = vm.createContext({ console });
|
|
30223
|
+
sources.forEach((source, index) => vm.runInContext(source, context, { filename: index ? "engine/kit.js" : "engine/pxfx.js" }));
|
|
30224
|
+
const engine = context.PXFX;
|
|
30225
|
+
if (!engine || typeof engine.View !== "function" || typeof engine.get !== "function") {
|
|
30226
|
+
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) does not define PXFX.View and PXFX.get`, "capability");
|
|
30227
|
+
}
|
|
30228
|
+
const loadErrors = [];
|
|
30229
|
+
for (const file of readdirSync2(path55.join(root, "fx")).filter((name) => name.endsWith(".js")).sort()) {
|
|
30230
|
+
try {
|
|
30231
|
+
vm.runInContext(read("fx", file), context, { filename: `fx/${file}` });
|
|
30232
|
+
} catch (error) {
|
|
30233
|
+
loadErrors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
30234
|
+
}
|
|
30235
|
+
}
|
|
30236
|
+
const meta = JSON.parse(read("data", "meta.json"));
|
|
30237
|
+
const catalogue = meta.flatMap(
|
|
30238
|
+
(entry) => typeof entry.id === "string" && engine.get(entry.id) ? [{
|
|
30239
|
+
id: entry.id,
|
|
30240
|
+
en: typeof entry.en === "string" ? entry.en : entry.id,
|
|
30241
|
+
descEn: typeof entry.descEn === "string" ? entry.descEn : "",
|
|
30242
|
+
category: typeof entry.category === "string" ? entry.category : "other",
|
|
30243
|
+
schools: Array.isArray(entry.schools) ? entry.schools.filter((school) => typeof school === "string") : []
|
|
30244
|
+
}] : []
|
|
30245
|
+
);
|
|
30246
|
+
if (!catalogue.length) throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) loaded no effects`, "capability");
|
|
30247
|
+
const engineSha256 = createHash8("sha256").update(sources.join("\n")).digest("hex").slice(0, 12);
|
|
30248
|
+
return { version, engineSha256, engine, catalogue, loadErrors };
|
|
30249
|
+
}
|
|
30250
|
+
function listCodexEffects(lib) {
|
|
30251
|
+
return lib.catalogue.map((entry) => {
|
|
30252
|
+
const def = lib.engine.get(entry.id);
|
|
30253
|
+
return {
|
|
30254
|
+
...entry,
|
|
30255
|
+
loopSeconds: def.loop,
|
|
30256
|
+
params: Object.fromEntries(
|
|
30257
|
+
Object.entries(def.params ?? {}).map(([key2, param]) => [key2, { label: param.en ?? key2, min: param.min, max: param.max, value: param.value }])
|
|
30258
|
+
)
|
|
30259
|
+
};
|
|
30260
|
+
});
|
|
30261
|
+
}
|
|
30262
|
+
function formatCodexEffects(lib) {
|
|
30263
|
+
const effects = listCodexEffects(lib);
|
|
30264
|
+
const categories = [...new Set(effects.map((effect) => effect.category))];
|
|
30265
|
+
const lines = [`pixel-vfx-codex ${lib.version}: ${effects.length} effects (${CODEX_REPOSITORY}, MIT)`];
|
|
30266
|
+
for (const category of categories) {
|
|
30267
|
+
const inCategory = effects.filter((effect) => effect.category === category);
|
|
30268
|
+
lines.push("", `${category} (${inCategory.length})`);
|
|
30269
|
+
for (const effect of inCategory) lines.push(` ${effect.id.padEnd(28)} ${effect.en}`);
|
|
30270
|
+
}
|
|
30271
|
+
lines.push("", "--json lists every effect's parameters, with their ranges.");
|
|
30272
|
+
return lines.join("\n");
|
|
30273
|
+
}
|
|
30274
|
+
function findDef(lib, id) {
|
|
30275
|
+
const info = listCodexEffects(lib).find((entry) => entry.id === id);
|
|
30276
|
+
if (!info) {
|
|
30277
|
+
const near = lib.catalogue.map((entry) => entry.id).filter((other) => other.includes(id) || id.includes(other));
|
|
30278
|
+
throw new UsageError(
|
|
30279
|
+
`pixel-vfx-codex ${lib.version} has no effect "${id}"` + (near.length ? `; close: ${near.slice(0, 10).join(", ")}` : ""),
|
|
30280
|
+
{ hint: "List them with: pixelkiln vfx effects --lib codex" }
|
|
30281
|
+
);
|
|
30282
|
+
}
|
|
30283
|
+
return { def: lib.engine.get(id), info };
|
|
30284
|
+
}
|
|
30285
|
+
function checkCodexRecipe(lib, recipe) {
|
|
30286
|
+
const { info } = findDef(lib, recipe.effect);
|
|
30287
|
+
const { camera, fps, margin, hue, params = {}, tune = {} } = recipe;
|
|
30288
|
+
if (camera !== void 0 && !CODEX_CAMERAS.includes(camera)) {
|
|
30289
|
+
throw new UsageError(`--camera must be ${CODEX_CAMERAS.join(", ")}, got "${camera}"`);
|
|
30290
|
+
}
|
|
30291
|
+
if (fps !== void 0 && (!Number.isInteger(fps) || fps < 1 || fps > 60)) throw new UsageError(`codex fps must be a whole number 1 to 60, got ${fps}`);
|
|
30292
|
+
if (margin !== void 0 && (!Number.isInteger(margin) || margin < 0 || margin > 64)) {
|
|
30293
|
+
throw new UsageError(`codex margin must be a whole number 0 to 64, got ${margin}`);
|
|
30294
|
+
}
|
|
30295
|
+
if (hue !== void 0 && (typeof hue !== "number" || !Number.isFinite(hue) || hue < -360 || hue > 360)) {
|
|
30296
|
+
throw new UsageError(`codex hue is degrees from -360 to 360, got ${JSON.stringify(hue)}`);
|
|
30297
|
+
}
|
|
30298
|
+
for (const [key2, value] of Object.entries(params)) {
|
|
30299
|
+
const param = info.params[key2];
|
|
30300
|
+
if (!param) {
|
|
30301
|
+
const known = Object.keys(info.params);
|
|
30302
|
+
throw new UsageError(`${recipe.effect} has no parameter "${key2}"${known.length ? `; it has ${known.join(", ")}` : " (it takes none)"}`);
|
|
30303
|
+
}
|
|
30304
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < param.min || value > param.max) {
|
|
30305
|
+
throw new UsageError(`${recipe.effect} ${key2} is a number from ${param.min} to ${param.max}, got ${JSON.stringify(value)}`);
|
|
30306
|
+
}
|
|
30307
|
+
}
|
|
30308
|
+
for (const [key2, value] of Object.entries(tune)) {
|
|
30309
|
+
if (!CODEX_TUNE_KEYS.includes(key2)) throw new UsageError(`unknown tune knob "${key2}"; they are ${CODEX_TUNE_KEYS.join(", ")}`);
|
|
30310
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new UsageError(`tune ${key2} is a number, got ${JSON.stringify(value)}`);
|
|
30311
|
+
}
|
|
30312
|
+
return info;
|
|
30313
|
+
}
|
|
30314
|
+
function cropFrames(frames, width, height, pivot, margin) {
|
|
30315
|
+
let x0 = Math.floor(pivot.x), x1 = Math.floor(pivot.x), y0 = Math.floor(pivot.y), y1 = Math.floor(pivot.y);
|
|
30316
|
+
x0 = Math.max(0, Math.min(x0, width - 1));
|
|
30317
|
+
x1 = Math.max(0, Math.min(x1, width - 1));
|
|
30318
|
+
y0 = Math.max(0, Math.min(y0, height - 1));
|
|
30319
|
+
y1 = Math.max(0, Math.min(y1, height - 1));
|
|
30320
|
+
for (const frame of frames) {
|
|
30321
|
+
for (let y = 0; y < height; y++) {
|
|
30322
|
+
for (let x = 0; x < width; x++) {
|
|
30323
|
+
if (frame[(y * width + x) * 4 + 3]) {
|
|
30324
|
+
if (x < x0) x0 = x;
|
|
30325
|
+
if (x > x1) x1 = x;
|
|
30326
|
+
if (y < y0) y0 = y;
|
|
30327
|
+
if (y > y1) y1 = y;
|
|
30328
|
+
}
|
|
30329
|
+
}
|
|
30330
|
+
}
|
|
30331
|
+
}
|
|
30332
|
+
const cropWidth = x1 - x0 + 1 + margin * 2;
|
|
30333
|
+
const cropHeight = y1 - y0 + 1 + margin * 2;
|
|
30334
|
+
const cropped = frames.map((frame) => {
|
|
30335
|
+
const out = Buffer.alloc(cropWidth * cropHeight * 4);
|
|
30336
|
+
for (let y = 0; y < cropHeight; y++) {
|
|
30337
|
+
const sy = y0 - margin + y;
|
|
30338
|
+
if (sy < 0 || sy >= height) continue;
|
|
30339
|
+
for (let x = 0; x < cropWidth; x++) {
|
|
30340
|
+
const sx = x0 - margin + x;
|
|
30341
|
+
if (sx < 0 || sx >= width) continue;
|
|
30342
|
+
frame.copy(out, (y * cropWidth + x) * 4, (sy * width + sx) * 4, (sy * width + sx) * 4 + 4);
|
|
30343
|
+
}
|
|
30344
|
+
}
|
|
30345
|
+
return out;
|
|
30346
|
+
});
|
|
30347
|
+
return { width: cropWidth, height: cropHeight, frames: cropped, anchor: { x: pivot.x - x0 + margin, y: pivot.y - y0 + margin } };
|
|
30348
|
+
}
|
|
30349
|
+
function planCodex(lib, recipe) {
|
|
30350
|
+
checkCodexRecipe(lib, recipe);
|
|
30351
|
+
const camera = recipe.camera ?? "2d";
|
|
30352
|
+
const fps = recipe.fps ?? lib.engine.MODES[camera]?.fps ?? 12;
|
|
30353
|
+
const seconds = lib.engine.timing(lib.engine.get(recipe.effect), { ...recipe.tune ?? {} }).length;
|
|
30354
|
+
return { camera, fps, frames: Math.max(1, Math.round(seconds * fps)), seconds };
|
|
30355
|
+
}
|
|
30356
|
+
function renderCodex(lib, recipe) {
|
|
30357
|
+
const info = checkCodexRecipe(lib, recipe);
|
|
30358
|
+
const def = lib.engine.get(recipe.effect);
|
|
30359
|
+
const camera = recipe.camera ?? "2d";
|
|
30360
|
+
const [canvasWidth, canvasHeight] = CANVAS[camera];
|
|
30361
|
+
const fps = recipe.fps ?? lib.engine.MODES[camera]?.fps ?? 12;
|
|
30362
|
+
const view = new lib.engine.View(null, canvasWidth, canvasHeight);
|
|
30363
|
+
view.mode = camera;
|
|
30364
|
+
view.night = false;
|
|
30365
|
+
view.hue = recipe.hue ?? 0;
|
|
30366
|
+
view.params = { ...recipe.params ?? {} };
|
|
30367
|
+
view.tune = { ...recipe.tune ?? {} };
|
|
30368
|
+
view.transparent = true;
|
|
30369
|
+
view.noProps = true;
|
|
30370
|
+
view.shakeX = 0;
|
|
30371
|
+
view.shakeY = 0;
|
|
30372
|
+
view.camera(def);
|
|
30373
|
+
view.P(0, 0, 0);
|
|
30374
|
+
const pivot = { x: Math.round(view.px), y: Math.round(view.py) };
|
|
30375
|
+
const timing = lib.engine.timing(def, view.tune);
|
|
30376
|
+
const count = Math.max(1, Math.round(timing.length * fps));
|
|
30377
|
+
const frames = [];
|
|
30378
|
+
for (let index = 0; index < count; index++) {
|
|
30379
|
+
view.renderAt(def, lib.engine.frameTime(index / count * timing.length, camera), timing);
|
|
30380
|
+
frames.push(Buffer.from(view.pix.buffer.slice(0)));
|
|
30381
|
+
}
|
|
30382
|
+
const cropped = cropFrames(frames, canvasWidth, canvasHeight, pivot, recipe.margin ?? 0);
|
|
30383
|
+
return { effect: info, fps, loop: true, ...cropped };
|
|
30384
|
+
}
|
|
30385
|
+
async function readCodexRecipe(file, opts = {}) {
|
|
30386
|
+
const parsed = JSON.parse(await readFile38(file, "utf8"));
|
|
30387
|
+
const record = parsed.tool === CODEX_ID;
|
|
30388
|
+
if (!record && !(opts.bare && parsed.tool === void 0)) return null;
|
|
30389
|
+
const raw = record ? parsed.recipe : parsed;
|
|
30390
|
+
if (!raw || typeof raw !== "object" || typeof raw.effect !== "string" || Array.isArray(raw.layers)) {
|
|
30391
|
+
if (record) throw new Error(`${file} is a codex record with no recipe naming an effect`);
|
|
30392
|
+
return null;
|
|
30393
|
+
}
|
|
30394
|
+
const recipe = { effect: raw.effect };
|
|
30395
|
+
if (raw.camera !== void 0) recipe.camera = raw.camera;
|
|
30396
|
+
for (const key2 of ["fps", "margin", "hue"]) if (raw[key2] !== void 0) recipe[key2] = raw[key2];
|
|
30397
|
+
for (const key2 of ["params", "tune"]) {
|
|
30398
|
+
const value = raw[key2];
|
|
30399
|
+
if (value === void 0) continue;
|
|
30400
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${file}: a codex recipe's ${key2} is an object`);
|
|
30401
|
+
recipe[key2] = value;
|
|
30402
|
+
}
|
|
30403
|
+
const library = record ? parsed.library : void 0;
|
|
30404
|
+
return {
|
|
30405
|
+
recipe,
|
|
30406
|
+
...typeof library?.version === "string" ? { libraryVersion: library.version } : {},
|
|
30407
|
+
...typeof library?.engineSha256 === "string" ? { engineSha256: library.engineSha256 } : {}
|
|
30408
|
+
};
|
|
30409
|
+
}
|
|
30410
|
+
async function makeCodexVfx(lib, opts) {
|
|
30411
|
+
const recipe = {
|
|
30412
|
+
effect: opts.effect,
|
|
30413
|
+
...opts.camera && opts.camera !== "2d" ? { camera: opts.camera } : {},
|
|
30414
|
+
...opts.fps !== void 0 ? { fps: opts.fps } : {},
|
|
30415
|
+
...opts.margin ? { margin: opts.margin } : {},
|
|
30416
|
+
...opts.hue ? { hue: opts.hue } : {},
|
|
30417
|
+
...opts.params && Object.keys(opts.params).length ? { params: opts.params } : {},
|
|
30418
|
+
...opts.tune && Object.keys(opts.tune).length ? { tune: opts.tune } : {}
|
|
30419
|
+
};
|
|
30420
|
+
checkCodexRecipe(lib, recipe);
|
|
30421
|
+
const paths = assertFreshOutputs(opts.out, opts.force);
|
|
30422
|
+
const render = renderCodex(lib, recipe);
|
|
30423
|
+
const library = { name: CODEX_PACKAGE, version: lib.version, engineSha256: lib.engineSha256 };
|
|
30424
|
+
const written = await writeLocalVfx({
|
|
30425
|
+
paths,
|
|
30426
|
+
name: opts.name ?? render.effect.en,
|
|
30427
|
+
effect: opts.effect,
|
|
30428
|
+
render,
|
|
30429
|
+
atlasKey: CODEX_ID,
|
|
30430
|
+
atlasFacts: { version: lib.version, engineSha256: lib.engineSha256, camera: recipe.camera ?? "2d" },
|
|
30431
|
+
record: { provider: CODEX_ID, tool: CODEX_ID, library: { ...library, repository: CODEX_REPOSITORY, license: "MIT" } },
|
|
30432
|
+
recipe
|
|
30433
|
+
});
|
|
30434
|
+
return {
|
|
30435
|
+
provider: CODEX_ID,
|
|
30436
|
+
library,
|
|
30437
|
+
...written.facts,
|
|
30438
|
+
columns: written.columns,
|
|
30439
|
+
sheetSha256: written.sheetSha256,
|
|
30440
|
+
paths: written.paths,
|
|
30441
|
+
recipe
|
|
30442
|
+
};
|
|
30443
|
+
}
|
|
30444
|
+
|
|
30445
|
+
// src/pixelfx-vfx.ts
|
|
30446
|
+
import { existsSync as existsSync47, readFileSync as readFileSync10 } from "fs";
|
|
30447
|
+
import { readFile as readFile39 } from "fs/promises";
|
|
30448
|
+
import { createRequire as createRequire3 } from "module";
|
|
30449
|
+
import path56 from "path";
|
|
30450
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
29641
30451
|
var PIXELFX_TOOL = "pixelfx";
|
|
29642
30452
|
var PIXELFX_REPOSITORY = "https://github.com/patch-gg/pixelfx";
|
|
29643
30453
|
var PIXELFX_INSTALL = "npm i github:patch-gg/pixelfx";
|
|
@@ -29649,24 +30459,24 @@ function missingPixelfx(cause) {
|
|
|
29649
30459
|
);
|
|
29650
30460
|
}
|
|
29651
30461
|
function pixelfxVersion(entry) {
|
|
29652
|
-
for (let dir =
|
|
29653
|
-
const file =
|
|
29654
|
-
if (!
|
|
29655
|
-
const pkg = JSON.parse(
|
|
30462
|
+
for (let dir = path56.dirname(entry); dir !== path56.dirname(dir); dir = path56.dirname(dir)) {
|
|
30463
|
+
const file = path56.join(dir, "package.json");
|
|
30464
|
+
if (!existsSync47(file)) continue;
|
|
30465
|
+
const pkg = JSON.parse(readFileSync10(file, "utf8"));
|
|
29656
30466
|
if (pkg.name === "pixelfx") return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
29657
30467
|
}
|
|
29658
30468
|
return "unknown";
|
|
29659
30469
|
}
|
|
29660
30470
|
async function loadPixelfx(from) {
|
|
29661
|
-
const bases = from?.map((base) =>
|
|
29662
|
-
|
|
30471
|
+
const bases = from?.map((base) => pathToFileURL2(path56.resolve(base)).href) ?? [
|
|
30472
|
+
pathToFileURL2(path56.join(process.cwd(), "package.json")).href,
|
|
29663
30473
|
import.meta.url
|
|
29664
30474
|
];
|
|
29665
30475
|
let resolved;
|
|
29666
30476
|
let failure;
|
|
29667
30477
|
for (const base of bases) {
|
|
29668
30478
|
try {
|
|
29669
|
-
const require2 =
|
|
30479
|
+
const require2 = createRequire3(base);
|
|
29670
30480
|
resolved = { core: require2.resolve("pixelfx"), index: require2.resolve("pixelfx/fx/index") };
|
|
29671
30481
|
break;
|
|
29672
30482
|
} catch (error) {
|
|
@@ -29674,8 +30484,8 @@ async function loadPixelfx(from) {
|
|
|
29674
30484
|
}
|
|
29675
30485
|
}
|
|
29676
30486
|
if (!resolved) throw missingPixelfx(failure);
|
|
29677
|
-
const core = await import(
|
|
29678
|
-
const index = await import(
|
|
30487
|
+
const core = await import(pathToFileURL2(resolved.core).href);
|
|
30488
|
+
const index = await import(pathToFileURL2(resolved.index).href);
|
|
29679
30489
|
const version = pixelfxVersion(resolved.core);
|
|
29680
30490
|
for (const name of ["createFrame", "clearFrame", "createFx", "composite"]) {
|
|
29681
30491
|
if (typeof core[name] !== "function") {
|
|
@@ -29825,23 +30635,8 @@ function renderPixelfx(lib, recipe) {
|
|
|
29825
30635
|
frames
|
|
29826
30636
|
};
|
|
29827
30637
|
}
|
|
29828
|
-
function pixelfxSheet(render) {
|
|
29829
|
-
const { width, height, frames } = render;
|
|
29830
|
-
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
29831
|
-
const rows = Math.ceil(frames.length / columns);
|
|
29832
|
-
const sheet = Buffer.alloc(columns * width * rows * height * 4);
|
|
29833
|
-
const rects = frames.map((rgba, index) => {
|
|
29834
|
-
const x = index % columns * width;
|
|
29835
|
-
const y = Math.floor(index / columns) * height;
|
|
29836
|
-
for (let row = 0; row < height; row++) {
|
|
29837
|
-
rgba.copy(sheet, ((y + row) * columns * width + x) * 4, row * width * 4, (row + 1) * width * 4);
|
|
29838
|
-
}
|
|
29839
|
-
return { x, y, w: width, h: height };
|
|
29840
|
-
});
|
|
29841
|
-
return { png: encodeRgbaPng(columns * width, rows * height, sheet), columns, rows, rects };
|
|
29842
|
-
}
|
|
29843
30638
|
async function readPixelfxRecipe(file) {
|
|
29844
|
-
const parsed = JSON.parse(await
|
|
30639
|
+
const parsed = JSON.parse(await readFile39(file, "utf8"));
|
|
29845
30640
|
const record = parsed.tool === PIXELFX_TOOL;
|
|
29846
30641
|
const raw = record ? parsed.recipe : parsed;
|
|
29847
30642
|
if (!raw || typeof raw !== "object" || typeof raw.effect !== "string" || Array.isArray(raw.layers)) {
|
|
@@ -29863,7 +30658,6 @@ async function readPixelfxRecipe(file) {
|
|
|
29863
30658
|
return { recipe, ...typeof version === "string" ? { libraryVersion: version } : {} };
|
|
29864
30659
|
}
|
|
29865
30660
|
async function makePixelfxVfx(lib, opts) {
|
|
29866
|
-
const paths = vfxOutputPaths(opts.out);
|
|
29867
30661
|
const recipe = {
|
|
29868
30662
|
effect: opts.effect,
|
|
29869
30663
|
...opts.fps !== void 0 ? { fps: opts.fps } : {},
|
|
@@ -29871,91 +30665,36 @@ async function makePixelfxVfx(lib, opts) {
|
|
|
29871
30665
|
...opts.options && Object.keys(opts.options).length ? { options: opts.options } : {}
|
|
29872
30666
|
};
|
|
29873
30667
|
checkPixelfxRecipe(lib, recipe);
|
|
29874
|
-
|
|
29875
|
-
for (const file of [paths.sheet, paths.atlas, paths.provenance]) {
|
|
29876
|
-
if (existsSync45(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
29877
|
-
}
|
|
29878
|
-
}
|
|
30668
|
+
const paths = assertFreshOutputs(opts.out, opts.force);
|
|
29879
30669
|
const render = renderPixelfx(lib, recipe);
|
|
29880
|
-
const
|
|
29881
|
-
|
|
29882
|
-
|
|
29883
|
-
const anchor = { kind: "origin", ...render.anchor };
|
|
29884
|
-
const size = { w: render.width, h: render.height };
|
|
29885
|
-
const atlas = {
|
|
29886
|
-
frames: sheet.rects.map((frame, index) => ({
|
|
29887
|
-
filename: `${clip} ${index}`,
|
|
29888
|
-
frame,
|
|
29889
|
-
rotated: false,
|
|
29890
|
-
trimmed: false,
|
|
29891
|
-
spriteSourceSize: { x: 0, y: 0, ...size },
|
|
29892
|
-
sourceSize: size,
|
|
29893
|
-
duration: Math.round(1e3 / render.fps)
|
|
29894
|
-
})),
|
|
29895
|
-
meta: {
|
|
29896
|
-
app: "pixelkiln",
|
|
29897
|
-
version: "1",
|
|
29898
|
-
image: path54.basename(paths.sheet),
|
|
29899
|
-
format: "RGBA8888",
|
|
29900
|
-
size: { w: sheet.columns * render.width, h: sheet.rows * render.height },
|
|
29901
|
-
scale: "1",
|
|
29902
|
-
frameTags: [{ name: clip, from: 0, to: render.frames.length - 1, direction: "forward" }],
|
|
29903
|
-
anchor,
|
|
29904
|
-
pixelfx: {
|
|
29905
|
-
id: opts.effect,
|
|
29906
|
-
name,
|
|
29907
|
-
version: lib.version,
|
|
29908
|
-
fps: render.fps,
|
|
29909
|
-
loop: render.loop,
|
|
29910
|
-
frames: render.frames.length,
|
|
29911
|
-
frameSize: [render.width, render.height],
|
|
29912
|
-
pivot: [anchor.x, anchor.y],
|
|
29913
|
-
columns: sheet.columns
|
|
29914
|
-
}
|
|
29915
|
-
}
|
|
29916
|
-
};
|
|
29917
|
-
const sheetSha256 = sha256(sheet.png);
|
|
29918
|
-
const facts = {
|
|
29919
|
-
name,
|
|
30670
|
+
const written = await writeLocalVfx({
|
|
30671
|
+
paths,
|
|
30672
|
+
name: opts.name ?? render.effect.name,
|
|
29920
30673
|
effect: opts.effect,
|
|
29921
|
-
|
|
29922
|
-
|
|
29923
|
-
|
|
29924
|
-
|
|
29925
|
-
|
|
29926
|
-
|
|
29927
|
-
|
|
29928
|
-
|
|
29929
|
-
version: 1,
|
|
29930
|
-
provider: "pixelfx",
|
|
29931
|
-
tool: PIXELFX_TOOL,
|
|
29932
|
-
library: { name: "pixelfx", version: lib.version, repository: PIXELFX_REPOSITORY, license: "MIT" },
|
|
29933
|
-
...facts,
|
|
29934
|
-
files: { sheet: path54.basename(paths.sheet), atlas: path54.basename(paths.atlas) },
|
|
29935
|
-
sheetSha256,
|
|
29936
|
-
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30674
|
+
render,
|
|
30675
|
+
atlasKey: "pixelfx",
|
|
30676
|
+
atlasFacts: { version: lib.version },
|
|
30677
|
+
record: {
|
|
30678
|
+
provider: "pixelfx",
|
|
30679
|
+
tool: PIXELFX_TOOL,
|
|
30680
|
+
library: { name: "pixelfx", version: lib.version, repository: PIXELFX_REPOSITORY, license: "MIT" }
|
|
30681
|
+
},
|
|
29937
30682
|
recipe
|
|
29938
|
-
};
|
|
29939
|
-
await mkdir19(path54.dirname(paths.sheet), { recursive: true });
|
|
29940
|
-
await writeFile24(paths.sheet, sheet.png);
|
|
29941
|
-
await writeFile24(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
29942
|
-
`);
|
|
29943
|
-
await writeFile24(paths.provenance, `${JSON.stringify(provenance, null, 2)}
|
|
29944
|
-
`);
|
|
30683
|
+
});
|
|
29945
30684
|
return {
|
|
29946
30685
|
provider: "pixelfx",
|
|
29947
30686
|
library: { name: "pixelfx", version: lib.version },
|
|
29948
|
-
...facts,
|
|
29949
|
-
columns:
|
|
29950
|
-
sheetSha256,
|
|
29951
|
-
paths:
|
|
30687
|
+
...written.facts,
|
|
30688
|
+
columns: written.columns,
|
|
30689
|
+
sheetSha256: written.sheetSha256,
|
|
30690
|
+
paths: written.paths,
|
|
29952
30691
|
recipe
|
|
29953
30692
|
};
|
|
29954
30693
|
}
|
|
29955
30694
|
|
|
29956
30695
|
// src/cli/commands/pixellab-utils.ts
|
|
29957
30696
|
function loadKeys(args) {
|
|
29958
|
-
loadEnvFiles(
|
|
30697
|
+
loadEnvFiles(path57.dirname(path57.resolve(args.manifest)));
|
|
29959
30698
|
loadEnvFiles(process.cwd());
|
|
29960
30699
|
}
|
|
29961
30700
|
async function runUnzoom(args) {
|
|
@@ -30117,14 +30856,56 @@ async function runNormalMap(args) {
|
|
|
30117
30856
|
}
|
|
30118
30857
|
log(` ${res.width}x${res.height}${res.frames > 1 ? `, ${res.frames} frames` : ""}; wrote ${res.out}`);
|
|
30119
30858
|
}
|
|
30120
|
-
var VFX_LIBS = ["pixellab", "pixelfx"];
|
|
30859
|
+
var VFX_LIBS = ["pixellab", "pixelfx", "codex"];
|
|
30860
|
+
async function readLocalRecipe(file, lib) {
|
|
30861
|
+
const codex = await readCodexRecipe(file, { bare: lib === "codex" });
|
|
30862
|
+
if (codex) {
|
|
30863
|
+
if (lib === "pixelfx") throw new UsageError(`${file} is a record from pixel-vfx-codex; drop --lib pixelfx, or use --lib codex`);
|
|
30864
|
+
return { lib: "codex", read: codex };
|
|
30865
|
+
}
|
|
30866
|
+
if (lib === "codex") return null;
|
|
30867
|
+
const pixelfx = await readPixelfxRecipe(file);
|
|
30868
|
+
if (pixelfx) return { lib: "pixelfx", read: pixelfx };
|
|
30869
|
+
return null;
|
|
30870
|
+
}
|
|
30871
|
+
function pixelfxOnly(args) {
|
|
30872
|
+
return [["--seed", args.seed], ["--palette", args.palette.length ? args.palette : void 0]];
|
|
30873
|
+
}
|
|
30874
|
+
function numberPairs(flag, pairs) {
|
|
30875
|
+
const out = {};
|
|
30876
|
+
for (const pair of pairs) {
|
|
30877
|
+
const [key2, raw, ...rest] = pair.split("=");
|
|
30878
|
+
const value = Number(raw);
|
|
30879
|
+
if (!key2 || raw === void 0 || rest.length || raw.trim() === "" || !Number.isFinite(value)) {
|
|
30880
|
+
throw new UsageError(`${flag} takes name=number, got "${pair}"`);
|
|
30881
|
+
}
|
|
30882
|
+
out[key2] = value;
|
|
30883
|
+
}
|
|
30884
|
+
return out;
|
|
30885
|
+
}
|
|
30121
30886
|
async function runVfx(args) {
|
|
30122
30887
|
if (args.lib !== void 0 && !VFX_LIBS.includes(args.lib)) {
|
|
30123
|
-
throw new UsageError(`--lib must be ${VFX_LIBS.join("
|
|
30124
|
-
}
|
|
30125
|
-
const
|
|
30126
|
-
|
|
30127
|
-
|
|
30888
|
+
throw new UsageError(`--lib must be ${VFX_LIBS.join(", ")}, got "${args.lib}"`);
|
|
30889
|
+
}
|
|
30890
|
+
const pixelfxOnly_ = pixelfxOnly(args);
|
|
30891
|
+
const codexOnly = [
|
|
30892
|
+
["--camera", args.camera],
|
|
30893
|
+
["--hue", args.hue],
|
|
30894
|
+
["--param", args.param.length ? args.param : void 0],
|
|
30895
|
+
["--tune", args.tune.length ? args.tune : void 0]
|
|
30896
|
+
];
|
|
30897
|
+
const listsLocal = args.subcommand === "effects" || (args.lib === "pixelfx" || args.lib === "codex") && args.subcommand === "presets";
|
|
30898
|
+
if (listsLocal) {
|
|
30899
|
+
if (args.lib === "pixellab") throw new UsageError("vfx effects lists a local library's effects; PixelLab's lists are vfx presets and vfx parts");
|
|
30900
|
+
if (args.lib === "codex") {
|
|
30901
|
+
const lib2 = loadCodex();
|
|
30902
|
+
if (args.json) {
|
|
30903
|
+
log(JSON.stringify({ version: 1, library: { name: "pixel-vfx-codex", version: lib2.version, engineSha256: lib2.engineSha256 }, effects: listCodexEffects(lib2) }, null, 2));
|
|
30904
|
+
return;
|
|
30905
|
+
}
|
|
30906
|
+
log(formatCodexEffects(lib2));
|
|
30907
|
+
return;
|
|
30908
|
+
}
|
|
30128
30909
|
const lib = await loadPixelfx();
|
|
30129
30910
|
if (args.json) {
|
|
30130
30911
|
log(JSON.stringify({ version: 1, library: { name: "pixelfx", version: lib.version }, categories: lib.categories, effects: listPixelfxEffects(lib) }, null, 2));
|
|
@@ -30133,15 +30914,17 @@ async function runVfx(args) {
|
|
|
30133
30914
|
log(formatPixelfxEffects(lib));
|
|
30134
30915
|
return;
|
|
30135
30916
|
}
|
|
30136
|
-
if (args.subcommand === "parts" && args.lib === "pixelfx") {
|
|
30137
|
-
throw new UsageError(
|
|
30917
|
+
if (args.subcommand === "parts" && (args.lib === "pixelfx" || args.lib === "codex")) {
|
|
30918
|
+
throw new UsageError(`${args.lib} has no parts: its effects are whole; list them with vfx effects --lib ${args.lib}`);
|
|
30138
30919
|
}
|
|
30139
30920
|
if (args.subcommand === "make") {
|
|
30140
|
-
const
|
|
30141
|
-
|
|
30921
|
+
const local = args.recipe && args.lib !== "pixellab" ? await readLocalRecipe(args.recipe, args.lib) : null;
|
|
30922
|
+
const source = local?.lib ?? (args.lib === "pixelfx" || args.lib === "codex" ? args.lib : null);
|
|
30923
|
+
if (source === "pixelfx") return runPixelfxVfx(args, local?.lib === "pixelfx" ? local.read : null);
|
|
30924
|
+
if (source === "codex") return runCodexVfx(args, local?.lib === "codex" ? local.read : null);
|
|
30142
30925
|
}
|
|
30143
|
-
for (const [flag, value] of
|
|
30144
|
-
if (value !== void 0) throw new UsageError(`vfx takes ${flag} only with --lib pixelfx`);
|
|
30926
|
+
for (const [flag, value] of [...pixelfxOnly_, ...codexOnly, ["--margin", args.margin]]) {
|
|
30927
|
+
if (value !== void 0) throw new UsageError(`vfx takes ${flag} only with --lib pixelfx or --lib codex`);
|
|
30145
30928
|
}
|
|
30146
30929
|
if (args.subcommand === "presets" || args.subcommand === "parts") {
|
|
30147
30930
|
if (args.dryRun) {
|
|
@@ -30167,7 +30950,7 @@ async function runVfx(args) {
|
|
|
30167
30950
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
30168
30951
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
30169
30952
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
30170
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
30953
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path57.basename(paths.sheet, ".png"));
|
|
30171
30954
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
30172
30955
|
log(
|
|
30173
30956
|
` vfx ${name ? `"${name}"` : "(keeping its saved name)"} from ${from}${args.parts.length ? ` + ${args.parts.join(", ")}` : ""}${sprite ? ` around ${sprite}` : ""} \u2192 ${paths.sheet} (+ .gif, .json, .vfx.json${args.gamePack ? ", -game.zip" : ""})`
|
|
@@ -30217,6 +31000,9 @@ async function runPixelfxVfx(args, fromFile) {
|
|
|
30217
31000
|
for (const [flag, value] of pixellabOnly) {
|
|
30218
31001
|
if (value !== void 0) throw new UsageError(`${flag} is for PixelLab's VFX tools; a pixelfx effect takes --effect, --palette, --seed, --fps and --margin`);
|
|
30219
31002
|
}
|
|
31003
|
+
for (const [flag, value] of [["--camera", args.camera], ["--hue", args.hue], ["--param", args.param.length ? args.param : void 0], ["--tune", args.tune.length ? args.tune : void 0]]) {
|
|
31004
|
+
if (value !== void 0) throw new UsageError(`${flag} is for --lib codex; a pixelfx effect takes --effect, --palette, --seed, --fps and --margin`);
|
|
31005
|
+
}
|
|
30220
31006
|
if (args.recipe && !fromFile) throw new UsageError(`${args.recipe} is not a pixelfx recipe: it names no pixelfx effect`);
|
|
30221
31007
|
if (args.recipe && args.effect) throw new UsageError("vfx takes one of --effect or --recipe, not both");
|
|
30222
31008
|
const effect = fromFile?.recipe.effect ?? args.effect;
|
|
@@ -30258,6 +31044,68 @@ async function runPixelfxVfx(args, fromFile) {
|
|
|
30258
31044
|
for (const file of [res.paths.sheet, res.paths.atlas, res.paths.provenance]) log(` wrote ${file}`);
|
|
30259
31045
|
log(` render it again: pixelkiln vfx --recipe ${res.paths.provenance} --out <base>`);
|
|
30260
31046
|
}
|
|
31047
|
+
async function runCodexVfx(args, fromFile) {
|
|
31048
|
+
if (!args.out) throw new UsageError("vfx needs --out <base>: <base>.png, .json, and .vfx.json are written");
|
|
31049
|
+
const refused = [
|
|
31050
|
+
["--preset", args.preset],
|
|
31051
|
+
["--part", args.parts.length ? args.parts : void 0],
|
|
31052
|
+
["--sprite", args.sprite],
|
|
31053
|
+
["--description", args.description],
|
|
31054
|
+
["--artist", args.artist],
|
|
31055
|
+
["--sprite-frames", args.spriteFrames],
|
|
31056
|
+
["--sprite-fps", args.spriteFps],
|
|
31057
|
+
["--game-pack", args.gamePack || void 0]
|
|
31058
|
+
];
|
|
31059
|
+
for (const [flag, value] of refused) {
|
|
31060
|
+
if (value !== void 0) throw new UsageError(`${flag} is for PixelLab's VFX tools; a codex effect takes --effect, --camera, --fps, --margin, --hue, --param and --tune`);
|
|
31061
|
+
}
|
|
31062
|
+
for (const [flag, value] of pixelfxOnly(args)) {
|
|
31063
|
+
if (value !== void 0) throw new UsageError(`${flag} is for --lib pixelfx: codex effects take no seed or palette (they are pure functions of time; recolour with --hue)`);
|
|
31064
|
+
}
|
|
31065
|
+
if (args.recipe && !fromFile) throw new UsageError(`${args.recipe} is not a codex recipe: it names no pixel-vfx-codex effect`);
|
|
31066
|
+
if (args.recipe && args.effect) throw new UsageError("vfx takes one of --effect or --recipe, not both");
|
|
31067
|
+
const effect = fromFile?.recipe.effect ?? args.effect;
|
|
31068
|
+
if (!effect) throw new UsageError("vfx --lib codex needs --effect <id> (vfx effects --lib codex lists them) or --recipe <file>");
|
|
31069
|
+
const params = { ...fromFile?.recipe.params ?? {}, ...numberPairs("--param", args.param) };
|
|
31070
|
+
const tune = { ...fromFile?.recipe.tune ?? {}, ...numberPairs("--tune", args.tune) };
|
|
31071
|
+
const camera = args.camera ?? fromFile?.recipe.camera;
|
|
31072
|
+
if (args.camera !== void 0 && !CODEX_CAMERAS.includes(args.camera)) {
|
|
31073
|
+
throw new UsageError(`--camera must be ${CODEX_CAMERAS.join(", ")}, got "${args.camera}"`);
|
|
31074
|
+
}
|
|
31075
|
+
const recipe = {
|
|
31076
|
+
effect,
|
|
31077
|
+
...camera ? { camera } : {},
|
|
31078
|
+
...(args.fps ?? fromFile?.recipe.fps) !== void 0 ? { fps: args.fps ?? fromFile?.recipe.fps } : {},
|
|
31079
|
+
...(args.margin ?? fromFile?.recipe.margin) !== void 0 ? { margin: args.margin ?? fromFile?.recipe.margin } : {},
|
|
31080
|
+
...(args.hue ?? fromFile?.recipe.hue) !== void 0 ? { hue: args.hue ?? fromFile?.recipe.hue } : {},
|
|
31081
|
+
...Object.keys(params).length ? { params } : {},
|
|
31082
|
+
...Object.keys(tune).length ? { tune } : {}
|
|
31083
|
+
};
|
|
31084
|
+
const lib = loadCodex();
|
|
31085
|
+
const info = checkCodexRecipe(lib, recipe);
|
|
31086
|
+
const plan = planCodex(lib, recipe);
|
|
31087
|
+
const paths = vfxOutputPaths(args.out);
|
|
31088
|
+
log(
|
|
31089
|
+
` vfx "${args.name ?? info.en}" from pixel-vfx-codex ${lib.version} ${effect}${args.recipe ? ` (recipe ${args.recipe})` : ""} \u2192 ${paths.sheet} (+ .json, .vfx.json)`
|
|
31090
|
+
);
|
|
31091
|
+
log(` ${plan.camera} camera, about ${plan.frames} frames @ ${plan.fps} fps over ${plan.seconds.toFixed(1)} s, cropped to the effect; loops`);
|
|
31092
|
+
log(" cost: free; rendered on this machine, nothing sent");
|
|
31093
|
+
if (fromFile?.engineSha256 && fromFile.engineSha256 !== lib.engineSha256) {
|
|
31094
|
+
log(` note: the record was rendered with engine ${fromFile.engineSha256}; this install is ${lib.engineSha256}, so it may draw the effect differently`);
|
|
31095
|
+
}
|
|
31096
|
+
if (args.dryRun) {
|
|
31097
|
+
log(" dry run: nothing written");
|
|
31098
|
+
return;
|
|
31099
|
+
}
|
|
31100
|
+
const res = await makeCodexVfx(lib, { ...recipe, out: args.out, name: args.name, force: args.force });
|
|
31101
|
+
if (args.json) {
|
|
31102
|
+
log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
31103
|
+
return;
|
|
31104
|
+
}
|
|
31105
|
+
log(` ${res.width}x${res.height}, ${res.frames} frames @ ${res.fps} fps`);
|
|
31106
|
+
for (const file of [res.paths.sheet, res.paths.atlas, res.paths.provenance]) log(` wrote ${file}`);
|
|
31107
|
+
log(` render it again: pixelkiln vfx --recipe ${res.paths.provenance} --out <base>`);
|
|
31108
|
+
}
|
|
30261
31109
|
async function runVfxArtist(args, out) {
|
|
30262
31110
|
const description = args.description.trim();
|
|
30263
31111
|
if (!description) throw new UsageError('vfx --description needs the effect in words, e.g. "a blue lightning strike that leaves sparks"');
|
|
@@ -30284,7 +31132,7 @@ async function runVfxArtist(args, out) {
|
|
|
30284
31132
|
if ((args.spriteFrames !== void 0 || args.spriteFps !== void 0) && !args.sprite) {
|
|
30285
31133
|
throw new UsageError("--sprite-frames and --sprite-fps describe a --sprite; add one");
|
|
30286
31134
|
}
|
|
30287
|
-
const taken = args.sprite ? vfxArtistSprite(await
|
|
31135
|
+
const taken = args.sprite ? vfxArtistSprite(await readFile40(args.sprite), args.sprite, args.spriteFrames ?? 1) : void 0;
|
|
30288
31136
|
if (args.spriteFps !== void 0 && !taken?.animated) {
|
|
30289
31137
|
throw new UsageError("--sprite-fps is the speed of an animated sprite: a GIF, or a PNG strip with --sprite-frames 2 or more");
|
|
30290
31138
|
}
|
|
@@ -30297,7 +31145,7 @@ async function runVfxArtist(args, out) {
|
|
|
30297
31145
|
);
|
|
30298
31146
|
if (args.effect) {
|
|
30299
31147
|
log(
|
|
30300
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
31148
|
+
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${path57.basename(paths.provenance)})` : `; ${path57.basename(paths.provenance)} holds no conversation for it, so PixelLab prices it as a new effect`)
|
|
30301
31149
|
);
|
|
30302
31150
|
}
|
|
30303
31151
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -30347,13 +31195,13 @@ async function runVfxArtist(args, out) {
|
|
|
30347
31195
|
}
|
|
30348
31196
|
|
|
30349
31197
|
// src/cli/commands/audio.ts
|
|
30350
|
-
import { readFile as
|
|
30351
|
-
import
|
|
31198
|
+
import { readFile as readFile41 } from "fs/promises";
|
|
31199
|
+
import path59 from "path";
|
|
30352
31200
|
|
|
30353
31201
|
// src/pixellab-audio.ts
|
|
30354
|
-
import { existsSync as
|
|
31202
|
+
import { existsSync as existsSync48 } from "fs";
|
|
30355
31203
|
import { mkdir as mkdir20, writeFile as writeFile25 } from "fs/promises";
|
|
30356
|
-
import
|
|
31204
|
+
import path58 from "path";
|
|
30357
31205
|
var MUSIC_COST_GENERATIONS = 10;
|
|
30358
31206
|
var MUSIC_LOOP_COST_GENERATIONS = 4;
|
|
30359
31207
|
var MUSIC_LOOP_MIN_BODY_SECONDS = 36;
|
|
@@ -30410,7 +31258,7 @@ async function billedUsage(client2, jobId) {
|
|
|
30410
31258
|
}
|
|
30411
31259
|
}
|
|
30412
31260
|
function musicOutputPaths(out) {
|
|
30413
|
-
const base =
|
|
31261
|
+
const base = path58.resolve(out.replace(/\.(music\.json|mp3)$/i, ""));
|
|
30414
31262
|
return {
|
|
30415
31263
|
takes: [`${base}.mp3`, `${base}.take2.mp3`],
|
|
30416
31264
|
loops: [`${base}.loop.mp3`, `${base}.loop.take2.mp3`],
|
|
@@ -30432,7 +31280,7 @@ async function collectTakes(client2, songs, files, what, opts) {
|
|
|
30432
31280
|
if (!song.audio_url) throw new Error(`PixelLab ${what} ${song.id} completed without an audio URL`);
|
|
30433
31281
|
const bytes = await client2.download(song.audio_url);
|
|
30434
31282
|
validateAudio(bytes, "mp3");
|
|
30435
|
-
await mkdir20(
|
|
31283
|
+
await mkdir20(path58.dirname(file), { recursive: true });
|
|
30436
31284
|
await writeFile25(file, bytes);
|
|
30437
31285
|
finished.push(song);
|
|
30438
31286
|
takes.push({
|
|
@@ -30460,7 +31308,7 @@ async function generateMusic(client2, opts) {
|
|
|
30460
31308
|
}
|
|
30461
31309
|
const writes = [paths.record, ...opts.loopOf ? [] : paths.takes, ...wantsLoop ? paths.loops : []];
|
|
30462
31310
|
if (!opts.force) {
|
|
30463
|
-
for (const file of writes) if (
|
|
31311
|
+
for (const file of writes) if (existsSync48(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
30464
31312
|
}
|
|
30465
31313
|
const usage2 = [];
|
|
30466
31314
|
let quoted = null;
|
|
@@ -30498,9 +31346,9 @@ async function generateMusic(client2, opts) {
|
|
|
30498
31346
|
quotedGenerations: quoted,
|
|
30499
31347
|
usage: usage2
|
|
30500
31348
|
});
|
|
30501
|
-
const relative = (take) => ({ ...take, file:
|
|
31349
|
+
const relative = (take) => ({ ...take, file: path58.basename(take.file) });
|
|
30502
31350
|
const writeRecord = async (result2) => {
|
|
30503
|
-
await mkdir20(
|
|
31351
|
+
await mkdir20(path58.dirname(paths.record), { recursive: true });
|
|
30504
31352
|
await writeFile25(
|
|
30505
31353
|
paths.record,
|
|
30506
31354
|
JSON.stringify(
|
|
@@ -30541,7 +31389,7 @@ async function generateMusic(client2, opts) {
|
|
|
30541
31389
|
submitted = await client2.loopMusic(loopSource);
|
|
30542
31390
|
} catch (error) {
|
|
30543
31391
|
const detail = refusalDetail(error);
|
|
30544
|
-
const kept = takes.length ? ` The song's takes are saved (${
|
|
31392
|
+
const kept = takes.length ? ` The song's takes are saved (${path58.basename(paths.record)}); nothing was charged for the loop.` : "";
|
|
30545
31393
|
throw new Error(`PixelLab refused to loop ${loopSource}: ${detail ?? (error instanceof Error ? error.message : String(error))}${kept}`, { cause: error });
|
|
30546
31394
|
}
|
|
30547
31395
|
quoted = (quoted ?? 0) + (submitted.quoted_generations ?? 0);
|
|
@@ -30555,13 +31403,13 @@ async function generateMusic(client2, opts) {
|
|
|
30555
31403
|
return result;
|
|
30556
31404
|
}
|
|
30557
31405
|
function soundEffectOutputPaths(out) {
|
|
30558
|
-
const base =
|
|
31406
|
+
const base = path58.resolve(out.replace(/\.(sfx\.json|wav)$/i, ""));
|
|
30559
31407
|
return { wav: `${base}.wav`, record: `${base}.sfx.json` };
|
|
30560
31408
|
}
|
|
30561
31409
|
async function generateSoundEffect(client2, opts) {
|
|
30562
31410
|
const { wav, record } = soundEffectOutputPaths(opts.out);
|
|
30563
31411
|
if (!opts.force) {
|
|
30564
|
-
for (const file of [wav, record]) if (
|
|
31412
|
+
for (const file of [wav, record]) if (existsSync48(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
30565
31413
|
}
|
|
30566
31414
|
const seconds = opts.seconds ?? 2;
|
|
30567
31415
|
const submitted = await client2.createSoundEffect({ prompt: opts.prompt, seconds, name: opts.name });
|
|
@@ -30570,7 +31418,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
30570
31418
|
if (!clip.audio_url) throw new Error(`PixelLab sound effect ${id} completed without an audio URL`);
|
|
30571
31419
|
const bytes = await client2.download(clip.audio_url);
|
|
30572
31420
|
validateAudio(bytes, "wav");
|
|
30573
|
-
await mkdir20(
|
|
31421
|
+
await mkdir20(path58.dirname(wav), { recursive: true });
|
|
30574
31422
|
await writeFile25(wav, bytes);
|
|
30575
31423
|
const result = {
|
|
30576
31424
|
soundEffectId: id,
|
|
@@ -30593,7 +31441,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
30593
31441
|
prompt: opts.prompt,
|
|
30594
31442
|
seconds,
|
|
30595
31443
|
soundEffectId: id,
|
|
30596
|
-
file:
|
|
31444
|
+
file: path58.basename(wav),
|
|
30597
31445
|
sha256: result.sha256,
|
|
30598
31446
|
durationMs: result.durationMs,
|
|
30599
31447
|
quotedGenerations: result.quotedGenerations,
|
|
@@ -30608,7 +31456,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
30608
31456
|
|
|
30609
31457
|
// src/cli/commands/audio.ts
|
|
30610
31458
|
function loadKeys2(args) {
|
|
30611
|
-
loadEnvFiles(
|
|
31459
|
+
loadEnvFiles(path59.dirname(path59.resolve(args.manifest)));
|
|
30612
31460
|
loadEnvFiles(process.cwd());
|
|
30613
31461
|
}
|
|
30614
31462
|
function progress() {
|
|
@@ -30665,7 +31513,7 @@ async function runMusic(args) {
|
|
|
30665
31513
|
const cost = musicCost({ loop: args.loop, loopOf: args.loopOf });
|
|
30666
31514
|
const paths = musicOutputPaths(args.out);
|
|
30667
31515
|
const what = args.loopOf ? `loop of ${args.loopOf} (two loop takes)` : `"${args.description}"${vocals ? ", with vocals" : ", instrumental"}, two takes${args.loop ? " plus loops of take 1" : ""}`;
|
|
30668
|
-
log(` music: ${what} \u2192 ${
|
|
31516
|
+
log(` music: ${what} \u2192 ${path59.relative(process.cwd(), args.loopOf ? paths.loops[0] : paths.takes[0])} \u2026`);
|
|
30669
31517
|
log(` cost: ${cost} generations (PixelLab's published price)${args.improve ? ", plus about 0.05 for --improve" : ""}`);
|
|
30670
31518
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
30671
31519
|
throw new Error(`--budget ${args.budget} is below this run's ${cost}-generation cost`);
|
|
@@ -30682,7 +31530,7 @@ async function runMusic(args) {
|
|
|
30682
31530
|
style = (await client2.improveMusicStyle({ style, instrumental: !vocals, bpm: args.bpm })).style;
|
|
30683
31531
|
log(` style: ${style}`);
|
|
30684
31532
|
}
|
|
30685
|
-
const lyrics = args.lyrics ? await
|
|
31533
|
+
const lyrics = args.lyrics ? await readFile41(path59.resolve(args.lyrics), "utf8") : void 0;
|
|
30686
31534
|
const res = await generateMusic(client2, {
|
|
30687
31535
|
style,
|
|
30688
31536
|
lyrics,
|
|
@@ -30718,7 +31566,7 @@ async function runSfx(args) {
|
|
|
30718
31566
|
const seconds = args.seconds ?? 2;
|
|
30719
31567
|
const cost = soundEffectCost(seconds);
|
|
30720
31568
|
const { wav } = soundEffectOutputPaths(args.out);
|
|
30721
|
-
log(` sfx: "${args.description}", ${seconds} s \u2192 ${
|
|
31569
|
+
log(` sfx: "${args.description}", ${seconds} s \u2192 ${path59.relative(process.cwd(), wav)}`);
|
|
30722
31570
|
log(` cost: ${cost} generation${cost === 1 ? "" : "s"} (PixelLab's published price, by length)`);
|
|
30723
31571
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
30724
31572
|
throw new Error(`--budget ${args.budget} is below this clip's ${cost}-generation cost`);
|
|
@@ -30746,12 +31594,12 @@ async function runSfx(args) {
|
|
|
30746
31594
|
}
|
|
30747
31595
|
|
|
30748
31596
|
// src/cli/commands/ui.ts
|
|
30749
|
-
import
|
|
31597
|
+
import path61 from "path";
|
|
30750
31598
|
|
|
30751
31599
|
// src/pixellab-ui.ts
|
|
30752
|
-
import { existsSync as
|
|
31600
|
+
import { existsSync as existsSync49 } from "fs";
|
|
30753
31601
|
import { mkdir as mkdir21, writeFile as writeFile26 } from "fs/promises";
|
|
30754
|
-
import
|
|
31602
|
+
import path60 from "path";
|
|
30755
31603
|
var UI_STATES_COSTS = [10, 15, 25];
|
|
30756
31604
|
var UI_STATES_MAX_COST = 25;
|
|
30757
31605
|
var UI_STATES_MAX_ELEMENTS = 64;
|
|
@@ -30844,8 +31692,8 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
30844
31692
|
const asset = await client2.getUiAssetDetail(uiAssetId);
|
|
30845
31693
|
if (asset.status && asset.status !== "completed") throw new Error(`UI asset ${uiAssetId} is ${asset.status}; pull it once it is completed`);
|
|
30846
31694
|
if (!asset.image_url) throw new Error(`UI asset ${uiAssetId} has no image yet`);
|
|
30847
|
-
const dir =
|
|
30848
|
-
const record =
|
|
31695
|
+
const dir = path60.resolve(opts.out);
|
|
31696
|
+
const record = path60.join(dir, "ui.json");
|
|
30849
31697
|
const plan = [];
|
|
30850
31698
|
const insets = (part) => part.nine_slice ? { nineSlice: { left: part.nine_slice.left, right: part.nine_slice.right, top: part.nine_slice.top, bottom: part.nine_slice.bottom } } : {};
|
|
30851
31699
|
const taken = /* @__PURE__ */ new Set();
|
|
@@ -30893,16 +31741,16 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
30893
31741
|
}
|
|
30894
31742
|
if (kind === "element") addStates(asset, rootName, asset.states);
|
|
30895
31743
|
if (!opts.force) {
|
|
30896
|
-
for (const file of [record, ...plan.map((item) =>
|
|
30897
|
-
if (
|
|
31744
|
+
for (const file of [record, ...plan.map((item) => path60.join(dir, item.file))]) {
|
|
31745
|
+
if (existsSync49(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
30898
31746
|
}
|
|
30899
31747
|
}
|
|
30900
31748
|
const files = [];
|
|
30901
31749
|
for (const { url, ...item } of plan) {
|
|
30902
31750
|
const bytes = await client2.download(url);
|
|
30903
31751
|
validateMedia(bytes, MediaType.PNG);
|
|
30904
|
-
const target =
|
|
30905
|
-
await mkdir21(
|
|
31752
|
+
const target = path60.join(dir, item.file);
|
|
31753
|
+
await mkdir21(path60.dirname(target), { recursive: true });
|
|
30906
31754
|
await writeFile26(target, bytes);
|
|
30907
31755
|
files.push({ ...item, sha256: sha256(bytes) });
|
|
30908
31756
|
}
|
|
@@ -30928,7 +31776,7 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
30928
31776
|
|
|
30929
31777
|
// src/cli/commands/ui.ts
|
|
30930
31778
|
function loadKeys3(args) {
|
|
30931
|
-
loadEnvFiles(
|
|
31779
|
+
loadEnvFiles(path61.dirname(path61.resolve(args.manifest)));
|
|
30932
31780
|
loadEnvFiles(process.cwd());
|
|
30933
31781
|
}
|
|
30934
31782
|
function requireId(args) {
|
|
@@ -31042,18 +31890,18 @@ async function runUi(args) {
|
|
|
31042
31890
|
log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
31043
31891
|
return;
|
|
31044
31892
|
}
|
|
31045
|
-
for (const file of res.files) log(` wrote ${
|
|
31046
|
-
log(` wrote ${
|
|
31893
|
+
for (const file of res.files) log(` wrote ${path61.join(args.out, file.file)} (${file.kind}, ${file.size.width}x${file.size.height})`);
|
|
31894
|
+
log(` wrote ${path61.join(args.out, "ui.json")}`);
|
|
31047
31895
|
}
|
|
31048
31896
|
|
|
31049
31897
|
// src/cli/commands/asset.ts
|
|
31050
|
-
import { readFile as
|
|
31051
|
-
import
|
|
31898
|
+
import { readFile as readFile43 } from "fs/promises";
|
|
31899
|
+
import path63 from "path";
|
|
31052
31900
|
|
|
31053
31901
|
// src/pixellab-assets.ts
|
|
31054
|
-
import { existsSync as
|
|
31055
|
-
import { mkdir as mkdir22, readdir as readdir5, readFile as
|
|
31056
|
-
import
|
|
31902
|
+
import { existsSync as existsSync50 } from "fs";
|
|
31903
|
+
import { mkdir as mkdir22, readdir as readdir5, readFile as readFile42, stat as stat6, writeFile as writeFile27 } from "fs/promises";
|
|
31904
|
+
import path62 from "path";
|
|
31057
31905
|
var ASSET_KINDS = ["object", "character"];
|
|
31058
31906
|
var EXPORT_FORMATS = ["zip", "spritesheet", "aseprite", "gif"];
|
|
31059
31907
|
var MIRROR_DIRECTIONS = ["east", "west", "south-east", "south-west", "north-east", "north-west"];
|
|
@@ -31073,7 +31921,7 @@ function parseCanvasSize(text, kind) {
|
|
|
31073
31921
|
}
|
|
31074
31922
|
function exportOutPath(out, format) {
|
|
31075
31923
|
const extension = format === "aseprite" ? ".aseprite" : format === "gif" ? ".gif" : ".zip";
|
|
31076
|
-
return
|
|
31924
|
+
return path62.extname(out) ? path62.resolve(out) : path62.resolve(`${out}${extension}`);
|
|
31077
31925
|
}
|
|
31078
31926
|
function checkExportBytes(bytes, format) {
|
|
31079
31927
|
const ok = format === "gif" ? bytes.subarray(0, 4).toString("ascii") === "GIF8" : format === "aseprite" ? bytes.length > 6 && bytes.readUInt16LE(4) === 42464 : bytes.subarray(0, 2).toString("ascii") === "PK";
|
|
@@ -31081,15 +31929,15 @@ function checkExportBytes(bytes, format) {
|
|
|
31081
31929
|
}
|
|
31082
31930
|
async function exportAssetFile(client2, kind, id, format, opts) {
|
|
31083
31931
|
const out = exportOutPath(opts.out, format);
|
|
31084
|
-
if (
|
|
31932
|
+
if (existsSync50(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
31085
31933
|
const bytes = await client2.exportAsset(kind, id, format, { animationGroupId: opts.animationGroupId, direction: opts.direction });
|
|
31086
31934
|
checkExportBytes(bytes, format);
|
|
31087
|
-
await mkdir22(
|
|
31935
|
+
await mkdir22(path62.dirname(out), { recursive: true });
|
|
31088
31936
|
await writeFile27(out, bytes);
|
|
31089
31937
|
return { out, bytes: bytes.length };
|
|
31090
31938
|
}
|
|
31091
31939
|
async function importObjectFile(client2, file, opts = {}) {
|
|
31092
|
-
const bytes = await
|
|
31940
|
+
const bytes = await readFile42(file);
|
|
31093
31941
|
const metadata = imageMetadata(bytes);
|
|
31094
31942
|
if (!metadata || metadata.format !== "png") throw new Error(`${file} is not a PNG; PixelLab imports PNG only (JPEG compression would be stored as pixels)`);
|
|
31095
31943
|
if (metadata.width > IMPORT_MAX_SIDE || metadata.height > IMPORT_MAX_SIDE) {
|
|
@@ -31131,11 +31979,11 @@ async function pullExpansionReview(client2, id, opts) {
|
|
|
31131
31979
|
if (object.status !== "review-expansion" || !review?.rotation_urls) {
|
|
31132
31980
|
throw new Error(`object ${id} is ${object.status ?? "unknown"}; there is no expansion waiting for review`);
|
|
31133
31981
|
}
|
|
31134
|
-
const dir =
|
|
31982
|
+
const dir = path62.resolve(opts.out);
|
|
31135
31983
|
const entries = Object.entries(review.rotation_urls).filter((entry) => typeof entry[1] === "string");
|
|
31136
|
-
const files = entries.map(([direction]) => ({ direction, file:
|
|
31984
|
+
const files = entries.map(([direction]) => ({ direction, file: path62.join(dir, `${direction}.png`) }));
|
|
31137
31985
|
if (!opts.force) {
|
|
31138
|
-
for (const { file } of files) if (
|
|
31986
|
+
for (const { file } of files) if (existsSync50(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
31139
31987
|
}
|
|
31140
31988
|
await mkdir22(dir, { recursive: true });
|
|
31141
31989
|
for (const [index, [, url]] of entries.entries()) {
|
|
@@ -31182,7 +32030,7 @@ function readPng(bytes, file) {
|
|
|
31182
32030
|
return metadata;
|
|
31183
32031
|
}
|
|
31184
32032
|
async function importTilesetFile(client2, file, opts = {}) {
|
|
31185
|
-
const bytes = await
|
|
32033
|
+
const bytes = await readFile42(file);
|
|
31186
32034
|
const { width, height } = readPng(bytes, file);
|
|
31187
32035
|
const reading = chooseTilesetSheetReading(file, width, height, opts.tileSize);
|
|
31188
32036
|
const mode2 = opts.mode ?? "topdown";
|
|
@@ -31200,11 +32048,11 @@ async function importTilesetFile(client2, file, opts = {}) {
|
|
|
31200
32048
|
return { tilesetId: res.tileset_id, mode: mode2, tileSize: reading.tileSize, layout: reading.layout };
|
|
31201
32049
|
}
|
|
31202
32050
|
async function pngFilesAt(from) {
|
|
31203
|
-
if (!
|
|
32051
|
+
if (!existsSync50(from)) throw new Error(`${from} does not exist`);
|
|
31204
32052
|
if (!(await stat6(from)).isDirectory()) return [from];
|
|
31205
32053
|
const names = (await readdir5(from)).filter((name) => /\.png$/i.test(name)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
31206
32054
|
if (names.length === 0) throw new Error(`${from} holds no PNG files`);
|
|
31207
|
-
return names.map((name) =>
|
|
32055
|
+
return names.map((name) => path62.join(from, name));
|
|
31208
32056
|
}
|
|
31209
32057
|
function importTileHeights(tileType, tileSize) {
|
|
31210
32058
|
if (tileType === "square_topdown" || tileType === "octagon") return { min: tileSize, max: tileSize };
|
|
@@ -31219,7 +32067,7 @@ async function importTilesFiles(client2, from, opts) {
|
|
|
31219
32067
|
const heights = importTileHeights(opts.tileType, opts.tileSize);
|
|
31220
32068
|
const frames = [];
|
|
31221
32069
|
for (const file of files) {
|
|
31222
|
-
const bytes = await
|
|
32070
|
+
const bytes = await readFile42(file);
|
|
31223
32071
|
const { width, height } = readPng(bytes, file);
|
|
31224
32072
|
if (width !== opts.tileSize || height < heights.min || height > heights.max) {
|
|
31225
32073
|
const tall = heights.min === heights.max ? `${heights.min}` : `${heights.min} to ${heights.max}`;
|
|
@@ -31239,13 +32087,13 @@ function checkSaveTarget(target) {
|
|
|
31239
32087
|
}
|
|
31240
32088
|
function saveUndoDir(target, now = /* @__PURE__ */ new Date()) {
|
|
31241
32089
|
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
31242
|
-
return
|
|
32090
|
+
return path62.resolve("pixelkiln-undo", `${target.replace(/[^a-zA-Z0-9-]+/g, "_")}-${stamp}`);
|
|
31243
32091
|
}
|
|
31244
32092
|
async function writeUndo(frames, dir) {
|
|
31245
32093
|
await mkdir22(dir, { recursive: true });
|
|
31246
32094
|
const files = [];
|
|
31247
32095
|
for (const [index, frame] of frames.entries()) {
|
|
31248
|
-
const file =
|
|
32096
|
+
const file = path62.join(dir, frames.length === 1 ? "previous.png" : `previous-${String(index).padStart(2, "0")}.png`);
|
|
31249
32097
|
await writeFile27(file, Buffer.from(frame.base64, "base64"));
|
|
31250
32098
|
files.push(file);
|
|
31251
32099
|
}
|
|
@@ -31255,13 +32103,13 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
31255
32103
|
checkSaveTarget(target);
|
|
31256
32104
|
if ((opts.name || opts.description) && target !== "gallery:new") throw new Error("a name and a description belong to a new gallery image: --target gallery:new");
|
|
31257
32105
|
const files = await pngFilesAt(from).catch(async (error) => {
|
|
31258
|
-
if (
|
|
32106
|
+
if (existsSync50(from) && /\.gif$/i.test(from)) return [from];
|
|
31259
32107
|
throw error;
|
|
31260
32108
|
});
|
|
31261
32109
|
let image;
|
|
31262
32110
|
let frames;
|
|
31263
32111
|
if (files.length === 1) {
|
|
31264
|
-
const bytes = await
|
|
32112
|
+
const bytes = await readFile42(files[0]);
|
|
31265
32113
|
const gif = bytes.subarray(0, 4).toString("ascii") === "GIF8";
|
|
31266
32114
|
if (!gif) readPng(bytes, files[0]);
|
|
31267
32115
|
image = { base64: bytes.toString("base64"), format: gif ? "gif" : "png" };
|
|
@@ -31270,14 +32118,14 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
31270
32118
|
let size;
|
|
31271
32119
|
frames = [];
|
|
31272
32120
|
for (const file of files) {
|
|
31273
|
-
const bytes = await
|
|
32121
|
+
const bytes = await readFile42(file);
|
|
31274
32122
|
const { width, height } = readPng(bytes, file);
|
|
31275
32123
|
if (size && size !== `${width}x${height}`) throw new Error(`${file} is ${width}x${height}, but the frames before it are ${size}; an animation's frames share one size`);
|
|
31276
32124
|
size = `${width}x${height}`;
|
|
31277
32125
|
frames.push({ base64: bytes.toString("base64"), format: "png" });
|
|
31278
32126
|
}
|
|
31279
32127
|
}
|
|
31280
|
-
const undoDir = opts.undoDir ?
|
|
32128
|
+
const undoDir = opts.undoDir ? path62.resolve(opts.undoDir) : saveUndoDir(target);
|
|
31281
32129
|
let res;
|
|
31282
32130
|
try {
|
|
31283
32131
|
res = await client2.saveToAsset({ target, image, frames, name: opts.name, description: opts.description });
|
|
@@ -31313,7 +32161,7 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
31313
32161
|
|
|
31314
32162
|
// src/cli/commands/asset.ts
|
|
31315
32163
|
function loadKeys4(args) {
|
|
31316
|
-
loadEnvFiles(
|
|
32164
|
+
loadEnvFiles(path63.dirname(path63.resolve(args.manifest)));
|
|
31317
32165
|
loadEnvFiles(process.cwd());
|
|
31318
32166
|
}
|
|
31319
32167
|
function kindOf(args) {
|
|
@@ -31434,7 +32282,7 @@ async function runAsset(args) {
|
|
|
31434
32282
|
const res2 = await pullExpansionReview(clientFromEnv(), id, { out: args.out, force: args.force });
|
|
31435
32283
|
if (args.json) emit(res2);
|
|
31436
32284
|
else {
|
|
31437
|
-
for (const file of res2.files) log(` wrote ${
|
|
32285
|
+
for (const file of res2.files) log(` wrote ${path63.join(args.out, `${file.direction}.png`)}${file.direction === res2.existingDirection ? " (your image, unchanged)" : ""}`);
|
|
31438
32286
|
log(` keep them: pixelkiln asset expand --id ${id} --keep discard: pixelkiln asset expand --id ${id} --discard`);
|
|
31439
32287
|
}
|
|
31440
32288
|
return;
|
|
@@ -31479,7 +32327,7 @@ async function runTileImport(args, emit) {
|
|
|
31479
32327
|
if (args.tileType) throw new UsageError("--tile-type belongs to --kind tiles; a tileset is a Wang sheet");
|
|
31480
32328
|
const opts2 = { mode: mode2, tileSize, lowerDescription: args.lower, upperDescription: args.upper, transitionDescription: args.transition, name: args.name };
|
|
31481
32329
|
if (args.dryRun) {
|
|
31482
|
-
const metadata = imageMetadata(await
|
|
32330
|
+
const metadata = imageMetadata(await readFile43(args.from));
|
|
31483
32331
|
if (!metadata || metadata.format !== "png") throw new UsageError(`${args.from} is not a PNG`);
|
|
31484
32332
|
const reading = await usage(() => chooseTilesetSheetReading(args.from, metadata.width, metadata.height, tileSize));
|
|
31485
32333
|
log(` would import ${args.from} as a ${mode2} tileset of ${reading.tileSize}px tiles (${reading.layout === "compact" ? "4 wide" : "8 wide"}); nothing sent`);
|
|
@@ -31518,7 +32366,7 @@ async function runSave(args, emit) {
|
|
|
31518
32366
|
if (!args.from) throw new UsageError("asset save needs --from: a PNG, an animated GIF, or a directory of PNG frames");
|
|
31519
32367
|
await usage(() => checkSaveTarget(target));
|
|
31520
32368
|
const adding = target === "gallery:new";
|
|
31521
|
-
const undoDir = args.out ?
|
|
32369
|
+
const undoDir = args.out ? path63.resolve(args.out) : saveUndoDir(target);
|
|
31522
32370
|
if (adding) log(` add ${args.from} to your PixelLab gallery as a new image (free)`);
|
|
31523
32371
|
else {
|
|
31524
32372
|
log(` save ${args.from} over ${target} on PixelLab (free)`);
|
|
@@ -31541,21 +32389,21 @@ async function runSave(args, emit) {
|
|
|
31541
32389
|
else {
|
|
31542
32390
|
log(` ${res.target}: ${res.kind} saved, ${res.width}x${res.height}, ${res.frames} frame(s), ${res.changedPixels} pixel(s) changed`);
|
|
31543
32391
|
for (const file of res.undo) log(` kept the old pixels: ${file}`);
|
|
31544
|
-
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] :
|
|
32392
|
+
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] : path63.dirname(res.undo[0])} --yes`);
|
|
31545
32393
|
}
|
|
31546
32394
|
if (res.note) log(` ${res.note}`);
|
|
31547
32395
|
if (res.maps) log(` ${res.maps}`);
|
|
31548
32396
|
}
|
|
31549
32397
|
|
|
31550
32398
|
// src/cli/commands/talk.ts
|
|
31551
|
-
import { existsSync as
|
|
31552
|
-
import { mkdir as mkdir24, readFile as
|
|
31553
|
-
import
|
|
32399
|
+
import { existsSync as existsSync52 } from "fs";
|
|
32400
|
+
import { mkdir as mkdir24, readFile as readFile45, writeFile as writeFile29 } from "fs/promises";
|
|
32401
|
+
import path65 from "path";
|
|
31554
32402
|
|
|
31555
32403
|
// src/pixellab-talk.ts
|
|
31556
|
-
import { existsSync as
|
|
31557
|
-
import { mkdir as mkdir23, readFile as
|
|
31558
|
-
import
|
|
32404
|
+
import { existsSync as existsSync51 } from "fs";
|
|
32405
|
+
import { mkdir as mkdir23, readFile as readFile44, writeFile as writeFile28 } from "fs/promises";
|
|
32406
|
+
import path64 from "path";
|
|
31559
32407
|
var TALK_MOODS = ["neutral", "happy", "angry", "sad", "surprised"];
|
|
31560
32408
|
var VISEME_COUNTS = [3, 5, 7, 12];
|
|
31561
32409
|
var VISEME_ENGINES = ["v3", "pixminimax"];
|
|
@@ -31566,7 +32414,7 @@ function visemeCost(engine, side, count) {
|
|
|
31566
32414
|
return Math.ceil(forSeven * count / 7);
|
|
31567
32415
|
}
|
|
31568
32416
|
function talkOutputPaths(out) {
|
|
31569
|
-
const base =
|
|
32417
|
+
const base = path64.resolve(out.replace(/\.(png|json)$/i, "").replace(/\.(talk|visemes)$/i, ""));
|
|
31570
32418
|
return { strip: `${base}.visemes.png`, record: `${base}.talk.json` };
|
|
31571
32419
|
}
|
|
31572
32420
|
function readPortrait(bytes, label) {
|
|
@@ -31608,14 +32456,14 @@ async function makeVisemes(client2, opts) {
|
|
|
31608
32456
|
if (Boolean(opts.portrait) === Boolean(opts.characterId)) throw new Error("give a portrait file or a character id, not both");
|
|
31609
32457
|
const paths = talkOutputPaths(opts.out);
|
|
31610
32458
|
if (!opts.force) {
|
|
31611
|
-
for (const file of [paths.strip, paths.record]) if (
|
|
32459
|
+
for (const file of [paths.strip, paths.record]) if (existsSync51(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
31612
32460
|
}
|
|
31613
32461
|
const progress2 = opts.onProgress ?? (() => {
|
|
31614
32462
|
});
|
|
31615
32463
|
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
31616
32464
|
const interval = opts.intervalMs ?? 8e3;
|
|
31617
32465
|
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
31618
|
-
const portrait = opts.portrait ? readPortrait(await
|
|
32466
|
+
const portrait = opts.portrait ? readPortrait(await readFile44(opts.portrait), opts.portrait) : void 0;
|
|
31619
32467
|
const engine = opts.engine ?? "v3";
|
|
31620
32468
|
const visemeCount = opts.visemeCount ?? 7;
|
|
31621
32469
|
const submitted = await client2.createVocalAnimation({
|
|
@@ -31660,7 +32508,7 @@ async function makeVisemes(client2, opts) {
|
|
|
31660
32508
|
throw new Error(`PixelLab vocal-animation job ${jobId} finished with no mouth positions and no spritesheet`);
|
|
31661
32509
|
}
|
|
31662
32510
|
const usage2 = (await client2.getBackgroundJob(jobId).catch(() => null))?.usage ?? job.usage ?? null;
|
|
31663
|
-
await mkdir23(
|
|
32511
|
+
await mkdir23(path64.dirname(paths.strip), { recursive: true });
|
|
31664
32512
|
await writeFile28(paths.strip, strip);
|
|
31665
32513
|
const record = {
|
|
31666
32514
|
version: 1,
|
|
@@ -31671,8 +32519,8 @@ async function makeVisemes(client2, opts) {
|
|
|
31671
32519
|
visemeCount,
|
|
31672
32520
|
visemeOrder,
|
|
31673
32521
|
cell,
|
|
31674
|
-
strip:
|
|
31675
|
-
source: opts.portrait ? { portrait:
|
|
32522
|
+
strip: path64.basename(paths.strip),
|
|
32523
|
+
source: opts.portrait ? { portrait: path64.relative(path64.dirname(paths.record), path64.resolve(opts.portrait)).split(path64.sep).join("/") } : { characterId: opts.characterId },
|
|
31676
32524
|
...job.moods_on_character ? { moodsOnCharacter: job.moods_on_character } : {},
|
|
31677
32525
|
jobId,
|
|
31678
32526
|
usage: usage2,
|
|
@@ -31685,17 +32533,17 @@ async function makeVisemes(client2, opts) {
|
|
|
31685
32533
|
async function readTalkRecord(file) {
|
|
31686
32534
|
let record;
|
|
31687
32535
|
try {
|
|
31688
|
-
record = JSON.parse(await
|
|
32536
|
+
record = JSON.parse(await readFile44(file, "utf8"));
|
|
31689
32537
|
} catch (error) {
|
|
31690
32538
|
throw new Error(`${file} is not a readable .talk.json record: ${error instanceof Error ? error.message : String(error)}`);
|
|
31691
32539
|
}
|
|
31692
32540
|
if (record?.tool !== "vocal-animation" || !Array.isArray(record.visemeOrder) || !record.cell || !record.strip) {
|
|
31693
32541
|
throw new Error(`${file} is not a .talk.json record from pixelkiln talk visemes`);
|
|
31694
32542
|
}
|
|
31695
|
-
const stripFile =
|
|
31696
|
-
if (!
|
|
32543
|
+
const stripFile = path64.resolve(path64.dirname(path64.resolve(file)), record.strip);
|
|
32544
|
+
if (!existsSync51(stripFile)) throw new Error(`${file} names ${record.strip}, which is missing beside it`);
|
|
31697
32545
|
const row = Math.max(0, record.moodsOnCharacter?.indexOf(record.mood) ?? 0);
|
|
31698
|
-
const cells = cutStrip(await
|
|
32546
|
+
const cells = cutStrip(await readFile44(stripFile), record.visemeOrder.length, record.cell, row);
|
|
31699
32547
|
const visemes = Object.fromEntries(record.visemeOrder.map((id, index) => [id, { base64: cells[index].toString("base64"), format: "png" }]));
|
|
31700
32548
|
return { record, visemes };
|
|
31701
32549
|
}
|
|
@@ -31708,14 +32556,14 @@ function checkText(text) {
|
|
|
31708
32556
|
async function makeTalkingGif(client2, text, source, opts) {
|
|
31709
32557
|
if (Boolean(source.record) === Boolean(source.characterId)) throw new Error("give a .talk.json record or a character id, not both");
|
|
31710
32558
|
if (source.record && source.mood) throw new Error("a record holds one expression; --mood picks among a character's stored ones");
|
|
31711
|
-
const out =
|
|
31712
|
-
if (
|
|
32559
|
+
const out = path64.extname(opts.out) ? path64.resolve(opts.out) : path64.resolve(`${opts.out}.gif`);
|
|
32560
|
+
if (existsSync51(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
31713
32561
|
const line = checkText(text);
|
|
31714
32562
|
const visemes = source.record ? (await readTalkRecord(source.record)).visemes : void 0;
|
|
31715
32563
|
const res = await client2.createTalkingGif({ text: line, visemes, characterId: source.characterId, mood: source.mood, frameMs: opts.frameMs, holdMs: opts.holdMs });
|
|
31716
32564
|
const bytes = Buffer.from(res.gif_base64, "base64");
|
|
31717
32565
|
if (bytes.subarray(0, 4).toString("ascii") !== "GIF8") throw new Error(`PixelLab's talking GIF was not a GIF (${bytes.length} bytes)`);
|
|
31718
|
-
await mkdir23(
|
|
32566
|
+
await mkdir23(path64.dirname(out), { recursive: true });
|
|
31719
32567
|
await writeFile28(out, bytes);
|
|
31720
32568
|
return { out, frames: res.frames, durationMs: res.duration_ms, frameMs: res.frame_ms, holdMs: res.hold_ms, width: res.width, height: res.height, bytes: bytes.length };
|
|
31721
32569
|
}
|
|
@@ -31748,7 +32596,7 @@ async function planLipSync(client2, text, source, opts = {}) {
|
|
|
31748
32596
|
|
|
31749
32597
|
// src/cli/commands/talk.ts
|
|
31750
32598
|
function loadKeys5(args) {
|
|
31751
|
-
loadEnvFiles(
|
|
32599
|
+
loadEnvFiles(path65.dirname(path65.resolve(args.manifest)));
|
|
31752
32600
|
loadEnvFiles(process.cwd());
|
|
31753
32601
|
}
|
|
31754
32602
|
function moodOf(args) {
|
|
@@ -31770,7 +32618,7 @@ function textOf(args) {
|
|
|
31770
32618
|
}
|
|
31771
32619
|
function sourceOf(args) {
|
|
31772
32620
|
if (args.from && args.id) throw new UsageError("pass --from <record.talk.json> or --id <character id>, not both");
|
|
31773
|
-
if (args.from && !
|
|
32621
|
+
if (args.from && !existsSync52(args.from)) throw new UsageError(`${args.from} does not exist; --from is the .talk.json record talk visemes wrote`);
|
|
31774
32622
|
return { record: args.from, characterId: args.id };
|
|
31775
32623
|
}
|
|
31776
32624
|
async function runVisemes(args) {
|
|
@@ -31786,9 +32634,9 @@ async function runVisemes(args) {
|
|
|
31786
32634
|
const paths = talkOutputPaths(args.out);
|
|
31787
32635
|
let side = "unknown";
|
|
31788
32636
|
if (args.from) {
|
|
31789
|
-
if (!
|
|
32637
|
+
if (!existsSync52(args.from)) throw new UsageError(`${args.from} does not exist`);
|
|
31790
32638
|
try {
|
|
31791
|
-
side = readPortrait(await
|
|
32639
|
+
side = readPortrait(await readFile45(args.from), args.from).side;
|
|
31792
32640
|
} catch (error) {
|
|
31793
32641
|
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
31794
32642
|
}
|
|
@@ -31871,9 +32719,9 @@ async function runPlan2(args) {
|
|
|
31871
32719
|
log(json.trimEnd());
|
|
31872
32720
|
return;
|
|
31873
32721
|
}
|
|
31874
|
-
const out =
|
|
31875
|
-
if (
|
|
31876
|
-
await mkdir24(
|
|
32722
|
+
const out = path65.extname(args.out) ? path65.resolve(args.out) : path65.resolve(`${args.out}.json`);
|
|
32723
|
+
if (existsSync52(out) && !args.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
32724
|
+
await mkdir24(path65.dirname(out), { recursive: true });
|
|
31877
32725
|
await writeFile29(out, json);
|
|
31878
32726
|
if (args.json) log(json.trimEnd());
|
|
31879
32727
|
else log(` wrote ${out} (${plan.frames.length} frames, ${(plan.totalMs / 1e3).toFixed(2)} s, free)`);
|
|
@@ -31885,19 +32733,19 @@ async function runTalk(args) {
|
|
|
31885
32733
|
}
|
|
31886
32734
|
|
|
31887
32735
|
// src/cli/commands/quality.ts
|
|
31888
|
-
import
|
|
31889
|
-
import { readFile as
|
|
32736
|
+
import path67 from "path";
|
|
32737
|
+
import { readFile as readFile47 } from "fs/promises";
|
|
31890
32738
|
|
|
31891
32739
|
// src/pipeline/quality-regression.ts
|
|
31892
|
-
import
|
|
31893
|
-
import { existsSync as
|
|
31894
|
-
import { readFile as
|
|
32740
|
+
import path66 from "path";
|
|
32741
|
+
import { existsSync as existsSync53 } from "fs";
|
|
32742
|
+
import { readFile as readFile46 } from "fs/promises";
|
|
31895
32743
|
import { z as z16 } from "zod";
|
|
31896
32744
|
var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
31897
32745
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
31898
32746
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
31899
32747
|
var QualityPathSchema = z16.string().min(1).refine(
|
|
31900
|
-
(value) => !
|
|
32748
|
+
(value) => !path66.posix.isAbsolute(value) && !value.includes("\\"),
|
|
31901
32749
|
"expected a portable relative path"
|
|
31902
32750
|
);
|
|
31903
32751
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -32044,10 +32892,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
32044
32892
|
};
|
|
32045
32893
|
}
|
|
32046
32894
|
async function measureImageQuality(file) {
|
|
32047
|
-
const absolute =
|
|
32895
|
+
const absolute = path66.resolve(file);
|
|
32048
32896
|
let bytes;
|
|
32049
32897
|
try {
|
|
32050
|
-
bytes = await
|
|
32898
|
+
bytes = await readFile46(absolute);
|
|
32051
32899
|
} catch (error) {
|
|
32052
32900
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
32053
32901
|
}
|
|
@@ -32066,11 +32914,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
32066
32914
|
}
|
|
32067
32915
|
const ids = parsed.data.map((entry) => entry.id);
|
|
32068
32916
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
32069
|
-
const root =
|
|
32917
|
+
const root = path66.dirname(path66.resolve(inputsFilePath));
|
|
32070
32918
|
return parsed.data.map((entry) => ({
|
|
32071
32919
|
id: entry.id,
|
|
32072
|
-
file:
|
|
32073
|
-
...entry.record ? { record:
|
|
32920
|
+
file: path66.resolve(root, entry.path),
|
|
32921
|
+
...entry.record ? { record: path66.resolve(root, entry.record) } : {},
|
|
32074
32922
|
tolerances: QualityToleranceSchema.parse({
|
|
32075
32923
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
32076
32924
|
...entry.tolerances
|
|
@@ -32078,7 +32926,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
32078
32926
|
}));
|
|
32079
32927
|
}
|
|
32080
32928
|
function portableRelative2(from, to) {
|
|
32081
|
-
return
|
|
32929
|
+
return path66.relative(from, path66.resolve(to)).split(path66.sep).join("/") || ".";
|
|
32082
32930
|
}
|
|
32083
32931
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
32084
32932
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -32093,20 +32941,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
32093
32941
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
32094
32942
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
32095
32943
|
}
|
|
32096
|
-
const outputs = record.outputs.map((output) =>
|
|
32097
|
-
if (!outputs.includes(
|
|
32944
|
+
const outputs = record.outputs.map((output) => path66.resolve(path66.dirname(recordPath), output.path));
|
|
32945
|
+
if (!outputs.includes(path66.resolve(imagePath))) {
|
|
32098
32946
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
32099
32947
|
}
|
|
32100
32948
|
}
|
|
32101
32949
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
32102
32950
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
32103
|
-
const absolute =
|
|
32951
|
+
const absolute = path66.resolve(baselinePath);
|
|
32104
32952
|
for (const input of inputs) {
|
|
32105
|
-
if (
|
|
32953
|
+
if (path66.resolve(input.file) === absolute || input.record && path66.resolve(input.record) === absolute) {
|
|
32106
32954
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
32107
32955
|
}
|
|
32108
32956
|
}
|
|
32109
|
-
const root =
|
|
32957
|
+
const root = path66.dirname(absolute);
|
|
32110
32958
|
const cases = [];
|
|
32111
32959
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
32112
32960
|
const expected = await measureImageQuality(input.file);
|
|
@@ -32133,8 +32981,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
32133
32981
|
cases
|
|
32134
32982
|
});
|
|
32135
32983
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
32136
|
-
if (
|
|
32137
|
-
const current = await
|
|
32984
|
+
if (existsSync53(absolute) && !options.force) {
|
|
32985
|
+
const current = await readFile46(absolute);
|
|
32138
32986
|
if (!current.equals(data)) {
|
|
32139
32987
|
throw new OverwriteRefusedError(
|
|
32140
32988
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -32146,13 +32994,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
32146
32994
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
32147
32995
|
}
|
|
32148
32996
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
32149
|
-
const absolute =
|
|
32150
|
-
if (!
|
|
32997
|
+
const absolute = path66.resolve(baselinePath);
|
|
32998
|
+
if (!existsSync53(absolute)) {
|
|
32151
32999
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
32152
33000
|
}
|
|
32153
33001
|
let raw;
|
|
32154
33002
|
try {
|
|
32155
|
-
raw = JSON.parse(await
|
|
33003
|
+
raw = JSON.parse(await readFile46(absolute, "utf8"));
|
|
32156
33004
|
} catch (error) {
|
|
32157
33005
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
32158
33006
|
}
|
|
@@ -32162,12 +33010,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
32162
33010
|
if (unknown.length) {
|
|
32163
33011
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
32164
33012
|
}
|
|
32165
|
-
const root =
|
|
33013
|
+
const root = path66.dirname(absolute);
|
|
32166
33014
|
const cases = [...raw.cases];
|
|
32167
33015
|
const report = [];
|
|
32168
33016
|
for (const id of only) {
|
|
32169
33017
|
const input = byId.get(id);
|
|
32170
|
-
if (
|
|
33018
|
+
if (path66.resolve(input.file) === absolute || input.record && path66.resolve(input.record) === absolute) {
|
|
32171
33019
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
32172
33020
|
}
|
|
32173
33021
|
const expected = await measureImageQuality(input.file);
|
|
@@ -32197,16 +33045,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
32197
33045
|
}
|
|
32198
33046
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
32199
33047
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
32200
|
-
const current = await
|
|
33048
|
+
const current = await readFile46(absolute);
|
|
32201
33049
|
const changed = !current.equals(data);
|
|
32202
33050
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
32203
33051
|
return { baseline, path: absolute, changed, cases: report };
|
|
32204
33052
|
}
|
|
32205
33053
|
async function readQualityBaseline(baselinePath) {
|
|
32206
|
-
const absolute =
|
|
33054
|
+
const absolute = path66.resolve(baselinePath);
|
|
32207
33055
|
let raw;
|
|
32208
33056
|
try {
|
|
32209
|
-
raw = JSON.parse(await
|
|
33057
|
+
raw = JSON.parse(await readFile46(absolute, "utf8"));
|
|
32210
33058
|
} catch (error) {
|
|
32211
33059
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
32212
33060
|
}
|
|
@@ -32228,7 +33076,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
32228
33076
|
throw new Error(
|
|
32229
33077
|
`Invalid quality baseline ${absolute}:
|
|
32230
33078
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
32231
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
33079
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path66.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
32232
33080
|
);
|
|
32233
33081
|
}
|
|
32234
33082
|
return parsed.data;
|
|
@@ -32290,12 +33138,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
32290
33138
|
return { violations, warnings };
|
|
32291
33139
|
}
|
|
32292
33140
|
async function checkQualityBaseline(baselinePath) {
|
|
32293
|
-
const absolute =
|
|
33141
|
+
const absolute = path66.resolve(baselinePath);
|
|
32294
33142
|
const baseline = await readQualityBaseline(absolute);
|
|
32295
|
-
const root =
|
|
33143
|
+
const root = path66.dirname(absolute);
|
|
32296
33144
|
const cases = [];
|
|
32297
33145
|
for (const entry of baseline.cases) {
|
|
32298
|
-
const file =
|
|
33146
|
+
const file = path66.resolve(root, entry.file);
|
|
32299
33147
|
let actual = null;
|
|
32300
33148
|
const violations = [];
|
|
32301
33149
|
const warnings = [];
|
|
@@ -32308,7 +33156,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
32308
33156
|
violations.push(message4(error));
|
|
32309
33157
|
}
|
|
32310
33158
|
if (entry.record) {
|
|
32311
|
-
const recordPath =
|
|
33159
|
+
const recordPath = path66.resolve(root, entry.record.path);
|
|
32312
33160
|
try {
|
|
32313
33161
|
const recordHash = await sha256File(recordPath);
|
|
32314
33162
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -32350,15 +33198,15 @@ async function runQuality(args) {
|
|
|
32350
33198
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
32351
33199
|
let raw;
|
|
32352
33200
|
try {
|
|
32353
|
-
raw = JSON.parse(await
|
|
33201
|
+
raw = JSON.parse(await readFile47(path67.resolve(args.inputs), "utf8"));
|
|
32354
33202
|
} catch (error) {
|
|
32355
33203
|
throw new Error(
|
|
32356
|
-
`Could not read quality inputs ${
|
|
33204
|
+
`Could not read quality inputs ${path67.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
32357
33205
|
{ cause: error }
|
|
32358
33206
|
);
|
|
32359
33207
|
}
|
|
32360
33208
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
32361
|
-
if (
|
|
33209
|
+
if (path67.resolve(args.inputs) === path67.resolve(args.out)) {
|
|
32362
33210
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
32363
33211
|
}
|
|
32364
33212
|
if (args.assets.length) {
|
|
@@ -32373,7 +33221,7 @@ async function runQuality(args) {
|
|
|
32373
33221
|
}
|
|
32374
33222
|
log(
|
|
32375
33223
|
`
|
|
32376
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
33224
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path67.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
32377
33225
|
);
|
|
32378
33226
|
return;
|
|
32379
33227
|
}
|
|
@@ -32388,7 +33236,7 @@ async function runQuality(args) {
|
|
|
32388
33236
|
}, null, 2));
|
|
32389
33237
|
} else {
|
|
32390
33238
|
log(
|
|
32391
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
33239
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path67.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
32392
33240
|
);
|
|
32393
33241
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
32394
33242
|
}
|
|
@@ -32414,12 +33262,12 @@ async function runQuality(args) {
|
|
|
32414
33262
|
}
|
|
32415
33263
|
|
|
32416
33264
|
// src/cli/commands/recipe.ts
|
|
32417
|
-
import
|
|
33265
|
+
import path69 from "path";
|
|
32418
33266
|
|
|
32419
33267
|
// src/recipes.ts
|
|
32420
|
-
import
|
|
32421
|
-
import { existsSync as
|
|
32422
|
-
import { readdir as readdir6, readFile as
|
|
33268
|
+
import path68 from "path";
|
|
33269
|
+
import { existsSync as existsSync54 } from "fs";
|
|
33270
|
+
import { readdir as readdir6, readFile as readFile48 } from "fs/promises";
|
|
32423
33271
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
32424
33272
|
import { z as z17 } from "zod";
|
|
32425
33273
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
@@ -32428,7 +33276,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
32428
33276
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
32429
33277
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
32430
33278
|
var PortablePathSchema = z17.string().min(1).refine((value) => {
|
|
32431
|
-
if (value.includes("\\") ||
|
|
33279
|
+
if (value.includes("\\") || path68.posix.isAbsolute(value)) return false;
|
|
32432
33280
|
const parts = value.split("/");
|
|
32433
33281
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
32434
33282
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -32604,10 +33452,10 @@ function message5(error) {
|
|
|
32604
33452
|
return error instanceof Error ? error.message : String(error);
|
|
32605
33453
|
}
|
|
32606
33454
|
async function readRecipeFile(recipePath, bundled) {
|
|
32607
|
-
const absolute =
|
|
33455
|
+
const absolute = path68.resolve(recipePath);
|
|
32608
33456
|
let raw;
|
|
32609
33457
|
try {
|
|
32610
|
-
raw = JSON.parse(await
|
|
33458
|
+
raw = JSON.parse(await readFile48(absolute, "utf8"));
|
|
32611
33459
|
} catch (error) {
|
|
32612
33460
|
throw new Error(`Could not read recipe ${absolute}: ${message5(error)}`, { cause: error });
|
|
32613
33461
|
}
|
|
@@ -32618,13 +33466,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
32618
33466
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
32619
33467
|
);
|
|
32620
33468
|
}
|
|
32621
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
33469
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path68.dirname(absolute), bundled };
|
|
32622
33470
|
}
|
|
32623
33471
|
async function walkRecipeFiles(root) {
|
|
32624
|
-
if (!
|
|
33472
|
+
if (!existsSync54(root)) return [];
|
|
32625
33473
|
const out = [];
|
|
32626
33474
|
for (const entry of await readdir6(root, { withFileTypes: true })) {
|
|
32627
|
-
const resolved =
|
|
33475
|
+
const resolved = path68.join(root, entry.name);
|
|
32628
33476
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
32629
33477
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
32630
33478
|
}
|
|
@@ -32635,7 +33483,7 @@ function bundledRecipeRoot() {
|
|
|
32635
33483
|
}
|
|
32636
33484
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
32637
33485
|
const recipes = await Promise.all(
|
|
32638
|
-
(await walkRecipeFiles(
|
|
33486
|
+
(await walkRecipeFiles(path68.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
32639
33487
|
);
|
|
32640
33488
|
return recipes.sort(
|
|
32641
33489
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -32658,9 +33506,9 @@ function parseSelector(selector) {
|
|
|
32658
33506
|
return { id: match[1], version: match[2] };
|
|
32659
33507
|
}
|
|
32660
33508
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
32661
|
-
const local =
|
|
32662
|
-
if (
|
|
32663
|
-
const recipePath =
|
|
33509
|
+
const local = path68.resolve(target);
|
|
33510
|
+
if (existsSync54(local)) {
|
|
33511
|
+
const recipePath = path68.basename(local) === RECIPE_FILE ? local : path68.join(local, RECIPE_FILE);
|
|
32664
33512
|
return readRecipeFile(recipePath, false);
|
|
32665
33513
|
}
|
|
32666
33514
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -32674,8 +33522,8 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
32674
33522
|
return matches[0];
|
|
32675
33523
|
}
|
|
32676
33524
|
async function verifyFile(root, file) {
|
|
32677
|
-
const absolute =
|
|
32678
|
-
if (!
|
|
33525
|
+
const absolute = path68.resolve(root, ...file.path.split("/"));
|
|
33526
|
+
if (!existsSync54(absolute)) {
|
|
32679
33527
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
32680
33528
|
}
|
|
32681
33529
|
const actualSha256 = await sha256File(absolute);
|
|
@@ -32690,7 +33538,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
32690
33538
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
32691
33539
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
32692
33540
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
32693
|
-
const modelRoot = options.modelRoot ?
|
|
33541
|
+
const modelRoot = options.modelRoot ? path68.resolve(options.modelRoot) : null;
|
|
32694
33542
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
32695
33543
|
...await verifyFile(modelRoot, model),
|
|
32696
33544
|
source: model.source,
|
|
@@ -32724,7 +33572,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
32724
33572
|
};
|
|
32725
33573
|
}
|
|
32726
33574
|
function renderStyle(style, destination, cwd) {
|
|
32727
|
-
const portableDir =
|
|
33575
|
+
const portableDir = path68.relative(cwd, destination).split(path68.sep).join("/") || ".";
|
|
32728
33576
|
const replace = (value) => {
|
|
32729
33577
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
32730
33578
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -32736,25 +33584,25 @@ function renderStyle(style, destination, cwd) {
|
|
|
32736
33584
|
return replace(style);
|
|
32737
33585
|
}
|
|
32738
33586
|
async function installRecipe(target, options = {}) {
|
|
32739
|
-
const cwd =
|
|
33587
|
+
const cwd = path68.resolve(options.cwd ?? process.cwd());
|
|
32740
33588
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
32741
33589
|
const verification = await verifyRecipe(loaded.path);
|
|
32742
33590
|
if (!verification.ok) {
|
|
32743
33591
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
32744
33592
|
}
|
|
32745
|
-
const destination = options.out ?
|
|
33593
|
+
const destination = options.out ? path68.resolve(cwd, options.out) : path68.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
32746
33594
|
const sources = [
|
|
32747
33595
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
32748
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
33596
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path68.join(loaded.dir, ...file.path.split("/")) }))
|
|
32749
33597
|
];
|
|
32750
33598
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
32751
|
-
path:
|
|
32752
|
-
data: await
|
|
33599
|
+
path: path68.join(destination, ...file.path.split("/")),
|
|
33600
|
+
data: await readFile48(file.source)
|
|
32753
33601
|
})));
|
|
32754
33602
|
if (!options.force) {
|
|
32755
33603
|
for (const file of files) {
|
|
32756
|
-
if (!
|
|
32757
|
-
const current = await
|
|
33604
|
+
if (!existsSync54(file.path)) continue;
|
|
33605
|
+
const current = await readFile48(file.path);
|
|
32758
33606
|
if (!current.equals(file.data)) {
|
|
32759
33607
|
throw new OverwriteRefusedError(
|
|
32760
33608
|
`Recipe destination has local changes: ${file.path}. Choose another --out or pass --force to replace declared recipe files.`,
|
|
@@ -32848,14 +33696,14 @@ async function runRecipe(args) {
|
|
|
32848
33696
|
}, null, 2));
|
|
32849
33697
|
} else {
|
|
32850
33698
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
32851
|
-
log(` ${
|
|
33699
|
+
log(` ${path69.relative(process.cwd(), result.destination) || "."}`);
|
|
32852
33700
|
log(`
|
|
32853
33701
|
Add this entry under your manifest's styles object:`);
|
|
32854
33702
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
32855
33703
|
if (result.recipe.models.length) {
|
|
32856
33704
|
log(`
|
|
32857
33705
|
Models are not downloaded automatically. Verify them with:`);
|
|
32858
|
-
log(` pixelkiln recipe verify ${
|
|
33706
|
+
log(` pixelkiln recipe verify ${path69.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
32859
33707
|
}
|
|
32860
33708
|
}
|
|
32861
33709
|
return;
|
|
@@ -32863,7 +33711,7 @@ async function runRecipe(args) {
|
|
|
32863
33711
|
}
|
|
32864
33712
|
|
|
32865
33713
|
// src/cli/commands/refine.ts
|
|
32866
|
-
import
|
|
33714
|
+
import path70 from "path";
|
|
32867
33715
|
async function runRefine(args) {
|
|
32868
33716
|
if (args.from || args.subcommand === "approve") {
|
|
32869
33717
|
if (!args.from) {
|
|
@@ -32893,12 +33741,12 @@ async function runRefine(args) {
|
|
|
32893
33741
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
32894
33742
|
);
|
|
32895
33743
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
32896
|
-
log(` wrote ${
|
|
32897
|
-
log(` quality record: ${
|
|
33744
|
+
log(` wrote ${path70.relative(process.cwd(), result3.output)}`);
|
|
33745
|
+
log(` quality record: ${path70.relative(process.cwd(), result3.record)}`);
|
|
32898
33746
|
log(`
|
|
32899
33747
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
32900
33748
|
log(
|
|
32901
|
-
` pixelkiln refine approve --from ${
|
|
33749
|
+
` pixelkiln refine approve --from ${path70.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
32902
33750
|
);
|
|
32903
33751
|
}
|
|
32904
33752
|
return;
|
|
@@ -32926,7 +33774,7 @@ async function runRefine(args) {
|
|
|
32926
33774
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
32927
33775
|
else {
|
|
32928
33776
|
log(
|
|
32929
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
33777
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path70.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path70.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
32930
33778
|
);
|
|
32931
33779
|
}
|
|
32932
33780
|
return;
|
|
@@ -32935,7 +33783,7 @@ async function runRefine(args) {
|
|
|
32935
33783
|
if (args.json) {
|
|
32936
33784
|
log(JSON.stringify(result2, null, 2));
|
|
32937
33785
|
} else {
|
|
32938
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
33786
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path70.relative(process.cwd(), result2.output || result2.record)}`);
|
|
32939
33787
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
32940
33788
|
}
|
|
32941
33789
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -32981,7 +33829,7 @@ async function runRefine(args) {
|
|
|
32981
33829
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
32982
33830
|
if (item.state === "needs-approval") {
|
|
32983
33831
|
log(
|
|
32984
|
-
` pixelkiln refine approve --from ${
|
|
33832
|
+
` pixelkiln refine approve --from ${path70.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
32985
33833
|
);
|
|
32986
33834
|
}
|
|
32987
33835
|
}
|
|
@@ -32992,7 +33840,7 @@ async function runRefine(args) {
|
|
|
32992
33840
|
}
|
|
32993
33841
|
|
|
32994
33842
|
// src/cli/commands/anchors.ts
|
|
32995
|
-
import
|
|
33843
|
+
import path71 from "path";
|
|
32996
33844
|
async function runAnchors(args) {
|
|
32997
33845
|
const target = args.target;
|
|
32998
33846
|
const { specs, lock } = await openProject2(args);
|
|
@@ -33013,7 +33861,7 @@ async function runAnchors(args) {
|
|
|
33013
33861
|
dryRun: args.dryRun,
|
|
33014
33862
|
onProgress: log
|
|
33015
33863
|
});
|
|
33016
|
-
const file =
|
|
33864
|
+
const file = path71.relative(spec.root, result.file) || result.file;
|
|
33017
33865
|
if (args.dryRun) {
|
|
33018
33866
|
log(` ${result.estimated} frame${result.estimated === 1 ? "" : "s"} to estimate (about ${cost(result.estimated)}), ${result.current} already current`);
|
|
33019
33867
|
} else if (result.estimated) {
|
|
@@ -33025,12 +33873,12 @@ async function runAnchors(args) {
|
|
|
33025
33873
|
}
|
|
33026
33874
|
|
|
33027
33875
|
// src/cli/commands/redraw.ts
|
|
33028
|
-
import
|
|
33876
|
+
import path73 from "path";
|
|
33029
33877
|
|
|
33030
33878
|
// src/pipeline/redraw.ts
|
|
33031
|
-
import { existsSync as
|
|
33032
|
-
import { mkdir as mkdir25, readFile as
|
|
33033
|
-
import
|
|
33879
|
+
import { existsSync as existsSync55 } from "fs";
|
|
33880
|
+
import { mkdir as mkdir25, readFile as readFile49, rename as rename14, writeFile as writeFile30 } from "fs/promises";
|
|
33881
|
+
import path72 from "path";
|
|
33034
33882
|
function redrawRoles(spec, lock) {
|
|
33035
33883
|
return (lock.entries[lockKey(spec.styleId, spec.assetId)]?.outputs ?? []).map((output) => output.role ?? "");
|
|
33036
33884
|
}
|
|
@@ -33072,7 +33920,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
33072
33920
|
const still = source.spec.character?.kind !== "animation";
|
|
33073
33921
|
for (const [index, output] of sourceEntry.outputs.entries()) {
|
|
33074
33922
|
if (!still && !owners.includes(source.assetId)) continue;
|
|
33075
|
-
const png = await
|
|
33923
|
+
const png = await readFile49(currentEntryOutputPath(sourceEntry, source.spec, index));
|
|
33076
33924
|
if (still) stills.push(png);
|
|
33077
33925
|
if (!owners.includes(source.assetId)) continue;
|
|
33078
33926
|
const role = output.role ?? String(index).padStart(2, "0");
|
|
@@ -33106,23 +33954,23 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
33106
33954
|
continue;
|
|
33107
33955
|
}
|
|
33108
33956
|
const file = at2 >= 0 ? currentEntryOutputPath(entry, spec, at2) : null;
|
|
33109
|
-
if (!file || !
|
|
33957
|
+
if (!file || !existsSync55(file)) {
|
|
33110
33958
|
layers.push(null);
|
|
33111
33959
|
continue;
|
|
33112
33960
|
}
|
|
33113
33961
|
const pair = offset?.per && offset.per[source.assetId] || offset;
|
|
33114
|
-
const png = await
|
|
33962
|
+
const png = await readFile49(file);
|
|
33115
33963
|
layers.push(pair ? shiftPixels(png, -pair.x, -pair.y).png : png);
|
|
33116
33964
|
}
|
|
33117
33965
|
const prepared = redrawSheet(built, layers, redraw);
|
|
33118
33966
|
const size = decodePng(prepared.keyed);
|
|
33119
33967
|
const cost = proTierCost(size.width, size.height);
|
|
33120
|
-
const workDir =
|
|
33968
|
+
const workDir = path72.join(layerWorkDir(spec), "redraw");
|
|
33121
33969
|
const result = { roles, guides, sheet: { width: size.width, height: size.height }, cost, billed: null, written: [], workDir };
|
|
33122
33970
|
if (opts.dryRun) return result;
|
|
33123
33971
|
await mkdir25(workDir, { recursive: true });
|
|
33124
|
-
await writeFile30(
|
|
33125
|
-
await writeFile30(
|
|
33972
|
+
await writeFile30(path72.join(workDir, "keyed.png"), prepared.keyed);
|
|
33973
|
+
await writeFile30(path72.join(workDir, "mask.png"), prepared.mask);
|
|
33126
33974
|
const count = roles.length;
|
|
33127
33975
|
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"}.`;
|
|
33128
33976
|
const jobId = await painter.paintSheet({ description, keyed: prepared.keyed, mask: prepared.mask, seed: opts.seed ?? spec.seed });
|
|
@@ -33140,13 +33988,13 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
33140
33988
|
if (Date.now() > deadline) throw new Error(`${label}: redraw job ${jobId} did not finish in time; nothing was changed`);
|
|
33141
33989
|
await new Promise((resolve) => setTimeout(resolve, opts.pollMs ?? 3e3));
|
|
33142
33990
|
}
|
|
33143
|
-
await writeFile30(
|
|
33991
|
+
await writeFile30(path72.join(workDir, "result.png"), painted);
|
|
33144
33992
|
const returned = decodePng(painted);
|
|
33145
33993
|
if (returned.width !== size.width || returned.height !== size.height) {
|
|
33146
33994
|
throw new Error(`${label}: redraw job ${jobId} returned a ${returned.width}x${returned.height} image for a ${size.width}x${size.height} sheet`);
|
|
33147
33995
|
}
|
|
33148
33996
|
const cut = cutLayerFrames(painted, { keyed: prepared.keyed, mask: prepared.mask, frames: built.frames }, { key: layer.key, region: layer.region });
|
|
33149
|
-
const cacheDir =
|
|
33997
|
+
const cacheDir = path72.resolve(opts.cacheDir ?? path72.join(path72.dirname(opts.lockPath), ".pixelkiln", "cache"));
|
|
33150
33998
|
const outputs = [...entry.outputs];
|
|
33151
33999
|
const renames = [];
|
|
33152
34000
|
for (const [index, at2] of targets) {
|
|
@@ -33155,7 +34003,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
33155
34003
|
const empty = !decodePng(raw).pixels.some((value, i) => i % 4 === 3 && value > 0);
|
|
33156
34004
|
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`);
|
|
33157
34005
|
const target = currentEntryOutputPath(entry, spec, at2);
|
|
33158
|
-
if (
|
|
34006
|
+
if (existsSync55(target)) await cacheMedia(cacheDir, await readFile49(target), MediaType.PNG);
|
|
33159
34007
|
await cacheMedia(cacheDir, raw, MediaType.PNG);
|
|
33160
34008
|
const processed = applyPostprocess(raw, MediaType.PNG, entry.postprocess, [], role);
|
|
33161
34009
|
await cacheMedia(cacheDir, processed.bytes, MediaType.PNG);
|
|
@@ -33204,7 +34052,7 @@ async function runRedraw(args) {
|
|
|
33204
34052
|
const painter = args.dryRun ? { paintSheet: never, paintedSheet: never } : new PixelLabProvider(clientFromEnv());
|
|
33205
34053
|
const result = await redrawLayerFrames(spec, project2.lock, painter, {
|
|
33206
34054
|
frames: args.redrawFrames,
|
|
33207
|
-
lockPath:
|
|
34055
|
+
lockPath: path73.resolve(args.lock),
|
|
33208
34056
|
seed: args.seed,
|
|
33209
34057
|
dryRun: args.dryRun,
|
|
33210
34058
|
onProgress: log
|
|
@@ -33215,16 +34063,16 @@ async function runRedraw(args) {
|
|
|
33215
34063
|
log(` would redraw ${frames} (${result.roles.join(", ")}) beside ${result.guides} dressed, on a ${sheet} sheet: about ${result.cost} generations`);
|
|
33216
34064
|
return;
|
|
33217
34065
|
}
|
|
33218
|
-
for (const file of result.written) log(` wrote ${
|
|
34066
|
+
for (const file of result.written) log(` wrote ${path73.relative(process.cwd(), file)}`);
|
|
33219
34067
|
const billed = result.billed ? `${result.billed.amount} ${result.billed.unit} billed` : `about ${result.cost} generations`;
|
|
33220
|
-
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${
|
|
34068
|
+
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${path73.relative(process.cwd(), result.workDir)}`);
|
|
33221
34069
|
log(` look at ${result.written.length === 1 ? "it" : "them"}, then run pixelkiln gen to rebuild anything made from this layer`);
|
|
33222
34070
|
}
|
|
33223
34071
|
|
|
33224
34072
|
// src/cli/commands/skeleton.ts
|
|
33225
|
-
import
|
|
33226
|
-
import { existsSync as
|
|
33227
|
-
import { readFile as
|
|
34073
|
+
import path74 from "path";
|
|
34074
|
+
import { existsSync as existsSync56 } from "fs";
|
|
34075
|
+
import { readFile as readFile50, writeFile as writeFile31 } from "fs/promises";
|
|
33228
34076
|
|
|
33229
34077
|
// src/skeleton-preview.ts
|
|
33230
34078
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -33335,12 +34183,12 @@ var Canvas = class {
|
|
|
33335
34183
|
async function runEstimateSkeleton(args) {
|
|
33336
34184
|
const image = args.target;
|
|
33337
34185
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
33338
|
-
if (args.out &&
|
|
34186
|
+
if (args.out && existsSync56(path74.resolve(args.out)) && !args.force) {
|
|
33339
34187
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
33340
34188
|
}
|
|
33341
|
-
loadEnvFiles(
|
|
34189
|
+
loadEnvFiles(path74.dirname(path74.resolve(args.manifest)));
|
|
33342
34190
|
loadEnvFiles(process.cwd());
|
|
33343
|
-
const bytes = await
|
|
34191
|
+
const bytes = await readFile50(path74.resolve(image));
|
|
33344
34192
|
const metadata = imageMetadata(bytes);
|
|
33345
34193
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
33346
34194
|
const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
|
|
@@ -33352,7 +34200,7 @@ async function runEstimateSkeleton(args) {
|
|
|
33352
34200
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
33353
34201
|
const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
33354
34202
|
if (args.out) {
|
|
33355
|
-
await writeFile31(
|
|
34203
|
+
await writeFile31(path74.resolve(args.out), json + "\n");
|
|
33356
34204
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
33357
34205
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
33358
34206
|
} else {
|
|
@@ -33365,8 +34213,8 @@ async function runSkeletonPreview(args) {
|
|
|
33365
34213
|
let sourceFile;
|
|
33366
34214
|
let label;
|
|
33367
34215
|
if (target.endsWith(".json")) {
|
|
33368
|
-
keypointsFile =
|
|
33369
|
-
sourceFile = args.from ?
|
|
34216
|
+
keypointsFile = path74.resolve(target);
|
|
34217
|
+
sourceFile = args.from ? path74.resolve(args.from) : void 0;
|
|
33370
34218
|
label = target;
|
|
33371
34219
|
} else {
|
|
33372
34220
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -33378,31 +34226,31 @@ async function runSkeletonPreview(args) {
|
|
|
33378
34226
|
);
|
|
33379
34227
|
}
|
|
33380
34228
|
keypointsFile = spec.revision.keypointsFile;
|
|
33381
|
-
sourceFile = args.from ?
|
|
34229
|
+
sourceFile = args.from ? path74.resolve(args.from) : spec.revision.sourceFile;
|
|
33382
34230
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
33383
34231
|
}
|
|
33384
|
-
if (!
|
|
34232
|
+
if (!existsSync56(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
33385
34233
|
let json;
|
|
33386
34234
|
try {
|
|
33387
|
-
json = JSON.parse(await
|
|
34235
|
+
json = JSON.parse(await readFile50(keypointsFile, "utf8"));
|
|
33388
34236
|
} catch (error) {
|
|
33389
34237
|
throw new UsageError(`${keypointsFile} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
33390
34238
|
}
|
|
33391
34239
|
const set = parseSkeletonSet(json, keypointsFile);
|
|
33392
34240
|
let source;
|
|
33393
34241
|
if (sourceFile) {
|
|
33394
|
-
if (!
|
|
34242
|
+
if (!existsSync56(sourceFile)) {
|
|
33395
34243
|
log(` source image does not exist yet, drawing on a plain ground: ${sourceFile}`);
|
|
33396
34244
|
} else {
|
|
33397
|
-
const bytes = await
|
|
34245
|
+
const bytes = await readFile50(sourceFile);
|
|
33398
34246
|
if (imageMetadata(bytes)?.format !== "png") throw new UsageError(`${sourceFile} must be a PNG to preview over`);
|
|
33399
34247
|
source = decodePng(bytes);
|
|
33400
34248
|
}
|
|
33401
34249
|
}
|
|
33402
|
-
const out =
|
|
34250
|
+
const out = path74.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
33403
34251
|
await writeFile31(out, renderSkeletonSheet(set, { source }));
|
|
33404
34252
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
33405
|
-
const shown2 =
|
|
34253
|
+
const shown2 = path74.relative(process.cwd(), out);
|
|
33406
34254
|
log(` wrote ${shown2.startsWith("..") ? out : shown2}`);
|
|
33407
34255
|
}
|
|
33408
34256
|
|
|
@@ -33448,15 +34296,15 @@ async function runTools(args) {
|
|
|
33448
34296
|
}
|
|
33449
34297
|
|
|
33450
34298
|
// src/cli/commands/workspace.ts
|
|
33451
|
-
import
|
|
33452
|
-
import { existsSync as
|
|
34299
|
+
import path75 from "path";
|
|
34300
|
+
import { existsSync as existsSync57 } from "fs";
|
|
33453
34301
|
async function runWorkspace(args) {
|
|
33454
|
-
const workspacePath =
|
|
33455
|
-
const dir =
|
|
34302
|
+
const workspacePath = path75.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
34303
|
+
const dir = path75.dirname(workspacePath);
|
|
33456
34304
|
if (args.subcommand === "add") {
|
|
33457
|
-
const manifestPath =
|
|
34305
|
+
const manifestPath = path75.resolve(args.target);
|
|
33458
34306
|
const loadedTarget = await loadManifest(manifestPath);
|
|
33459
|
-
const lockPath = args.explicitLock ?
|
|
34307
|
+
const lockPath = args.explicitLock ? path75.resolve(args.explicitLock) : path75.join(path75.dirname(manifestPath), "pixelkiln.lock.json");
|
|
33460
34308
|
const ws = await loadWorkspace(workspacePath);
|
|
33461
34309
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
33462
34310
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -33476,10 +34324,10 @@ async function runWorkspace(args) {
|
|
|
33476
34324
|
...args.account ? { account: args.account } : {}
|
|
33477
34325
|
};
|
|
33478
34326
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project2] });
|
|
33479
|
-
log(` registered "${id}" in ${
|
|
34327
|
+
log(` registered "${id}" in ${path75.relative(process.cwd(), workspacePath)}`);
|
|
33480
34328
|
log(` manifest: ${project2.manifest}`);
|
|
33481
34329
|
log(` lock: ${project2.lock}`);
|
|
33482
|
-
if (!
|
|
34330
|
+
if (!existsSync57(lockPath)) {
|
|
33483
34331
|
log(
|
|
33484
34332
|
` warning: no lockfile there yet; this project contributes no claims until one is generated`
|
|
33485
34333
|
);
|
|
@@ -33488,7 +34336,7 @@ async function runWorkspace(args) {
|
|
|
33488
34336
|
}
|
|
33489
34337
|
if (args.subcommand === "remove") {
|
|
33490
34338
|
const ws = await loadWorkspace(workspacePath);
|
|
33491
|
-
const resolvedTarget =
|
|
34339
|
+
const resolvedTarget = path75.resolve(args.target);
|
|
33492
34340
|
const match = ws.projects.find(
|
|
33493
34341
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
33494
34342
|
);
|
|
@@ -33499,11 +34347,11 @@ async function runWorkspace(args) {
|
|
|
33499
34347
|
version: 1,
|
|
33500
34348
|
projects: ws.projects.filter((p) => p !== match)
|
|
33501
34349
|
});
|
|
33502
|
-
log(` removed "${match.id}" from ${
|
|
34350
|
+
log(` removed "${match.id}" from ${path75.relative(process.cwd(), workspacePath)}`);
|
|
33503
34351
|
return;
|
|
33504
34352
|
}
|
|
33505
34353
|
if (args.subcommand === "list") {
|
|
33506
|
-
if (!
|
|
34354
|
+
if (!existsSync57(workspacePath)) {
|
|
33507
34355
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
33508
34356
|
}
|
|
33509
34357
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -33511,9 +34359,9 @@ async function runWorkspace(args) {
|
|
|
33511
34359
|
if (args.json) {
|
|
33512
34360
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
33513
34361
|
} else if (!ws.projects.length) {
|
|
33514
|
-
log(` no projects registered in ${
|
|
34362
|
+
log(` no projects registered in ${path75.relative(process.cwd(), workspacePath)}`);
|
|
33515
34363
|
} else {
|
|
33516
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
34364
|
+
log(` ${ws.projects.length} project(s) in ${path75.relative(process.cwd(), workspacePath)}:`);
|
|
33517
34365
|
for (const p of ws.projects) {
|
|
33518
34366
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
33519
34367
|
}
|
|
@@ -33523,7 +34371,7 @@ async function runWorkspace(args) {
|
|
|
33523
34371
|
return;
|
|
33524
34372
|
}
|
|
33525
34373
|
if (args.subcommand === "status") {
|
|
33526
|
-
if (!
|
|
34374
|
+
if (!existsSync57(workspacePath)) {
|
|
33527
34375
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
33528
34376
|
}
|
|
33529
34377
|
const ws = await loadWorkspace(workspacePath);
|
|
@@ -33531,7 +34379,7 @@ async function runWorkspace(args) {
|
|
|
33531
34379
|
if (args.json) {
|
|
33532
34380
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
33533
34381
|
} else {
|
|
33534
|
-
log(` workspace: ${
|
|
34382
|
+
log(` workspace: ${path75.relative(process.cwd(), workspacePath)}`);
|
|
33535
34383
|
for (const p of report.projects) {
|
|
33536
34384
|
if (p.error) {
|
|
33537
34385
|
log(`
|
|
@@ -33585,8 +34433,8 @@ async function runHelp() {
|
|
|
33585
34433
|
async function runVersion() {
|
|
33586
34434
|
for (const up of ["../package.json", "../../package.json"]) {
|
|
33587
34435
|
const url = new URL(up, import.meta.url);
|
|
33588
|
-
if (!
|
|
33589
|
-
const pkg = JSON.parse(await
|
|
34436
|
+
if (!existsSync58(url)) continue;
|
|
34437
|
+
const pkg = JSON.parse(await readFile51(url, "utf8"));
|
|
33590
34438
|
if (pkg.name === "pixelkiln") {
|
|
33591
34439
|
log(`${pkg.name} ${pkg.version}`);
|
|
33592
34440
|
return;
|