pixelkiln 0.101.0 → 0.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -76,6 +76,9 @@ __export(index_exports, {
76
76
  HISTORY_ENV: () => HISTORY_ENV,
77
77
  HandEditCompanionSchema: () => HandEditCompanionSchema,
78
78
  IMPORT_MAX_SIDE: () => IMPORT_MAX_SIDE,
79
+ IMPORT_MAX_TILES: () => IMPORT_MAX_TILES,
80
+ IMPORT_TILE_TYPES: () => IMPORT_TILE_TYPES,
81
+ IMPORT_TILE_VIEWS: () => IMPORT_TILE_VIEWS,
79
82
  ImageQualityMetricsSchema: () => ImageQualityMetricsSchema,
80
83
  InheritedStyleSchema: () => InheritedStyleSchema,
81
84
  LockEntrySchema: () => LockEntrySchema,
@@ -144,6 +147,7 @@ __export(index_exports, {
144
147
  StyleInputSchema: () => StyleInputSchema,
145
148
  StyleSchema: () => StyleSchema,
146
149
  TARGET_PALETTE_GENERATORS: () => TARGET_PALETTE_GENERATORS,
150
+ TILESET_MODES: () => TILESET_MODES,
147
151
  TerrainConnectSchema: () => TerrainConnectSchema,
148
152
  TerrainLinkSchema: () => TerrainLinkSchema,
149
153
  TerrainSideSchema: () => TerrainSideSchema,
@@ -158,7 +162,10 @@ __export(index_exports, {
158
162
  UnsupportedCapabilityError: () => UnsupportedCapabilityError,
159
163
  UsageError: () => UsageError,
160
164
  VFX_ARTISTS: () => VFX_ARTISTS,
165
+ VFX_ARTIST_ANIMATED_EXTRA: () => VFX_ARTIST_ANIMATED_EXTRA,
166
+ VFX_ARTIST_MAX_FRAMES: () => VFX_ARTIST_MAX_FRAMES,
161
167
  VFX_ARTIST_MAX_SPRITE: () => VFX_ARTIST_MAX_SPRITE,
168
+ VFX_ARTIST_MAX_STRIP: () => VFX_ARTIST_MAX_STRIP,
162
169
  VFX_TOOL: () => VFX_TOOL,
163
170
  VfxPartSchema: () => VfxPartSchema,
164
171
  WorkspaceProjectSchema: () => WorkspaceProjectSchema,
@@ -183,7 +190,9 @@ __export(index_exports, {
183
190
  checkExportBytes: () => checkExportBytes,
184
191
  checkQualityBaseline: () => checkQualityBaseline,
185
192
  checkQualityRecord: () => checkQualityRecord,
193
+ checkSaveTarget: () => checkSaveTarget,
186
194
  checkUiInsets: () => checkUiInsets,
195
+ chooseTilesetSheetReading: () => chooseTilesetSheetReading,
187
196
  clientFromEnv: () => clientFromEnv,
188
197
  colorDistance: () => colorDistance,
189
198
  countNumberedDescriptions: () => countNumberedDescriptions,
@@ -232,6 +241,7 @@ __export(index_exports, {
232
241
  generateMusic: () => generateMusic,
233
242
  generateSoundEffect: () => generateSoundEffect,
234
243
  generationCost: () => generationCost,
244
+ gifSize: () => gifSize,
235
245
  groupOrphansByStyle: () => groupOrphansByStyle,
236
246
  handEditBase: () => handEditBase,
237
247
  handEditBases: () => handEditBases,
@@ -246,6 +256,9 @@ __export(index_exports, {
246
256
  imageMetadata: () => imageMetadata,
247
257
  importLocal: () => importLocal,
248
258
  importObjectFile: () => importObjectFile,
259
+ importTileHeights: () => importTileHeights,
260
+ importTilesFiles: () => importTilesFiles,
261
+ importTilesetFile: () => importTilesetFile,
249
262
  inspectCaches: () => inspectCaches,
250
263
  inspectQualityProfile: () => inspectQualityProfile,
251
264
  inspectRevisionReadiness: () => inspectRevisionReadiness,
@@ -312,6 +325,7 @@ __export(index_exports, {
312
325
  pickHistory: () => pickHistory,
313
326
  pixMiniMaxCost: () => pixMiniMaxCost,
314
327
  pixelateFile: () => pixelateFile,
328
+ pngFilesAt: () => pngFilesAt,
315
329
  pngSize: () => pngSize,
316
330
  poll: () => poll,
317
331
  portableOutputPath: () => portableOutputPath,
@@ -376,6 +390,8 @@ __export(index_exports, {
376
390
  runVfxWorkbench: () => runVfxWorkbench,
377
391
  saveHandEdit: () => saveHandEdit,
378
392
  saveLock: () => saveLock,
393
+ saveToAssetFile: () => saveToAssetFile,
394
+ saveUndoDir: () => saveUndoDir,
379
395
  saveWorkspace: () => saveWorkspace,
380
396
  scanAssets: () => scanAssets,
381
397
  selectEntryOutput: () => selectEntryOutput,
@@ -406,6 +422,7 @@ __export(index_exports, {
406
422
  tileFeatureOutputCount: () => tileFeatureOutputCount,
407
423
  tileVariationCount: () => tileVariationCount,
408
424
  tilesCost: () => tilesCost,
425
+ tilesetSheetReadings: () => tilesetSheetReadings,
409
426
  toPortablePath: () => toPortablePath,
410
427
  totalSpend: () => totalSpend,
411
428
  uiElementCandidateCount: () => uiElementCandidateCount,
@@ -421,6 +438,7 @@ __export(index_exports, {
421
438
  vfxArtistCeiling: () => vfxArtistCeiling,
422
439
  vfxArtistFiles: () => vfxArtistFiles,
423
440
  vfxArtistFrameFacts: () => vfxArtistFrameFacts,
441
+ vfxArtistFrameSide: () => vfxArtistFrameSide,
424
442
  vfxArtistQuote: () => vfxArtistQuote,
425
443
  vfxArtistSprite: () => vfxArtistSprite,
426
444
  vfxAtlasFrames: () => vfxAtlasFrames,
@@ -721,8 +739,21 @@ var AssetVfxSchema = import_zod.z.object({
721
739
  fps: import_zod.z.number().int().min(1).max(60).optional(),
722
740
  name: import_zod.z.string().min(1).optional(),
723
741
  description: import_zod.z.string().trim().min(1).max(8e3).optional(),
724
- artist: import_zod.z.enum(["lite", "pro"]).optional()
742
+ artist: import_zod.z.enum(["lite", "pro"]).optional(),
743
+ spriteFrames: import_zod.z.number().int().min(1).max(32).optional(),
744
+ spriteFps: import_zod.z.number().int().min(1).max(60).optional()
725
745
  }).strict().superRefine((vfx, context) => {
746
+ for (const key2 of ["spriteFrames", "spriteFps"]) {
747
+ if (vfx[key2] === void 0) continue;
748
+ if (vfx.description === void 0) {
749
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: `${key2} describes the sprite sent to PixelLab's VFX artist; add a description`, path: [key2] });
750
+ } else if (!vfx.sprite) {
751
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: `${key2} describes a sprite strip; add a sprite`, path: [key2] });
752
+ }
753
+ }
754
+ if (vfx.spriteFps !== void 0 && vfx.sprite && vfx.description !== void 0 && (vfx.spriteFrames ?? 1) < 2) {
755
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "spriteFps is the speed of a sprite strip; set spriteFrames to 2 or more", path: ["spriteFps"] });
756
+ }
726
757
  if (vfx.description !== void 0) {
727
758
  for (const key2 of ["preset", "recipe", "parts", "fps"]) {
728
759
  if (vfx[key2] !== void 0) {
@@ -2550,6 +2581,53 @@ var ImportObjectSchema = import_zod3.z.object({
2550
2581
  size: import_zod3.z.object({ width: import_zod3.z.number(), height: import_zod3.z.number() }).passthrough(),
2551
2582
  image_url: import_zod3.z.string()
2552
2583
  }).passthrough();
2584
+ var ImportTilesetSchema = import_zod3.z.object({ tileset_id: import_zod3.z.string().min(1), status: import_zod3.z.string().default("completed") }).passthrough();
2585
+ var ImportTilesProSchema = import_zod3.z.object({ tile_id: import_zod3.z.string().min(1), status: import_zod3.z.string().default("completed") }).passthrough();
2586
+ var SaveToAssetSchema = import_zod3.z.object({
2587
+ action: import_zod3.z.enum(["saved", "added", "unchanged"]),
2588
+ target: import_zod3.z.string().min(1),
2589
+ kind: import_zod3.z.string(),
2590
+ width: import_zod3.z.number(),
2591
+ height: import_zod3.z.number(),
2592
+ frame_count: import_zod3.z.number(),
2593
+ changed_pixels: import_zod3.z.number().default(0),
2594
+ previous_frames: import_zod3.z.array(import_zod3.z.object({ base64: import_zod3.z.string().min(1) }).passthrough()).nullable().optional(),
2595
+ note: import_zod3.z.string().nullable().optional(),
2596
+ maps: import_zod3.z.string().nullable().optional()
2597
+ }).passthrough();
2598
+ var VocalAnimationSubmitSchema = import_zod3.z.object({ background_job_id: import_zod3.z.string().min(1), status: import_zod3.z.string().default("processing") }).passthrough();
2599
+ var VocalAnimationJobSchema = import_zod3.z.object({
2600
+ status: import_zod3.z.string(),
2601
+ mood: import_zod3.z.string().optional(),
2602
+ viseme_count: import_zod3.z.number().optional(),
2603
+ character_id: import_zod3.z.string().nullable().optional(),
2604
+ completed_visemes: import_zod3.z.array(import_zod3.z.string()).default([]),
2605
+ visemes: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.object({ base64: import_zod3.z.string().min(1) }).passthrough()).nullable().optional(),
2606
+ moods_on_character: import_zod3.z.array(import_zod3.z.string()).nullable().optional(),
2607
+ grid_url: import_zod3.z.string().nullable().optional(),
2608
+ viseme_order: import_zod3.z.array(import_zod3.z.string()).nullable().optional(),
2609
+ usage: import_zod3.z.unknown().optional()
2610
+ }).passthrough();
2611
+ var TalkingGifSchema = import_zod3.z.object({
2612
+ gif_base64: import_zod3.z.string().min(1),
2613
+ frames: import_zod3.z.number(),
2614
+ duration_ms: import_zod3.z.number(),
2615
+ frame_ms: import_zod3.z.number(),
2616
+ hold_ms: import_zod3.z.number(),
2617
+ width: import_zod3.z.number(),
2618
+ height: import_zod3.z.number(),
2619
+ mood: import_zod3.z.string().nullable().optional()
2620
+ }).passthrough();
2621
+ var LipSyncSchema = import_zod3.z.object({
2622
+ text: import_zod3.z.string(),
2623
+ total_ms: import_zod3.z.number(),
2624
+ viseme_order: import_zod3.z.array(import_zod3.z.string()),
2625
+ frames: import_zod3.z.array(import_zod3.z.object({ viseme: import_zod3.z.string(), column: import_zod3.z.number(), duration_ms: import_zod3.z.number(), text_offset: import_zod3.z.number() }).passthrough()),
2626
+ mood: import_zod3.z.string().nullable().optional(),
2627
+ grid_url: import_zod3.z.string().nullable().optional(),
2628
+ row: import_zod3.z.number().nullable().optional(),
2629
+ rows: import_zod3.z.number().nullable().optional()
2630
+ }).passthrough();
2553
2631
  var ExpandRotationsSchema = import_zod3.z.object({
2554
2632
  object_id: import_zod3.z.string().min(1),
2555
2633
  background_job_id: import_zod3.z.string().min(1),
@@ -4129,6 +4207,8 @@ var PixelLabClient = class {
4129
4207
  const body = { description: args.description };
4130
4208
  if (args.artist) body.artist = args.artist;
4131
4209
  if (args.sprite) body.sprite = { type: "base64", base64: args.sprite.base64, format: args.sprite.format };
4210
+ if (args.sprite && args.spriteFrames != null && args.spriteFrames > 1) body.sprite_frames = args.spriteFrames;
4211
+ if (args.sprite && args.spriteFps != null) body.sprite_fps = args.spriteFps;
4132
4212
  if (args.effectId) body.effect_id = args.effectId;
4133
4213
  if (args.conversation) body.conversation = args.conversation;
4134
4214
  if (args.name) body.name = args.name;
@@ -4273,6 +4353,108 @@ var PixelLabClient = class {
4273
4353
  "objects/import"
4274
4354
  );
4275
4355
  }
4356
+ /**
4357
+ * `POST /vocal-animation`: one expression's mouth positions for a portrait,
4358
+ * from an image (nothing stored; the frames come back inline) or from a
4359
+ * character's stored portrait (saved onto it). Paid; `pixminimax` costs 3
4360
+ * generations for 7 positions at any size, `v3` 3 to 24 by size.
4361
+ */
4362
+ async createVocalAnimation(args) {
4363
+ const body = {};
4364
+ if (args.portrait) body.portrait = { type: "base64", base64: args.portrait.base64, format: args.portrait.format };
4365
+ if (args.characterId) body.character_id = args.characterId;
4366
+ if (args.mood) body.mood = args.mood;
4367
+ if (args.visemeCount != null) body.viseme_count = args.visemeCount;
4368
+ if (args.engine) body.engine = args.engine;
4369
+ if (args.seed != null) body.seed = args.seed;
4370
+ return validateResponse(
4371
+ VocalAnimationSubmitSchema,
4372
+ await this.request("/vocal-animation", { method: "POST", body: JSON.stringify(body) }),
4373
+ "vocal-animation"
4374
+ );
4375
+ }
4376
+ /** `GET /vocal-animation/{job}`: the job's status, and its mouth positions once completed. Its bill is on `getBackgroundJob`. */
4377
+ async getVocalAnimation(jobId) {
4378
+ return validateResponse(VocalAnimationJobSchema, await this.request(`/vocal-animation/${encodeURIComponent(jobId)}`), "vocal-animation/{job}");
4379
+ }
4380
+ /** `POST /talking-gif`: a line of text lip-synced to a GIF from mouth positions already made. Free; answers at once. */
4381
+ async createTalkingGif(args) {
4382
+ const body = { text: args.text };
4383
+ if (args.visemes) {
4384
+ body.visemes = Object.fromEntries(Object.entries(args.visemes).map(([id, image]) => [id, { type: "base64", base64: image.base64, format: image.format }]));
4385
+ }
4386
+ if (args.characterId) body.character_id = args.characterId;
4387
+ if (args.mood) body.mood = args.mood;
4388
+ if (args.frameMs != null) body.frame_ms = args.frameMs;
4389
+ if (args.holdMs != null) body.hold_ms = args.holdMs;
4390
+ return validateResponse(TalkingGifSchema, await this.request("/talking-gif", { method: "POST", body: JSON.stringify(body) }), "talking-gif");
4391
+ }
4392
+ /** `POST /lip-sync`: which mouth position to show and for how long, for a line of text. Free; nothing is rendered. */
4393
+ async getLipSync(args) {
4394
+ const body = { text: args.text };
4395
+ if (args.characterId) body.character_id = args.characterId;
4396
+ if (args.mood) body.mood = args.mood;
4397
+ if (args.visemeCount != null) body.viseme_count = args.visemeCount;
4398
+ if (args.frameMs != null) body.frame_ms = args.frameMs;
4399
+ if (args.holdMs != null) body.hold_ms = args.holdMs;
4400
+ return validateResponse(LipSyncSchema, await this.request("/lip-sync", { method: "POST", body: JSON.stringify(body) }), "lip-sync");
4401
+ }
4402
+ /**
4403
+ * `POST /tilesets/import`: your own Wang sheet as a completed tileset, in
4404
+ * PixelLab's compact 4x4 layout or its 8-wide native one. Free. Send
4405
+ * `tileSize` whenever the sheet reads two ways: omitted, PixelLab takes the
4406
+ * 4x4 reading and cuts a native sheet into the wrong tiles.
4407
+ */
4408
+ async importTileset(args) {
4409
+ const body = {
4410
+ spritesheet: { type: "base64", base64: args.spritesheet.base64, format: args.spritesheet.format }
4411
+ };
4412
+ if (args.mode) body.tileset_mode = args.mode;
4413
+ if (args.tileSize != null) body.tile_size = { width: args.tileSize, height: args.tileSize };
4414
+ if (args.lowerDescription) body.lower_description = args.lowerDescription;
4415
+ if (args.upperDescription) body.upper_description = args.upperDescription;
4416
+ if (args.transitionDescription) body.transition_description = args.transitionDescription;
4417
+ if (args.name) body.name = args.name;
4418
+ return validateResponse(
4419
+ ImportTilesetSchema,
4420
+ await this.request("/tilesets/import", { method: "POST", body: JSON.stringify(body) }),
4421
+ "tilesets/import"
4422
+ );
4423
+ }
4424
+ /** `POST /tiles-pro/import`: 1 to 32 of your own tile PNGs as one completed tile group. Free. */
4425
+ async importTilesPro(args) {
4426
+ const body = {
4427
+ frames: args.frames.map((frame) => ({ type: "base64", base64: frame.base64, format: frame.format })),
4428
+ tile_type: args.tileType,
4429
+ tile_size: args.tileSize
4430
+ };
4431
+ if (args.description) body.description = args.description;
4432
+ if (args.tileView) body.tile_view = args.tileView;
4433
+ return validateResponse(
4434
+ ImportTilesProSchema,
4435
+ await this.request("/tiles-pro/import", { method: "POST", body: JSON.stringify(body) }),
4436
+ "tiles-pro/import"
4437
+ );
4438
+ }
4439
+ /**
4440
+ * `POST /save-to-asset`: write edited pixels back into a stored character
4441
+ * or object rotation, one direction of an animation, a gallery image or a
4442
+ * tileset sheet, or add a new gallery image (`gallery:new`). Free. The
4443
+ * image must match what it replaces in size and frame count. What was
4444
+ * there comes back as `previous_frames`; saving those again is the undo.
4445
+ */
4446
+ async saveToAsset(args) {
4447
+ const body = { target: args.target };
4448
+ if (args.image) body.image = { type: "base64", base64: args.image.base64, format: args.image.format };
4449
+ if (args.frames) body.frames = args.frames.map((frame) => ({ type: "base64", base64: frame.base64, format: frame.format }));
4450
+ if (args.name) body.name = args.name;
4451
+ if (args.description) body.description = args.description;
4452
+ return validateResponse(
4453
+ SaveToAssetSchema,
4454
+ await this.request("/save-to-asset", { method: "POST", body: JSON.stringify(body) }),
4455
+ "save-to-asset"
4456
+ );
4457
+ }
4276
4458
  /**
4277
4459
  * `POST /objects/{id}/expand-rotations`: draw the 7 missing directions of a
4278
4460
  * 1-direction object. The object then waits in `review-expansion` until
@@ -5243,7 +5425,11 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
5243
5425
  fps: spec.vfx.fps,
5244
5426
  sprite: spec.vfx.sprite ? "reference" in spec.vfx.sprite ? spec.vfx.sprite.reference : spec.vfx.sprite.sha256 : void 0,
5245
5427
  description: spec.vfx.description,
5246
- artist: spec.vfx.description ? spec.vfx.artist : void 0
5428
+ artist: spec.vfx.description ? spec.vfx.artist : void 0,
5429
+ // Absent for a still sprite, so every effect made before strips
5430
+ // existed keeps its hash.
5431
+ spriteFrames: spec.vfx.spriteFrames,
5432
+ spriteFps: spec.vfx.spriteFps
5247
5433
  } : void 0,
5248
5434
  // A mirror's bytes come from its source's recorded outputs; the plan
5249
5435
  // compares those directly, so only the choice of source is identity.
@@ -5663,27 +5849,64 @@ async function makeVfx(client2, opts) {
5663
5849
  }
5664
5850
  var VFX_ARTISTS = ["lite", "pro"];
5665
5851
  var VFX_ARTIST_MAX_SPRITE = 512;
5666
- function vfxArtistQuote(artist, sprite, change = false) {
5852
+ function vfxArtistQuote(artist, sprite, change = false, animated = false) {
5667
5853
  const table = {
5668
5854
  lite: { new: [1, 1, 3, 5], change: [1, 1, 2, 2] },
5669
5855
  pro: { new: [6, 8, 14, 28], change: [4, 4, 5, 8] }
5670
5856
  };
5671
5857
  const tier = sprite === "none" ? 0 : sprite === "unknown" ? 3 : sprite <= 128 ? 1 : sprite <= 256 ? 2 : 3;
5672
- return table[artist][change ? "change" : "new"][tier];
5858
+ const base = table[artist][change ? "change" : "new"][tier];
5859
+ return animated && tier > 0 ? base + VFX_ARTIST_ANIMATED_EXTRA[artist][tier - 1] : base;
5673
5860
  }
5861
+ var VFX_ARTIST_ANIMATED_EXTRA = { lite: [1, 1, 1], pro: [1, 2, 5] };
5862
+ var VFX_ARTIST_MAX_FRAMES = 32;
5863
+ var VFX_ARTIST_MAX_STRIP = 1024;
5674
5864
  function vfxArtistCeiling(quote) {
5675
5865
  return quote * 2;
5676
5866
  }
5677
- function vfxArtistSprite(bytes, label) {
5678
- const metadata = imageMetadata(bytes);
5679
- if (metadata?.format !== "png") throw new Error(`${label}: PixelLab's VFX artist takes a PNG sprite`);
5680
- const side = Math.max(metadata.width, metadata.height);
5867
+ function gifSize(bytes) {
5868
+ if (bytes.length < 10) return null;
5869
+ const magic = bytes.toString("ascii", 0, 6);
5870
+ if (magic !== "GIF87a" && magic !== "GIF89a") return null;
5871
+ return { width: bytes.readUInt16LE(6), height: bytes.readUInt16LE(8) };
5872
+ }
5873
+ function vfxArtistFrameSide(width, height, frames, label) {
5874
+ if (!Number.isInteger(frames) || frames < 1 || frames > VFX_ARTIST_MAX_FRAMES) {
5875
+ throw new Error(`${label}: a sprite strip holds 1 to ${VFX_ARTIST_MAX_FRAMES} frames, got ${frames}`);
5876
+ }
5877
+ if (width % frames !== 0) {
5878
+ throw new Error(`${label} is ${width}px wide, which does not divide into ${frames} equal frames`);
5879
+ }
5880
+ if (frames > 1 && width > VFX_ARTIST_MAX_STRIP) {
5881
+ throw new Error(
5882
+ `${label} is a ${width}px-wide strip; PixelLab's VFX artist takes a strip up to ${VFX_ARTIST_MAX_STRIP}px wide. Send fewer frames, or the animation as a GIF`
5883
+ );
5884
+ }
5885
+ const frameWidth = width / frames;
5886
+ const side = Math.max(frameWidth, height);
5681
5887
  if (side > VFX_ARTIST_MAX_SPRITE) {
5682
5888
  throw new Error(
5683
- `${label} is ${metadata.width}x${metadata.height}; PixelLab's VFX artist takes up to ${VFX_ARTIST_MAX_SPRITE}x${VFX_ARTIST_MAX_SPRITE} (crop or pad it; never rescale pixel art)`
5889
+ `${label} is ${frameWidth}x${height}${frames > 1 ? " a frame" : ""}; PixelLab's VFX artist takes up to ${VFX_ARTIST_MAX_SPRITE}x${VFX_ARTIST_MAX_SPRITE} (crop or pad it; never rescale pixel art)`
5684
5890
  );
5685
5891
  }
5686
- return { image: { base64: bytes.toString("base64"), format: "png" }, side };
5892
+ return side;
5893
+ }
5894
+ function vfxArtistSprite(bytes, label, frames = 1) {
5895
+ const gif = gifSize(bytes);
5896
+ if (gif) {
5897
+ if (frames !== 1) throw new Error(`${label} is a GIF, which brings its own frames; drop the frame count`);
5898
+ const side2 = Math.max(gif.width, gif.height);
5899
+ if (side2 > VFX_ARTIST_MAX_SPRITE) {
5900
+ throw new Error(
5901
+ `${label} is ${gif.width}x${gif.height}; PixelLab's VFX artist takes up to ${VFX_ARTIST_MAX_SPRITE}x${VFX_ARTIST_MAX_SPRITE} (crop or pad it; never rescale pixel art)`
5902
+ );
5903
+ }
5904
+ return { image: { base64: bytes.toString("base64"), format: "gif" }, side: side2, animated: true };
5905
+ }
5906
+ const metadata = imageMetadata(bytes);
5907
+ if (metadata?.format !== "png") throw new Error(`${label}: PixelLab's VFX artist takes a PNG or GIF sprite`);
5908
+ const side = vfxArtistFrameSide(metadata.width, metadata.height, frames, label);
5909
+ return { image: { base64: bytes.toString("base64"), format: "png" }, side, animated: frames > 1 };
5687
5910
  }
5688
5911
  function vfxArtistFiles(raw) {
5689
5912
  const urlOf = (value) => {
@@ -5768,7 +5991,7 @@ async function makeVfxWithArtist(client2, opts) {
5768
5991
  }
5769
5992
  const progress = opts.onProgress ?? (() => {
5770
5993
  });
5771
- const sprite = opts.sprite ? vfxArtistSprite(await (0, import_promises.readFile)(opts.sprite), opts.sprite).image : void 0;
5994
+ const sprite = opts.sprite ? vfxArtistSprite(await (0, import_promises.readFile)(opts.sprite), opts.sprite, opts.spriteFrames ?? 1).image : void 0;
5772
5995
  const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
5773
5996
  const interval = opts.intervalMs ?? 6e3;
5774
5997
  const timeout = opts.timeoutMs ?? 10 * 6e4;
@@ -5776,6 +5999,8 @@ async function makeVfxWithArtist(client2, opts) {
5776
5999
  description: opts.description,
5777
6000
  artist: opts.artist,
5778
6001
  sprite,
6002
+ spriteFrames: sprite ? opts.spriteFrames : void 0,
6003
+ spriteFps: sprite ? opts.spriteFps : void 0,
5779
6004
  effectId: opts.effect,
5780
6005
  conversation: opts.effect ? opts.conversation : void 0,
5781
6006
  name: opts.name,
@@ -5833,6 +6058,8 @@ async function makeVfxWithArtist(client2, opts) {
5833
6058
  message: result.message,
5834
6059
  source: {
5835
6060
  ...opts.sprite ? { sprite: import_node_path.default.relative(import_node_path.default.dirname(paths.provenance), import_node_path.default.resolve(opts.sprite)).split(import_node_path.default.sep).join("/") } : {},
6061
+ ...opts.sprite && opts.spriteFrames && opts.spriteFrames > 1 ? { spriteFrames: opts.spriteFrames } : {},
6062
+ ...opts.sprite && opts.spriteFps ? { spriteFps: opts.spriteFps } : {},
5836
6063
  ...opts.effect ? { changed: opts.effect } : {}
5837
6064
  },
5838
6065
  ...facts,
@@ -6176,8 +6403,9 @@ function pixelLabObjectUrl(generator, objectId) {
6176
6403
  }
6177
6404
  function vfxArtistSpecQuote(spec) {
6178
6405
  const sprite = spec.vfx?.sprite;
6179
- const side = !sprite ? "none" : "file" in sprite && sprite.width != null && sprite.height != null ? Math.max(sprite.width, sprite.height) : "unknown";
6180
- return vfxArtistQuote(spec.vfx?.artist ?? "lite", side);
6406
+ const frames = spec.vfx?.spriteFrames ?? 1;
6407
+ const side = !sprite ? "none" : "file" in sprite && sprite.width != null && sprite.height != null ? Math.max(Math.ceil(sprite.width / frames), sprite.height) : "unknown";
6408
+ return vfxArtistQuote(spec.vfx?.artist ?? "lite", side, false, frames > 1);
6181
6409
  }
6182
6410
  function workbenchVfxUrls(exported) {
6183
6411
  const sheetFile = exported.files.find((file) => /\.png$/i.test(file));
@@ -8210,11 +8438,20 @@ var PixelLabProvider = class _PixelLabProvider {
8210
8438
  if (sha256(bytes) !== vfx.sprite.sha256) {
8211
8439
  throw new Error(`vfx sprite changed after the manifest was resolved: ${file}; run the command again`);
8212
8440
  }
8213
- sprite = vfxArtistSprite(bytes, `vfx sprite ${file}`).image;
8441
+ const taken = vfxArtistSprite(bytes, `vfx sprite ${file}`, vfx.spriteFrames ?? 1).image;
8442
+ if (taken.format !== "png") throw new Error(`vfx sprite must be a PNG: ${file}`);
8443
+ sprite = { base64: taken.base64, format: "png" };
8214
8444
  }
8215
8445
  const previous = context?.replacedMetadata?.vfx ?? context?.lastGenerationMetadata?.vfx;
8216
8446
  const artist = vfx.artist ?? "lite";
8217
- const submitted = await this.client.createVfx({ description: vfx.description, artist, sprite, name: vfx.name });
8447
+ const submitted = await this.client.createVfx({
8448
+ description: vfx.description,
8449
+ artist,
8450
+ sprite,
8451
+ spriteFrames: vfx.spriteFrames,
8452
+ spriteFps: vfx.spriteFps,
8453
+ name: vfx.name
8454
+ });
8218
8455
  return {
8219
8456
  jobId: submitted.background_job_id,
8220
8457
  metadata: {
@@ -12821,6 +13058,9 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
12821
13058
  } else if (spriteRef) {
12822
13059
  const image = await optionalRevisionImage(spriteRef, `assets.${assetId}.vfx.sprite`, vfx.description ? "png" : void 0);
12823
13060
  sprite = { file: spriteRef, sha256: image?.hash ?? null, width: image?.width ?? null, height: image?.height ?? null, format: image?.format ?? null };
13061
+ if (image && vfx.description && (vfx.spriteFrames ?? 1) > 1) {
13062
+ vfxArtistFrameSide(image.width, image.height, vfx.spriteFrames, `assets.${assetId}.vfx.sprite`);
13063
+ }
12824
13064
  }
12825
13065
  return {
12826
13066
  ...vfx.preset ? { preset: vfx.preset } : {},
@@ -12830,7 +13070,10 @@ async function resolveVfxShape(root, assetId, vfx, defaultName) {
12830
13070
  ...vfx.fps !== void 0 ? { fps: vfx.fps } : {},
12831
13071
  // The artist caps a name at 80 characters; a long default is cut, not refused.
12832
13072
  name: vfx.name ?? (vfx.description ? defaultName.slice(0, 80) : defaultName),
12833
- ...vfx.description ? { description: vfx.description, artist: vfx.artist ?? "lite" } : {}
13073
+ ...vfx.description ? { description: vfx.description, artist: vfx.artist ?? "lite" } : {},
13074
+ // A strip of one frame is a still: it is sent, priced and hashed as one.
13075
+ ...vfx.spriteFrames !== void 0 && vfx.spriteFrames > 1 ? { spriteFrames: vfx.spriteFrames } : {},
13076
+ ...vfx.spriteFps !== void 0 ? { spriteFps: vfx.spriteFps } : {}
12834
13077
  };
12835
13078
  }
12836
13079
  async function optionalRevisionImage(file, label, requiredFormat) {
@@ -16303,6 +16546,172 @@ async function pullExpansionReview(client2, id, opts) {
16303
16546
  }
16304
16547
  return { dir, existingDirection: review.existing_direction ?? null, files };
16305
16548
  }
16549
+ var TILESET_MODES = ["topdown", "sidescroller"];
16550
+ var IMPORT_TILE_TYPES = ["square_topdown", "isometric", "oblique", "hex", "hex_pointy", "octagon"];
16551
+ var IMPORT_TILE_VIEWS = ["top-down", "high top-down", "low top-down", "side"];
16552
+ var SHEET_TILE_SIZES = [16, 24, 32, 48, 64];
16553
+ var IMPORT_MAX_TILES = 32;
16554
+ function tilesetSheetReadings(width, height) {
16555
+ if (height !== width && height !== width * 2) return [];
16556
+ const readings = [];
16557
+ if (SHEET_TILE_SIZES.includes(width / 4)) readings.push({ tileSize: width / 4, layout: "compact" });
16558
+ if (SHEET_TILE_SIZES.includes(width / 8)) readings.push({ tileSize: width / 8, layout: "native" });
16559
+ return readings;
16560
+ }
16561
+ function chooseTilesetSheetReading(file, width, height, tileSize) {
16562
+ const readings = tilesetSheetReadings(width, height);
16563
+ const describe = (reading) => `${reading.tileSize}px tiles (${reading.layout === "compact" ? "4 wide" : "8 wide"})`;
16564
+ if (readings.length === 0) {
16565
+ throw new Error(
16566
+ `${file} is ${width}x${height}, not a PixelLab tileset sheet: it takes a square sheet 4 or 8 tiles wide (or twice as tall, for a set with transitions) of 16, 24, 32, 48 or 64px tiles`
16567
+ );
16568
+ }
16569
+ if (tileSize === void 0) {
16570
+ if (readings.length > 1) {
16571
+ throw new Error(
16572
+ `${file} is ${width}x${height}, which reads as ${readings.map(describe).join(" or ")}; say which with --size ${readings.map((reading) => reading.tileSize).join(" or --size ")}`
16573
+ );
16574
+ }
16575
+ return readings[0];
16576
+ }
16577
+ const chosen = readings.find((reading) => reading.tileSize === tileSize);
16578
+ if (!chosen) throw new Error(`${file} is ${width}x${height}, which holds ${readings.map(describe).join(" or ")}, not ${tileSize}px tiles`);
16579
+ return chosen;
16580
+ }
16581
+ function readPng(bytes, file) {
16582
+ const metadata = imageMetadata(bytes);
16583
+ if (!metadata || metadata.format !== "png") throw new Error(`${file} is not a PNG`);
16584
+ return metadata;
16585
+ }
16586
+ async function importTilesetFile(client2, file, opts = {}) {
16587
+ const bytes = await (0, import_promises14.readFile)(file);
16588
+ const { width, height } = readPng(bytes, file);
16589
+ const reading = chooseTilesetSheetReading(file, width, height, opts.tileSize);
16590
+ const mode2 = opts.mode ?? "topdown";
16591
+ if (mode2 === "sidescroller" && opts.upperDescription) throw new Error("a sidescroller tileset has one terrain, the platform; drop the upper description");
16592
+ const res = await client2.importTileset({
16593
+ spritesheet: { base64: bytes.toString("base64"), format: "png" },
16594
+ mode: mode2,
16595
+ // PixelLab cannot be told 48, and a 4-wide reading is the one it takes unprompted.
16596
+ tileSize: reading.tileSize === 48 ? void 0 : reading.tileSize,
16597
+ lowerDescription: opts.lowerDescription,
16598
+ upperDescription: opts.upperDescription,
16599
+ transitionDescription: opts.transitionDescription,
16600
+ name: opts.name
16601
+ });
16602
+ return { tilesetId: res.tileset_id, mode: mode2, tileSize: reading.tileSize, layout: reading.layout };
16603
+ }
16604
+ async function pngFilesAt(from) {
16605
+ if (!(0, import_node_fs20.existsSync)(from)) throw new Error(`${from} does not exist`);
16606
+ if (!(await (0, import_promises14.stat)(from)).isDirectory()) return [from];
16607
+ const names = (await (0, import_promises14.readdir)(from)).filter((name) => /\.png$/i.test(name)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
16608
+ if (names.length === 0) throw new Error(`${from} holds no PNG files`);
16609
+ return names.map((name) => import_node_path23.default.join(from, name));
16610
+ }
16611
+ function importTileHeights(tileType, tileSize) {
16612
+ if (tileType === "square_topdown" || tileType === "octagon") return { min: tileSize, max: tileSize };
16613
+ if (tileType === "oblique") return { min: tileSize, max: tileSize * 2 };
16614
+ return { min: tileSize / 2, max: tileSize * 2 };
16615
+ }
16616
+ async function importTilesFiles(client2, from, opts) {
16617
+ if (!IMPORT_TILE_TYPES.includes(opts.tileType)) throw new Error(`tile type must be one of ${IMPORT_TILE_TYPES.join(", ")}`);
16618
+ if (!Number.isInteger(opts.tileSize) || opts.tileSize < 16 || opts.tileSize > 256) throw new Error("tile size is a whole number from 16 to 256");
16619
+ const files = await pngFilesAt(from);
16620
+ if (files.length > IMPORT_MAX_TILES) throw new Error(`${from} holds ${files.length} PNGs; PixelLab imports at most ${IMPORT_MAX_TILES} tiles in one group`);
16621
+ const heights = importTileHeights(opts.tileType, opts.tileSize);
16622
+ const frames = [];
16623
+ for (const file of files) {
16624
+ const bytes = await (0, import_promises14.readFile)(file);
16625
+ const { width, height } = readPng(bytes, file);
16626
+ if (width !== opts.tileSize || height < heights.min || height > heights.max) {
16627
+ const tall = heights.min === heights.max ? `${heights.min}` : `${heights.min} to ${heights.max}`;
16628
+ throw new Error(`${file} is ${width}x${height}; a ${opts.tileSize}px ${opts.tileType} tile is ${opts.tileSize} wide and ${tall} tall`);
16629
+ }
16630
+ frames.push({ base64: bytes.toString("base64"), format: "png" });
16631
+ }
16632
+ const res = await client2.importTilesPro({ frames, tileType: opts.tileType, tileSize: opts.tileSize, description: opts.description, tileView: opts.tileView });
16633
+ return { tileId: res.tile_id, tiles: files.length, files };
16634
+ }
16635
+ function checkSaveTarget(target) {
16636
+ if (!/^(character:[^:]+:[^:]+(:[^:]+)?|object:[^:]+(:[^:]+){0,2}|gallery:[^:]+|tileset:[^:]+)$/.test(target)) {
16637
+ throw new Error(
16638
+ `--target "${target}" is not a place PixelLab can save to. Use character:<id>:<direction>, object:<id>[:<direction>], either with :<animation group id> added, gallery:<id>, gallery:new, or tileset:<id>`
16639
+ );
16640
+ }
16641
+ }
16642
+ function saveUndoDir(target, now = /* @__PURE__ */ new Date()) {
16643
+ const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
16644
+ return import_node_path23.default.resolve("pixelkiln-undo", `${target.replace(/[^a-zA-Z0-9-]+/g, "_")}-${stamp}`);
16645
+ }
16646
+ async function writeUndo(frames, dir) {
16647
+ await (0, import_promises14.mkdir)(dir, { recursive: true });
16648
+ const files = [];
16649
+ for (const [index, frame] of frames.entries()) {
16650
+ const file = import_node_path23.default.join(dir, frames.length === 1 ? "previous.png" : `previous-${String(index).padStart(2, "0")}.png`);
16651
+ await (0, import_promises14.writeFile)(file, Buffer.from(frame.base64, "base64"));
16652
+ files.push(file);
16653
+ }
16654
+ return files;
16655
+ }
16656
+ async function saveToAssetFile(client2, target, from, opts = {}) {
16657
+ checkSaveTarget(target);
16658
+ 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");
16659
+ const files = await pngFilesAt(from).catch(async (error) => {
16660
+ if ((0, import_node_fs20.existsSync)(from) && /\.gif$/i.test(from)) return [from];
16661
+ throw error;
16662
+ });
16663
+ let image;
16664
+ let frames;
16665
+ if (files.length === 1) {
16666
+ const bytes = await (0, import_promises14.readFile)(files[0]);
16667
+ const gif = bytes.subarray(0, 4).toString("ascii") === "GIF8";
16668
+ if (!gif) readPng(bytes, files[0]);
16669
+ image = { base64: bytes.toString("base64"), format: gif ? "gif" : "png" };
16670
+ } else {
16671
+ if (files.length > 128) throw new Error(`${from} holds ${files.length} PNGs; PixelLab takes at most 128 frames`);
16672
+ let size;
16673
+ frames = [];
16674
+ for (const file of files) {
16675
+ const bytes = await (0, import_promises14.readFile)(file);
16676
+ const { width, height } = readPng(bytes, file);
16677
+ 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`);
16678
+ size = `${width}x${height}`;
16679
+ frames.push({ base64: bytes.toString("base64"), format: "png" });
16680
+ }
16681
+ }
16682
+ const undoDir = opts.undoDir ? import_node_path23.default.resolve(opts.undoDir) : saveUndoDir(target);
16683
+ let res;
16684
+ try {
16685
+ res = await client2.saveToAsset({ target, image, frames, name: opts.name, description: opts.description });
16686
+ } catch (error) {
16687
+ if (error instanceof PixelLabError && error.body.startsWith("{")) {
16688
+ let previous;
16689
+ try {
16690
+ previous = JSON.parse(error.body).detail?.previous_frames;
16691
+ } catch {
16692
+ previous = void 0;
16693
+ }
16694
+ if (Array.isArray(previous) && previous.length && previous.every((frame) => typeof frame?.base64 === "string")) {
16695
+ const written = await writeUndo(previous, undoDir);
16696
+ throw new Error(`${error.message}. The save failed partway; what was stored before is in ${undoDir} (${written.length} frame(s)). Save it back to ${target} to restore it`);
16697
+ }
16698
+ }
16699
+ throw error;
16700
+ }
16701
+ const undo = res.action === "saved" && res.previous_frames?.length ? await writeUndo(res.previous_frames, undoDir) : [];
16702
+ return {
16703
+ action: res.action,
16704
+ target: res.target,
16705
+ kind: res.kind,
16706
+ width: res.width,
16707
+ height: res.height,
16708
+ frames: res.frame_count,
16709
+ changedPixels: res.changed_pixels,
16710
+ undo,
16711
+ note: res.note ?? null,
16712
+ maps: res.maps ?? null
16713
+ };
16714
+ }
16306
16715
 
16307
16716
  // src/pipeline/quality-regression.ts
16308
16717
  var import_node_path24 = __toESM(require("path"), 1);
@@ -23665,6 +24074,9 @@ async function workspaceStatus(ws, dir) {
23665
24074
  HISTORY_ENV,
23666
24075
  HandEditCompanionSchema,
23667
24076
  IMPORT_MAX_SIDE,
24077
+ IMPORT_MAX_TILES,
24078
+ IMPORT_TILE_TYPES,
24079
+ IMPORT_TILE_VIEWS,
23668
24080
  ImageQualityMetricsSchema,
23669
24081
  InheritedStyleSchema,
23670
24082
  LockEntrySchema,
@@ -23733,6 +24145,7 @@ async function workspaceStatus(ws, dir) {
23733
24145
  StyleInputSchema,
23734
24146
  StyleSchema,
23735
24147
  TARGET_PALETTE_GENERATORS,
24148
+ TILESET_MODES,
23736
24149
  TerrainConnectSchema,
23737
24150
  TerrainLinkSchema,
23738
24151
  TerrainSideSchema,
@@ -23747,7 +24160,10 @@ async function workspaceStatus(ws, dir) {
23747
24160
  UnsupportedCapabilityError,
23748
24161
  UsageError,
23749
24162
  VFX_ARTISTS,
24163
+ VFX_ARTIST_ANIMATED_EXTRA,
24164
+ VFX_ARTIST_MAX_FRAMES,
23750
24165
  VFX_ARTIST_MAX_SPRITE,
24166
+ VFX_ARTIST_MAX_STRIP,
23751
24167
  VFX_TOOL,
23752
24168
  VfxPartSchema,
23753
24169
  WorkspaceProjectSchema,
@@ -23772,7 +24188,9 @@ async function workspaceStatus(ws, dir) {
23772
24188
  checkExportBytes,
23773
24189
  checkQualityBaseline,
23774
24190
  checkQualityRecord,
24191
+ checkSaveTarget,
23775
24192
  checkUiInsets,
24193
+ chooseTilesetSheetReading,
23776
24194
  clientFromEnv,
23777
24195
  colorDistance,
23778
24196
  countNumberedDescriptions,
@@ -23821,6 +24239,7 @@ async function workspaceStatus(ws, dir) {
23821
24239
  generateMusic,
23822
24240
  generateSoundEffect,
23823
24241
  generationCost,
24242
+ gifSize,
23824
24243
  groupOrphansByStyle,
23825
24244
  handEditBase,
23826
24245
  handEditBases,
@@ -23835,6 +24254,9 @@ async function workspaceStatus(ws, dir) {
23835
24254
  imageMetadata,
23836
24255
  importLocal,
23837
24256
  importObjectFile,
24257
+ importTileHeights,
24258
+ importTilesFiles,
24259
+ importTilesetFile,
23838
24260
  inspectCaches,
23839
24261
  inspectQualityProfile,
23840
24262
  inspectRevisionReadiness,
@@ -23901,6 +24323,7 @@ async function workspaceStatus(ws, dir) {
23901
24323
  pickHistory,
23902
24324
  pixMiniMaxCost,
23903
24325
  pixelateFile,
24326
+ pngFilesAt,
23904
24327
  pngSize,
23905
24328
  poll,
23906
24329
  portableOutputPath,
@@ -23965,6 +24388,8 @@ async function workspaceStatus(ws, dir) {
23965
24388
  runVfxWorkbench,
23966
24389
  saveHandEdit,
23967
24390
  saveLock,
24391
+ saveToAssetFile,
24392
+ saveUndoDir,
23968
24393
  saveWorkspace,
23969
24394
  scanAssets,
23970
24395
  selectEntryOutput,
@@ -23995,6 +24420,7 @@ async function workspaceStatus(ws, dir) {
23995
24420
  tileFeatureOutputCount,
23996
24421
  tileVariationCount,
23997
24422
  tilesCost,
24423
+ tilesetSheetReadings,
23998
24424
  toPortablePath,
23999
24425
  totalSpend,
24000
24426
  uiElementCandidateCount,
@@ -24010,6 +24436,7 @@ async function workspaceStatus(ws, dir) {
24010
24436
  vfxArtistCeiling,
24011
24437
  vfxArtistFiles,
24012
24438
  vfxArtistFrameFacts,
24439
+ vfxArtistFrameSide,
24013
24440
  vfxArtistQuote,
24014
24441
  vfxArtistSprite,
24015
24442
  vfxAtlasFrames,