pixelkiln 0.97.0 → 0.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1330,6 +1330,21 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
1330
1330
  terrainBoundarySeed: spec.terrainBoundarySeed,
1331
1331
  terrainStepSlope: spec.terrainStepSlope,
1332
1332
  terrainConnectDiagonals: spec.terrainConnectDiagonals,
1333
+ // Added after the fields above, each only when set, so no terrain entry
1334
+ // written before them changes hash. The walkable flags change no pixel
1335
+ // and are deliberately not here.
1336
+ terrainShapeSeed: spec.terrainShapeSeed,
1337
+ terrainSideWallThickness: spec.terrainSideWallThickness,
1338
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
1339
+ terrainEnhance: spec.terrainEnhance,
1340
+ terrainPlatformThickness: spec.terrainPlatformThickness,
1341
+ // Reference images enter as their bytes' hashes, never their paths.
1342
+ terrainReferences: spec.terrainReferences && Object.keys(spec.terrainReferences).length ? Object.fromEntries(
1343
+ ["lower", "upper", "transition"].flatMap((side) => {
1344
+ const reference = spec.terrainReferences[side];
1345
+ return reference ? [[side, reference.sha256]] : [];
1346
+ })
1347
+ ) : void 0,
1333
1348
  // "top-down" is the default and draws the same set as leaving it out.
1334
1349
  terrainOrientation: spec.terrainOrientation === "sidescroller" ? spec.terrainOrientation : void 0,
1335
1350
  // Which set and which of its terrains, not that terrain's id: the id
@@ -1596,7 +1611,7 @@ function terrainTileCount(transitionSize, mode2, orientation) {
1596
1611
  return transitionSize === 1 ? 25 : 16;
1597
1612
  }
1598
1613
  function terrainCost(mode2, tileSize, orientation) {
1599
- if (orientation === "sidescroller") return 3;
1614
+ if (orientation === "sidescroller") return mode2 === "pro" ? 15 : 1;
1600
1615
  if (mode2 === "pro") return tileSize <= 32 ? 15 : 25;
1601
1616
  return 4;
1602
1617
  }
