pixelkiln 0.119.0 → 0.121.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
@@ -757,7 +757,15 @@ var CharacterPortraitSizeSchema = import_zod.z.union([
757
757
  var CharacterPortraitSchema = import_zod.z.object({
758
758
  /** The base or state to portray, in the same style. */
759
759
  of: import_zod.z.string().min(1),
760
- size: CharacterPortraitSizeSchema.default(64)
760
+ size: CharacterPortraitSizeSchema.default(64),
761
+ /** PixelLab's seed for this portrait, in place of the style's `seed`. Part of its identity. */
762
+ seed: import_zod.z.number().int().min(0).optional(),
763
+ /**
764
+ * Attach the drawn portrait to the parent's PixelLab character record, as
765
+ * PixelLab's own app shows it (the default). `false` leaves that record as
766
+ * it is, for a character used elsewhere. Not part of the portrait's identity.
767
+ */
768
+ attach: import_zod.z.boolean().optional()
761
769
  }).strict();
762
770
  var MapScenePlacementSchema = import_zod.z.union([
763
771
  import_zod.z.object({ oval: import_zod.z.number().min(0.05).max(0.95) }).strict(),
@@ -9335,7 +9343,17 @@ var PixelLabProvider = class _PixelLabProvider {
9335
9343
  });
9336
9344
  return {
9337
9345
  jobId: res2.background_job_id,
9338
- metadata: { character: { kind: "portrait", parentCharacterId: parentId, backgroundJobId: res2.background_job_id } }
9346
+ metadata: {
9347
+ character: {
9348
+ kind: "portrait",
9349
+ parentCharacterId: parentId,
9350
+ backgroundJobId: res2.background_job_id,
9351
+ // PixelLab expires finished jobs within about a day, so the seed sent is kept here;
9352
+ // poll replaces it with the one the job reports using.
9353
+ ...spec.seed != null ? { seed: spec.seed } : {},
9354
+ ...character.portrait.attach ? {} : { attach: false }
9355
+ }
9356
+ }
9339
9357
  };
9340
9358
  }
9341
9359
  const animation = character.animation;
@@ -9509,16 +9527,21 @@ var PixelLabProvider = class _PixelLabProvider {
9509
9527
  const job = await this.client.getPortraitCharacterJob(jobId);
9510
9528
  if (job.status === "failed") return { status: "failed", error: "portrait generation failed upstream" };
9511
9529
  if (job.status !== "completed" || !job.download_url) return { status: "processing" };
9512
- if (meta?.parentCharacterId) {
9530
+ const attach = meta?.parentCharacterId && meta.attach !== false ? meta.parentCharacterId : null;
9531
+ if (attach) {
9513
9532
  const bytes = await this.client.download(job.download_url);
9514
- await this.client.setCharacterPortrait(meta.parentCharacterId, { base64: bytes.toString("base64"), format: "png" });
9533
+ await this.client.setCharacterPortrait(attach, { base64: bytes.toString("base64"), format: "png" });
9515
9534
  }
9535
+ const { billed, lastResponse } = await this.readFinishedJob(meta?.backgroundJobId);
9536
+ const seed = typeof lastResponse?.seed === "number" ? lastResponse.seed : meta?.seed;
9516
9537
  return {
9517
9538
  status: "ready",
9518
9539
  objectId: jobId,
9519
9540
  sourceUrl: job.download_url,
9520
9541
  sources: [{ url: job.download_url }],
9521
- billed: await this.billedForJob(meta?.backgroundJobId)
9542
+ billed,
9543
+ ...seed != null ? { metadata: { character: { ...meta, seed } } } : {},
9544
+ ...attach ? { note: `attached to character ${attach} on PixelLab` } : {}
9522
9545
  };
9523
9546
  } catch (err) {
9524
9547
  if (err instanceof PixelLabError && err.status === 423) return { status: "processing" };
@@ -10246,17 +10269,22 @@ var PixelLabProvider = class _PixelLabProvider {
10246
10269
  * known", not a failure worth surfacing.
10247
10270
  */
10248
10271
  async billedForJob(backgroundJobId) {
10249
- if (!backgroundJobId) return null;
10272
+ return (await this.readFinishedJob(backgroundJobId)).billed;
10273
+ }
10274
+ /** A finished background job's bill (see `billedForJob`) and its `last_response`, read once. */
10275
+ async readFinishedJob(backgroundJobId) {
10276
+ if (!backgroundJobId) return { billed: null, lastResponse: null };
10250
10277
  try {
10251
10278
  const job = await this.client.getBackgroundJob(backgroundJobId);
10279
+ const lastResponse = job.last_response ?? null;
10252
10280
  const nested = job.last_response?.billing_usage;
10253
10281
  for (const usage of [job.usage, nested]) {
10254
10282
  const billed = billedFromUsage(usage);
10255
- if (billed && !(billed.unit === "usd" && billed.amount === 0)) return billed;
10283
+ if (billed && !(billed.unit === "usd" && billed.amount === 0)) return { billed, lastResponse };
10256
10284
  }
10257
- return null;
10285
+ return { billed: null, lastResponse };
10258
10286
  } catch {
10259
- return null;
10287
+ return { billed: null, lastResponse: null };
10260
10288
  }
10261
10289
  }
10262
10290
  async poll(jobId, generator, context) {
@@ -14315,7 +14343,8 @@ async function resolveSpecs(loaded, filter) {
14315
14343
  outline: style.outline,
14316
14344
  shading: style.shading,
14317
14345
  detail: style.detail,
14318
- seed: style.seed,
14346
+ // A portrait may pin its own; it reaches the wire and the identity like the style's.
14347
+ seed: asset.portrait?.seed ?? style.seed,
14319
14348
  uiPieces: generator === "uiAsset" ? asset.pieces : void 0,
14320
14349
  uiElements: generator === "uiAsset" ? asset.elements : void 0,
14321
14350
  uiColorPalette: generator === "uiAsset" || generator === "uiElement" ? style.uiColorPalette : void 0,
@@ -15212,7 +15241,7 @@ async function resolveCharacterShape(asset, style, kind, files) {
15212
15241
  };
15213
15242
  }
15214
15243
  if (asset.portrait) {
15215
- shape.portrait = { size: asset.portrait.size };
15244
+ shape.portrait = { size: asset.portrait.size, attach: asset.portrait.attach ?? true };
15216
15245
  }
15217
15246
  if (asset.animation) {
15218
15247
  const animationMode = asset.animation.mode ?? (asset.animation.template ? "template" : "v3");
@@ -20562,6 +20591,13 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
20562
20591
  }
20563
20592
 
20564
20593
  // src/pipeline/connected-sets.ts
20594
+ function unmatchedRoleWarning(label, outputs, terrainTiles) {
20595
+ const roles = new Set(terrainTiles.flatMap((tile) => isRecord2(tile) && typeof tile.role === "string" ? [tile.role] : []));
20596
+ const missing = outputs.flatMap((output) => output.role && !roles.has(output.role) ? [output.role] : []);
20597
+ if (!missing.length) return null;
20598
+ const shown = missing.slice(0, 3).join(", ") + (missing.length > 3 ? `, and ${missing.length - 3} more` : "");
20599
+ return `${label}: ${missing.length} tile(s) have a role that is not in the lock's terrainTiles (${shown}), so their corners were taken by position and may be wrong; regenerate the set if it paints the wrong tiles`;
20600
+ }
20565
20601
  var key2 = (spec) => `${spec.styleId}/${spec.assetId}`;
20566
20602
  var SIDES = ["lower", "upper"];
20567
20603
  function connectedGroup(start, specs) {
@@ -20672,6 +20708,7 @@ function mergeConnectedTerrain(members, manifestDir) {
20672
20708
  names[index] = name;
20673
20709
  }
20674
20710
  const tiles = [];
20711
+ const warnings = [];
20675
20712
  const providerRules = {};
20676
20713
  for (const { spec, entry } of members) {
20677
20714
  const metadata = entry.providerMetadata?.[entry.provider];
@@ -20686,6 +20723,8 @@ function mergeConnectedTerrain(members, manifestDir) {
20686
20723
  if (spec.source && sourceIsStem(spec.source, entry, manifestDir)) {
20687
20724
  outputs = outputs.map((output) => ({ ...output, absolutePath: sourceOutputPath(spec.source, entry, output.index, manifestDir) }));
20688
20725
  }
20726
+ const warning = unmatchedRoleWarning(key2(spec), outputs, terrainTiles);
20727
+ if (warning) warnings.push(warning);
20689
20728
  for (const output of outputs) {
20690
20729
  const tile = (output.role ? terrainTiles.find((item) => isRecord2(item) && item.role === output.role) : void 0) ?? terrainTiles[output.index];
20691
20730
  if (!isRecord2(tile) || !isRecord2(tile.corners)) continue;
@@ -20703,7 +20742,7 @@ function mergeConnectedTerrain(members, manifestDir) {
20703
20742
  }
20704
20743
  }
20705
20744
  if (!tiles.length) throw new Error(`connected sets ${ids.join(", ")} have no tiles with corner data`);
20706
- return { assets: ids, terrains: names, tiles, tileType: members[0].spec.tileType, providerRules };
20745
+ return { assets: ids, terrains: names, tiles, tileType: members[0].spec.tileType, providerRules, warnings };
20707
20746
  }
20708
20747
  function tileCorners(rules, tile) {
20709
20748
  if (tile.corners) return tile.corners;
@@ -21246,13 +21285,16 @@ function exportTileset(entry, spec, options) {
21246
21285
  terrainRules && !normalizeTileRules(rawRules) ? terrainTileIndexes(metadata, outputs) : void 0,
21247
21286
  spec.tileType === "isometric" ? isometricFootprint(packed.png, frames) : null
21248
21287
  );
21288
+ const roleWarning = terrainRules && !normalizeTileRules(rawRules) && isRecord3(metadata) && Array.isArray(metadata.terrainTiles) ? unmatchedRoleWarning(`${spec.styleId}/${spec.assetId}`, outputs, metadata.terrainTiles) : null;
21289
+ const warnings = roleWarning ? [roleWarning] : [];
21249
21290
  if (options.format === "generic") {
21250
21291
  return {
21251
21292
  png: packed.png,
21252
21293
  extension: ".json",
21253
21294
  document: JSON.stringify(generic, null, 2) + "\n",
21254
21295
  generic,
21255
- sources: packed.sources
21296
+ sources: packed.sources,
21297
+ warnings
21256
21298
  };
21257
21299
  }
21258
21300
  assertUniformTiles(generic);
@@ -21276,7 +21318,7 @@ function exportTileset(entry, spec, options) {
21276
21318
  "godot export does not yet map edge/side adjacency onto an oblique tile's diagonal peering bits safely; use --format generic or --format tiled"
21277
21319
  );
21278
21320
  }
21279
- return renderTileset(generic, packed, spec.tileType, options);
21321
+ return { ...renderTileset(generic, packed, spec.tileType, options), warnings };
21280
21322
  }
21281
21323
  function terrainTileIndexes(metadata, outputs) {
21282
21324
  const tiles = isRecord3(metadata) && Array.isArray(metadata.terrainTiles) ? metadata.terrainTiles : [];
@@ -21350,11 +21392,12 @@ function exportMergedTilesets(members, options) {
21350
21392
  extension: ".json",
21351
21393
  document: JSON.stringify(generic, null, 2) + "\n",
21352
21394
  generic,
21353
- sources: packed.sources
21395
+ sources: packed.sources,
21396
+ warnings: merged.warnings
21354
21397
  };
21355
21398
  }
21356
21399
  assertUniformTiles(generic);
21357
- return renderTileset(generic, packed, merged.tileType, options);
21400
+ return { ...renderTileset(generic, packed, merged.tileType, options), warnings: merged.warnings };
21358
21401
  }
21359
21402
  function isometricFootprint(png, frames) {
21360
21403
  const image = decodePng(png);
@@ -22153,7 +22196,7 @@ async function poll(provider, lock, lockPath, opts = {}) {
22153
22196
  billed: state.billed ?? entry.billed
22154
22197
  });
22155
22198
  result.completed++;
22156
- log(` ready ${key3}`);
22199
+ log(` ready ${key3}${state.note ? ` (${state.note})` : ""}`);
22157
22200
  } else if (state.status === "failed") {
22158
22201
  upsert(lock, key3, { status: "failed", error: state.error });
22159
22202
  result.failed++;