@@ -2384,6 +2399,48 @@ var StyleObjectSchema = z.object({
2384
2399
  * lower terrain between them.
2385
2400
  */
2386
2401
  terrainConnectDiagonals: z.boolean().optional(),
2402
+ /**
2403
+ * `terrain` generator only, standard mode, top-down. Which ragged border
2404
+ * `terrainRaggedness` draws, 0 to 99 (the website's Reshuffle): another
2405
+ * number gives a different boundary at the same raggedness. API default 0.
2406
+ */
2407
+ terrainShapeSeed: z.number().int().min(0).max(99).optional(),
2408
+ /**
2409
+ * `terrain` generator only, standard mode, top-down, with
2410
+ * `terrainTransitionSize` above 0. How thick the wall reads on the top
2411
+ * rim and down both sides of the front face, 0 to 1. The website starts
2412
+ * at 0.1.
2413
+ */
2414
+ terrainSideWallThickness: z.number().min(0).max(1).optional(),
2415
+ /**
2416
+ * `terrain` generator only, standard mode, top-down, with
2417
+ * `terrainTransitionSize` above 0. Which side of the border the wall sits
2418
+ * on: 0 sticks out past the terrain (the API default), 1 is carved into
2419
+ * it so the shape stays put. The website starts at 0.5.
2420
+ */
2421
+ terrainSideWallPlacement: z.number().min(0).max(1).optional(),
2422
+ /**
2423
+ * `terrain` generator only, standard mode. PixelLab rewrites the terrain
2424
+ * descriptions and picks base colors before drawing unless this is
2425
+ * false. On by default upstream; set false to have your wording used as
2426
+ * written.
2427
+ */
2428
+ terrainEnhance: z.boolean().optional(),
2429
+ /**
2430
+ * `terrain` generator only, a standard sidescroller set. How thick the
2431
+ * platform body is, 0 thin to 1 thick. Left out, PixelLab fits it to
2432
+ * `terrainTransitionSize`.
2433
+ */
2434
+ terrainPlatformThickness: z.number().min(0).max(1).optional(),
2435
+ /**
2436
+ * `terrain` generator only, top-down. Whether each terrain can be walked
2437
+ * on, stored with the set for PixelLab's maps and engine exports (left
2438
+ * out, those guess from the terrain's name). They change no pixel, so
2439
+ * they are sent when the set is generated and are not part of its
2440
+ * identity: changing one later does not make the set stale.
2441
+ */
2442
+ terrainLowerWalkable: z.boolean().optional(),
2443
+ terrainUpperWalkable: z.boolean().optional(),
2387
2444
  /**
2388
2445
  * `terrain` generator only. Visual height of the step between lower and
2389
2446
  * upper terrain. Without `terrainShapeStyle`, only 0, 0.25, 0.5, or 1 are
@@ -2776,6 +2833,18 @@ var AssetSchema = z.object({
2776
2833
  * (a sword hand, a parted fringe) comes out the other way round.
2777
2834
  */
2778
2835
  mirror: z.string().min(1).optional(),
2836
+ /**
2837
+ * `terrain` styles only: a PNG per terrain for PixelLab to take that
2838
+ * terrain's look from, paths relative to the manifest. Top-down sets
2839
+ * take `lower`, `upper` and `transition`. A sidescroller set takes
2840
+ * `lower` (the platform body, pro mode) or `transition` (the surface
2841
+ * layer, standard mode), each a square PNG of the tile size.
2842
+ */
2843
+ terrainReferences: z.object({
2844
+ lower: z.string().min(1).optional(),
2845
+ upper: z.string().min(1).optional(),
2846
+ transition: z.string().min(1).optional()
2847
+ }).strict().optional(),
2779
2848
  /** Made from existing pixels by a local transform; see AssetDeriveSchema. Free; the provider is never called. */
2780
2849
  derive: AssetDeriveSchema.optional(),
2781
2850
  /** Built by a tool outside pixelkiln; see AssetExternalSchema. Never generated. */
@@ -7401,7 +7470,12 @@ function refusalReason(status, body) {
7401
7470
  if (status < 400 || status >= 500 || !body.startsWith("{")) return "";
7402
7471
  try {
7403
7472
  const detail = JSON.parse(body).detail;
7404
- return typeof detail === "string" && detail ? `: ${detail.slice(0, 400)}` : "";
7473
+ if (typeof detail === "string" && detail) return `: ${detail.slice(0, 400)}`;
7474
+ if (Array.isArray(detail)) {
7475
+ const messages = detail.map((item) => item && typeof item === "object" && typeof item.msg === "string" ? item.msg : "").filter(Boolean).map((msg) => msg.replace(/^Value error, /, ""));
7476
+ if (messages.length) return `: ${messages.join("; ").slice(0, 400)}`;
7477
+ }
7478
+ return "";
7405
7479
  } catch {
7406
7480
  return "";
7407
7481
  }
@@ -7603,6 +7677,16 @@ var PixelLabClient = class {
7603
7677
  lower_description: args.lowerDescription,
7604
7678
  upper_description: args.upperDescription
7605
7679
  };
7680
+ const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
7681
+ if (args.shapeSeed != null) body.shape_seed = args.shapeSeed;
7682
+ if (args.sideWallThickness != null) body.side_wall_thickness = args.sideWallThickness;
7683
+ if (args.sideWallPlacement != null) body.side_wall_placement = args.sideWallPlacement;
7684
+ if (args.enhance != null) body.enhance = args.enhance;
7685
+ if (args.lowerWalkable != null) body.lower_walkable = args.lowerWalkable;
7686
+ if (args.upperWalkable != null) body.upper_walkable = args.upperWalkable;
7687
+ if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
7688
+ if (args.upperReferenceImage) body.upper_reference_image = image(args.upperReferenceImage);
7689
+ if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
7606
7690
  if (args.transitionDescription) body.transition_description = args.transitionDescription;
7607
7691
  if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
7608
7692
  if (args.upperBaseTileId) body.upper_base_tile_id = args.upperBaseTileId;
@@ -7640,6 +7724,12 @@ var PixelLabClient = class {
7640
7724
  */
7641
7725
  async createTilesetSidescroller(args) {
7642
7726
  const body = { lower_description: args.lowerDescription };
7727
+ const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
7728
+ if (args.mode) body.mode = args.mode;
7729
+ if (args.enhance != null) body.enhance = args.enhance;
7730
+ if (args.platformThickness != null) body.platform_thickness = args.platformThickness;
7731
+ if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
7732
+ if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
7643
7733
  if (args.transitionDescription) body.transition_description = args.transitionDescription;
7644
7734
  if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
7645
7735
  if (args.tileSize != null) body.tile_size = { width: args.tileSize, height: args.tileSize };
@@ -10444,6 +10534,23 @@ var PixelLabProvider = class _PixelLabProvider {
10444
10534
  if (spec.terrainTileSize === 64 && spec.terrainMode !== "pro") {
10445
10535
  throw new Error('PixelLab terrain: a 64px tile needs terrainMode: "pro"');
10446
10536
  }
10537
+ const standardOnly = {
10538
+ terrainShapeSeed: spec.terrainShapeSeed,
10539
+ terrainSideWallThickness: spec.terrainSideWallThickness,
10540
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
10541
+ terrainEnhance: spec.terrainEnhance
10542
+ };
10543
+ const proSet = Object.entries(standardOnly).filter(([, value]) => value != null).map(([field]) => field);
10544
+ if (pro && proSet.length) {
10545
+ throw new Error(`PixelLab terrain: ${proSet.join(", ")} shape a standard set; terrainMode: "pro" ignores them`);
10546
+ }
10547
+ if ((spec.terrainSideWallThickness != null || spec.terrainSideWallPlacement != null) && !(spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0)) {
10548
+ throw new Error("PixelLab terrain: terrainSideWallThickness and terrainSideWallPlacement shape the wall, which needs a terrainTransitionSize above 0");
10549
+ }
10550
+ if (spec.terrainPlatformThickness != null) {
10551
+ throw new Error("PixelLab terrain: terrainPlatformThickness is a sidescroller control");
10552
+ }
10553
+ this.requireTerrainReferences(spec);
10447
10554
  if (spec.terrainShapeStyle && spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0.5) {
10448
10555
  throw new Error(
10449
10556
  "PixelLab terrain: terrainShapeStyle with terrainTransitionSize above 0.5 uses an extended 32-tile layout pixelkiln does not model; use 0, 0.25, or 0.5"
@@ -10462,7 +10569,6 @@ var PixelLabProvider = class _PixelLabProvider {
10462
10569
  */
10463
10570
  validateSidescrollerTerrain(spec) {
10464
10571
  const topDownOnly = {
10465
- terrainMode: spec.terrainMode,
10466
10572
  terrainShapeStyle: spec.terrainShapeStyle,
10467
10573
  terrainView: spec.terrainView,
10468
10574
  terrainSpreadX: spec.terrainSpreadX,
@@ -10472,7 +10578,12 @@ var PixelLabProvider = class _PixelLabProvider {
10472
10578
  terrainBoundaryAmplitude: spec.terrainBoundaryAmplitude,
10473
10579
  terrainBoundarySeed: spec.terrainBoundarySeed,
10474
10580
  terrainStepSlope: spec.terrainStepSlope,
10475
- terrainConnectDiagonals: spec.terrainConnectDiagonals
10581
+ terrainConnectDiagonals: spec.terrainConnectDiagonals,
10582
+ terrainShapeSeed: spec.terrainShapeSeed,
10583
+ terrainSideWallThickness: spec.terrainSideWallThickness,
10584
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
10585
+ terrainLowerWalkable: spec.terrainLowerWalkable,
10586
+ terrainUpperWalkable: spec.terrainUpperWalkable
10476
10587
  };
10477
10588
  const set = Object.entries(topDownOnly).filter(([, value]) => value != null).map(([field]) => field);
10478
10589
  if (set.length) {
@@ -10481,9 +10592,26 @@ var PixelLabProvider = class _PixelLabProvider {
10481
10592
  if (spec.terrainTileSize !== 16 && spec.terrainTileSize !== 32) {
10482
10593
  throw new Error(`PixelLab terrain: a sidescroller set's tiles are 16 or 32px, got ${spec.terrainTileSize}`);
10483
10594
  }
10484
- if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5, 1].includes(spec.terrainTransitionSize)) {
10485
- throw new Error("PixelLab terrain: a sidescroller set's terrainTransitionSize must be 0, 0.25, 0.5, or 1");
10595
+ if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5].includes(spec.terrainTransitionSize)) {
10596
+ throw new Error("PixelLab terrain: a sidescroller set's terrainTransitionSize must be 0, 0.25, or 0.5 (the top layer stops at half a tile)");
10597
+ }
10598
+ const pro = spec.terrainMode === "pro";
10599
+ if (pro && (spec.terrainEnhance != null || spec.terrainPlatformThickness != null)) {
10600
+ throw new Error('PixelLab terrain: terrainEnhance and terrainPlatformThickness shape a standard sidescroller set; terrainMode: "pro" ignores them');
10601
+ }
10602
+ if (spec.terrainConnect?.lower && !pro) {
10603
+ throw new Error(`PixelLab terrain: a sidescroller set connects to another set's platform only with terrainMode: "pro"`);
10604
+ }
10605
+ if (spec.terrainReferences?.upper) {
10606
+ throw new Error("PixelLab terrain: a sidescroller set's upper terrain is empty air; it takes no upper reference");
10486
10607
  }
10608
+ if (spec.terrainReferences?.lower && !pro) {
10609
+ throw new Error('PixelLab terrain: a sidescroller set keeps a lower (platform body) reference only with terrainMode: "pro"');
10610
+ }
10611
+ if (spec.terrainReferences?.transition && pro) {
10612
+ throw new Error('PixelLab terrain: a sidescroller set textures its top layer from a transition reference only on standard mode; drop it or terrainMode: "pro"');
10613
+ }
10614
+ this.requireTerrainReferences(spec, spec.terrainTileSize);
10487
10615
  if (spec.terrainConnect?.upper) {
10488
10616
  throw new Error(
10489
10617
  "PixelLab terrain: a sidescroller set's upper terrain is empty air; only its lower (platform) terrain can connect"
@@ -10496,6 +10624,19 @@ var PixelLabProvider = class _PixelLabProvider {
10496
10624
  );
10497
10625
  }
10498
10626
  }
10627
+ /** Reference files must exist; a sidescroller's must be a square PNG of the tile size. */
10628
+ requireTerrainReferences(spec, tileSize) {
10629
+ for (const [side, reference] of Object.entries(spec.terrainReferences ?? {})) {
10630
+ if (!reference?.sha256) {
10631
+ throw new Error(`PixelLab terrain: the ${side} reference is missing or not a PNG: ${reference?.file}`);
10632
+ }
10633
+ if (tileSize != null && (reference.width !== tileSize || reference.height !== tileSize)) {
10634
+ throw new Error(
10635
+ `PixelLab terrain: a sidescroller set's ${side} reference must be a ${tileSize}x${tileSize} PNG; ${reference.file} is ${reference.width}x${reference.height}`
10636
+ );
10637
+ }
10638
+ }
10639
+ }
10499
10640
  validateCharacter(spec, styleImages = []) {
10500
10641
  const character = spec.character;
10501
10642
  if (!character) throw new Error(`${spec.styleId}/${spec.assetId} has no character shape`);
@@ -11273,7 +11414,12 @@ var PixelLabProvider = class _PixelLabProvider {
11273
11414
  outline: spec.outline,
11274
11415
  shading: spec.shading,
11275
11416
  detail: spec.detail,
11276
- seed: spec.seed
11417
+ seed: spec.seed,
11418
+ mode: spec.terrainMode,
11419
+ enhance: spec.terrainEnhance,
11420
+ platformThickness: spec.terrainPlatformThickness,
11421
+ lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
11422
+ transitionReferenceImage: await terrainReferenceImage(spec, "transition")
11277
11423
  });
11278
11424
  return {
11279
11425
  jobId: res2.tileset_id,
@@ -11308,7 +11454,16 @@ var PixelLabProvider = class _PixelLabProvider {
11308
11454
  shading: spec.shading,
11309
11455
  detail: spec.detail,
11310
11456
  seed: spec.seed,
11311
- targetPalette: targetPaletteFor(spec)
11457
+ targetPalette: targetPaletteFor(spec),
11458
+ shapeSeed: spec.terrainShapeSeed,
11459
+ sideWallThickness: spec.terrainSideWallThickness,
11460
+ sideWallPlacement: spec.terrainSideWallPlacement,
11461
+ enhance: spec.terrainEnhance,
11462
+ lowerWalkable: spec.terrainLowerWalkable,
11463
+ upperWalkable: spec.terrainUpperWalkable,
11464
+ lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
11465
+ upperReferenceImage: await terrainReferenceImage(spec, "upper"),
11466
+ transitionReferenceImage: await terrainReferenceImage(spec, "transition")
11312
11467
  });
11313
11468
  return {
11314
11469
  jobId: res2.tileset_id,
@@ -12487,6 +12642,16 @@ function sendsTargetPalette(spec) {
12487
12642
  return false;
12488
12643
  }
12489
12644
  }
12645
+ async function terrainReferenceImage(spec, side) {
12646
+ const reference = spec.terrainReferences?.[side];
12647
+ if (!reference) return void 0;
12648
+ if (!existsSync11(reference.file)) throw new Error(`terrain ${side} reference is missing: ${reference.file}`);
12649
+ const bytes = readFileSync2(reference.file);
12650
+ if (sha256(bytes) !== reference.sha256) {
12651
+ throw new Error(`terrain ${side} reference changed after the manifest was resolved: ${reference.file}; run the command again`);
12652
+ }
12653
+ return { base64: bytes.toString("base64"), format: "png" };
12654
+ }
12490
12655
  function targetPaletteFor(spec) {
12491
12656
  if (!sendsTargetPalette(spec)) return void 0;
12492
12657
  if (!spec.palette.length && spec.maxColors == null) return void 0;
@@ -14351,6 +14516,13 @@ async function resolveSpecs(loaded, filter) {
14351
14516
  terrainBoundarySeed: generator === "terrain" ? style.terrainBoundarySeed : void 0,
14352
14517
  terrainStepSlope: generator === "terrain" ? style.terrainStepSlope : void 0,
14353
14518
  terrainConnectDiagonals: generator === "terrain" ? style.terrainConnectDiagonals : void 0,
14519
+ terrainShapeSeed: generator === "terrain" ? style.terrainShapeSeed : void 0,
14520
+ terrainSideWallThickness: generator === "terrain" ? style.terrainSideWallThickness : void 0,
14521
+ terrainSideWallPlacement: generator === "terrain" ? style.terrainSideWallPlacement : void 0,
14522
+ terrainEnhance: generator === "terrain" ? style.terrainEnhance : void 0,
14523
+ terrainPlatformThickness: generator === "terrain" ? style.terrainPlatformThickness : void 0,
14524
+ terrainLowerWalkable: generator === "terrain" ? style.terrainLowerWalkable : void 0,
14525
+ terrainUpperWalkable: generator === "terrain" ? style.terrainUpperWalkable : void 0,
14354
14526
  terrainTransitionSize: generator === "terrain" ? style.terrainTransitionSize : void 0,
14355
14527
  terrainView: generator === "terrain" ? style.terrainView : void 0,
14356
14528
  terrainOrientation: generator === "terrain" ? style.terrainOrientation : void 0,
@@ -14783,6 +14955,20 @@ async function resolveSpecs(loaded, filter) {
14783
14955
  }
14784
14956
  resolved.terrainConnect = links;
14785
14957
  }
14958
+ if (asset.terrainReferences) {
14959
+ if (resolved.generator !== "terrain") {
14960
+ throw new Error(`assets.${assetId}.terrainReferences: only a terrain set takes terrain references; style "${styleId}" uses "${resolved.generator}"`);
14961
+ }
14962
+ const references = {};
14963
+ for (const side of ["lower", "upper", "transition"]) {
14964
+ const relative = asset.terrainReferences[side];
14965
+ if (!relative) continue;
14966
+ const file = path18.resolve(root, relative);
14967
+ const image = await optionalRevisionImage(file, `terrain ${side} reference`, "png");
14968
+ references[side] = { file, sha256: image?.hash ?? null, width: image?.width ?? null, height: image?.height ?? null };
14969
+ }
14970
+ if (Object.keys(references).length) resolved.terrainReferences = references;
14971
+ }
14786
14972
  if (asset.scene) resolved.scene = await resolveMapScene(root, styleId, assetId, resolved.generator, asset.scene, activeProvider);
14787
14973
  resolved.specHash = specHash(
14788
14974
  resolved,