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/index.cjs CHANGED
@@ -535,7 +535,7 @@ function terrainTileCount(transitionSize, mode2, orientation) {
535
535
  return transitionSize === 1 ? 25 : 16;
536
536
  }
537
537
  function terrainCost(mode2, tileSize, orientation) {
538
- if (orientation === "sidescroller") return 3;
538
+ if (orientation === "sidescroller") return mode2 === "pro" ? 15 : 1;
539
539
  if (mode2 === "pro") return tileSize <= 32 ? 15 : 25;
540
540
  return 4;
541
541
  }
@@ -1323,6 +1323,48 @@ var StyleObjectSchema = import_zod.z.object({
1323
1323
  * lower terrain between them.
1324
1324
  */
1325
1325
  terrainConnectDiagonals: import_zod.z.boolean().optional(),
1326
+ /**
1327
+ * `terrain` generator only, standard mode, top-down. Which ragged border
1328
+ * `terrainRaggedness` draws, 0 to 99 (the website's Reshuffle): another
1329
+ * number gives a different boundary at the same raggedness. API default 0.
1330
+ */
1331
+ terrainShapeSeed: import_zod.z.number().int().min(0).max(99).optional(),
1332
+ /**
1333
+ * `terrain` generator only, standard mode, top-down, with
1334
+ * `terrainTransitionSize` above 0. How thick the wall reads on the top
1335
+ * rim and down both sides of the front face, 0 to 1. The website starts
1336
+ * at 0.1.
1337
+ */
1338
+ terrainSideWallThickness: import_zod.z.number().min(0).max(1).optional(),
1339
+ /**
1340
+ * `terrain` generator only, standard mode, top-down, with
1341
+ * `terrainTransitionSize` above 0. Which side of the border the wall sits
1342
+ * on: 0 sticks out past the terrain (the API default), 1 is carved into
1343
+ * it so the shape stays put. The website starts at 0.5.
1344
+ */
1345
+ terrainSideWallPlacement: import_zod.z.number().min(0).max(1).optional(),
1346
+ /**
1347
+ * `terrain` generator only, standard mode. PixelLab rewrites the terrain
1348
+ * descriptions and picks base colors before drawing unless this is
1349
+ * false. On by default upstream; set false to have your wording used as
1350
+ * written.
1351
+ */
1352
+ terrainEnhance: import_zod.z.boolean().optional(),
1353
+ /**
1354
+ * `terrain` generator only, a standard sidescroller set. How thick the
1355
+ * platform body is, 0 thin to 1 thick. Left out, PixelLab fits it to
1356
+ * `terrainTransitionSize`.
1357
+ */
1358
+ terrainPlatformThickness: import_zod.z.number().min(0).max(1).optional(),
1359
+ /**
1360
+ * `terrain` generator only, top-down. Whether each terrain can be walked
1361
+ * on, stored with the set for PixelLab's maps and engine exports (left
1362
+ * out, those guess from the terrain's name). They change no pixel, so
1363
+ * they are sent when the set is generated and are not part of its
1364
+ * identity: changing one later does not make the set stale.
1365
+ */
1366
+ terrainLowerWalkable: import_zod.z.boolean().optional(),
1367
+ terrainUpperWalkable: import_zod.z.boolean().optional(),
1326
1368
  /**
1327
1369
  * `terrain` generator only. Visual height of the step between lower and
1328
1370
  * upper terrain. Without `terrainShapeStyle`, only 0, 0.25, 0.5, or 1 are
@@ -1715,6 +1757,18 @@ var AssetSchema = import_zod.z.object({
1715
1757
  * (a sword hand, a parted fringe) comes out the other way round.
1716
1758
  */
1717
1759
  mirror: import_zod.z.string().min(1).optional(),
1760
+ /**
1761
+ * `terrain` styles only: a PNG per terrain for PixelLab to take that
1762
+ * terrain's look from, paths relative to the manifest. Top-down sets
1763
+ * take `lower`, `upper` and `transition`. A sidescroller set takes
1764
+ * `lower` (the platform body, pro mode) or `transition` (the surface
1765
+ * layer, standard mode), each a square PNG of the tile size.
1766
+ */
1767
+ terrainReferences: import_zod.z.object({
1768
+ lower: import_zod.z.string().min(1).optional(),
1769
+ upper: import_zod.z.string().min(1).optional(),
1770
+ transition: import_zod.z.string().min(1).optional()
1771
+ }).strict().optional(),
1718
1772
  /** Made from existing pixels by a local transform; see AssetDeriveSchema. Free; the provider is never called. */
1719
1773
  derive: AssetDeriveSchema.optional(),
1720
1774
  /** Built by a tool outside pixelkiln; see AssetExternalSchema. Never generated. */
@@ -2738,7 +2792,12 @@ function refusalReason(status, body) {
2738
2792
  if (status < 400 || status >= 500 || !body.startsWith("{")) return "";
2739
2793
  try {
2740
2794
  const detail = JSON.parse(body).detail;
2741
- return typeof detail === "string" && detail ? `: ${detail.slice(0, 400)}` : "";
2795
+ if (typeof detail === "string" && detail) return `: ${detail.slice(0, 400)}`;
2796
+ if (Array.isArray(detail)) {
2797
+ const messages = detail.map((item) => item && typeof item === "object" && typeof item.msg === "string" ? item.msg : "").filter(Boolean).map((msg) => msg.replace(/^Value error, /, ""));
2798
+ if (messages.length) return `: ${messages.join("; ").slice(0, 400)}`;
2799
+ }
2800
+ return "";
2742
2801
  } catch {
2743
2802
  return "";
2744
2803
  }
@@ -2940,6 +2999,16 @@ var PixelLabClient = class {
2940
2999
  lower_description: args.lowerDescription,
2941
3000
  upper_description: args.upperDescription
2942
3001
  };
3002
+ const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
3003
+ if (args.shapeSeed != null) body.shape_seed = args.shapeSeed;
3004
+ if (args.sideWallThickness != null) body.side_wall_thickness = args.sideWallThickness;
3005
+ if (args.sideWallPlacement != null) body.side_wall_placement = args.sideWallPlacement;
3006
+ if (args.enhance != null) body.enhance = args.enhance;
3007
+ if (args.lowerWalkable != null) body.lower_walkable = args.lowerWalkable;
3008
+ if (args.upperWalkable != null) body.upper_walkable = args.upperWalkable;
3009
+ if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
3010
+ if (args.upperReferenceImage) body.upper_reference_image = image(args.upperReferenceImage);
3011
+ if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
2943
3012
  if (args.transitionDescription) body.transition_description = args.transitionDescription;
2944
3013
  if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
2945
3014
  if (args.upperBaseTileId) body.upper_base_tile_id = args.upperBaseTileId;
@@ -2977,6 +3046,12 @@ var PixelLabClient = class {
2977
3046
  */
2978
3047
  async createTilesetSidescroller(args) {
2979
3048
  const body = { lower_description: args.lowerDescription };
3049
+ const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
3050
+ if (args.mode) body.mode = args.mode;
3051
+ if (args.enhance != null) body.enhance = args.enhance;
3052
+ if (args.platformThickness != null) body.platform_thickness = args.platformThickness;
3053
+ if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
3054
+ if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
2980
3055
  if (args.transitionDescription) body.transition_description = args.transitionDescription;
2981
3056
  if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
2982
3057
  if (args.tileSize != null) body.tile_size = { width: args.tileSize, height: args.tileSize };
@@ -4952,6 +5027,21 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
4952
5027
  terrainBoundarySeed: spec.terrainBoundarySeed,
4953
5028
  terrainStepSlope: spec.terrainStepSlope,
4954
5029
  terrainConnectDiagonals: spec.terrainConnectDiagonals,
5030
+ // Added after the fields above, each only when set, so no terrain entry
5031
+ // written before them changes hash. The walkable flags change no pixel
5032
+ // and are deliberately not here.
5033
+ terrainShapeSeed: spec.terrainShapeSeed,
5034
+ terrainSideWallThickness: spec.terrainSideWallThickness,
5035
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
5036
+ terrainEnhance: spec.terrainEnhance,
5037
+ terrainPlatformThickness: spec.terrainPlatformThickness,
5038
+ // Reference images enter as their bytes' hashes, never their paths.
5039
+ terrainReferences: spec.terrainReferences && Object.keys(spec.terrainReferences).length ? Object.fromEntries(
5040
+ ["lower", "upper", "transition"].flatMap((side) => {
5041
+ const reference = spec.terrainReferences[side];
5042
+ return reference ? [[side, reference.sha256]] : [];
5043
+ })
5044
+ ) : void 0,
4955
5045
  // "top-down" is the default and draws the same set as leaving it out.
4956
5046
  terrainOrientation: spec.terrainOrientation === "sidescroller" ? spec.terrainOrientation : void 0,
4957
5047
  // Which set and which of its terrains, not that terrain's id: the id
@@ -6537,6 +6627,23 @@ var PixelLabProvider = class _PixelLabProvider {
6537
6627
  if (spec.terrainTileSize === 64 && spec.terrainMode !== "pro") {
6538
6628
  throw new Error('PixelLab terrain: a 64px tile needs terrainMode: "pro"');
6539
6629
  }
6630
+ const standardOnly = {
6631
+ terrainShapeSeed: spec.terrainShapeSeed,
6632
+ terrainSideWallThickness: spec.terrainSideWallThickness,
6633
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
6634
+ terrainEnhance: spec.terrainEnhance
6635
+ };
6636
+ const proSet = Object.entries(standardOnly).filter(([, value]) => value != null).map(([field]) => field);
6637
+ if (pro && proSet.length) {
6638
+ throw new Error(`PixelLab terrain: ${proSet.join(", ")} shape a standard set; terrainMode: "pro" ignores them`);
6639
+ }
6640
+ if ((spec.terrainSideWallThickness != null || spec.terrainSideWallPlacement != null) && !(spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0)) {
6641
+ throw new Error("PixelLab terrain: terrainSideWallThickness and terrainSideWallPlacement shape the wall, which needs a terrainTransitionSize above 0");
6642
+ }
6643
+ if (spec.terrainPlatformThickness != null) {
6644
+ throw new Error("PixelLab terrain: terrainPlatformThickness is a sidescroller control");
6645
+ }
6646
+ this.requireTerrainReferences(spec);
6540
6647
  if (spec.terrainShapeStyle && spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0.5) {
6541
6648
  throw new Error(
6542
6649
  "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"
@@ -6555,7 +6662,6 @@ var PixelLabProvider = class _PixelLabProvider {
6555
6662
  */
6556
6663
  validateSidescrollerTerrain(spec) {
6557
6664
  const topDownOnly = {
6558
- terrainMode: spec.terrainMode,
6559
6665
  terrainShapeStyle: spec.terrainShapeStyle,
6560
6666
  terrainView: spec.terrainView,
6561
6667
  terrainSpreadX: spec.terrainSpreadX,
@@ -6565,7 +6671,12 @@ var PixelLabProvider = class _PixelLabProvider {
6565
6671
  terrainBoundaryAmplitude: spec.terrainBoundaryAmplitude,
6566
6672
  terrainBoundarySeed: spec.terrainBoundarySeed,
6567
6673
  terrainStepSlope: spec.terrainStepSlope,
6568
- terrainConnectDiagonals: spec.terrainConnectDiagonals
6674
+ terrainConnectDiagonals: spec.terrainConnectDiagonals,
6675
+ terrainShapeSeed: spec.terrainShapeSeed,
6676
+ terrainSideWallThickness: spec.terrainSideWallThickness,
6677
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
6678
+ terrainLowerWalkable: spec.terrainLowerWalkable,
6679
+ terrainUpperWalkable: spec.terrainUpperWalkable
6569
6680
  };
6570
6681
  const set = Object.entries(topDownOnly).filter(([, value]) => value != null).map(([field]) => field);
6571
6682
  if (set.length) {
@@ -6574,9 +6685,26 @@ var PixelLabProvider = class _PixelLabProvider {
6574
6685
  if (spec.terrainTileSize !== 16 && spec.terrainTileSize !== 32) {
6575
6686
  throw new Error(`PixelLab terrain: a sidescroller set's tiles are 16 or 32px, got ${spec.terrainTileSize}`);
6576
6687
  }
6577
- if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5, 1].includes(spec.terrainTransitionSize)) {
6578
- throw new Error("PixelLab terrain: a sidescroller set's terrainTransitionSize must be 0, 0.25, 0.5, or 1");
6688
+ if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5].includes(spec.terrainTransitionSize)) {
6689
+ 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)");
6690
+ }
6691
+ const pro = spec.terrainMode === "pro";
6692
+ if (pro && (spec.terrainEnhance != null || spec.terrainPlatformThickness != null)) {
6693
+ throw new Error('PixelLab terrain: terrainEnhance and terrainPlatformThickness shape a standard sidescroller set; terrainMode: "pro" ignores them');
6694
+ }
6695
+ if (spec.terrainConnect?.lower && !pro) {
6696
+ throw new Error(`PixelLab terrain: a sidescroller set connects to another set's platform only with terrainMode: "pro"`);
6697
+ }
6698
+ if (spec.terrainReferences?.upper) {
6699
+ throw new Error("PixelLab terrain: a sidescroller set's upper terrain is empty air; it takes no upper reference");
6579
6700
  }
6701
+ if (spec.terrainReferences?.lower && !pro) {
6702
+ throw new Error('PixelLab terrain: a sidescroller set keeps a lower (platform body) reference only with terrainMode: "pro"');
6703
+ }
6704
+ if (spec.terrainReferences?.transition && pro) {
6705
+ 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"');
6706
+ }
6707
+ this.requireTerrainReferences(spec, spec.terrainTileSize);
6580
6708
  if (spec.terrainConnect?.upper) {
6581
6709
  throw new Error(
6582
6710
  "PixelLab terrain: a sidescroller set's upper terrain is empty air; only its lower (platform) terrain can connect"
@@ -6589,6 +6717,19 @@ var PixelLabProvider = class _PixelLabProvider {
6589
6717
  );
6590
6718
  }
6591
6719
  }
6720
+ /** Reference files must exist; a sidescroller's must be a square PNG of the tile size. */
6721
+ requireTerrainReferences(spec, tileSize) {
6722
+ for (const [side, reference] of Object.entries(spec.terrainReferences ?? {})) {
6723
+ if (!reference?.sha256) {
6724
+ throw new Error(`PixelLab terrain: the ${side} reference is missing or not a PNG: ${reference?.file}`);
6725
+ }
6726
+ if (tileSize != null && (reference.width !== tileSize || reference.height !== tileSize)) {
6727
+ throw new Error(
6728
+ `PixelLab terrain: a sidescroller set's ${side} reference must be a ${tileSize}x${tileSize} PNG; ${reference.file} is ${reference.width}x${reference.height}`
6729
+ );
6730
+ }
6731
+ }
6732
+ }
6592
6733
  validateCharacter(spec, styleImages = []) {
6593
6734
  const character = spec.character;
6594
6735
  if (!character) throw new Error(`${spec.styleId}/${spec.assetId} has no character shape`);
@@ -7366,7 +7507,12 @@ var PixelLabProvider = class _PixelLabProvider {
7366
7507
  outline: spec.outline,
7367
7508
  shading: spec.shading,
7368
7509
  detail: spec.detail,
7369
- seed: spec.seed
7510
+ seed: spec.seed,
7511
+ mode: spec.terrainMode,
7512
+ enhance: spec.terrainEnhance,
7513
+ platformThickness: spec.terrainPlatformThickness,
7514
+ lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
7515
+ transitionReferenceImage: await terrainReferenceImage(spec, "transition")
7370
7516
  });
7371
7517
  return {
7372
7518
  jobId: res2.tileset_id,
@@ -7401,7 +7547,16 @@ var PixelLabProvider = class _PixelLabProvider {
7401
7547
  shading: spec.shading,
7402
7548
  detail: spec.detail,
7403
7549
  seed: spec.seed,
7404
- targetPalette: targetPaletteFor(spec)
7550
+ targetPalette: targetPaletteFor(spec),
7551
+ shapeSeed: spec.terrainShapeSeed,
7552
+ sideWallThickness: spec.terrainSideWallThickness,
7553
+ sideWallPlacement: spec.terrainSideWallPlacement,
7554
+ enhance: spec.terrainEnhance,
7555
+ lowerWalkable: spec.terrainLowerWalkable,
7556
+ upperWalkable: spec.terrainUpperWalkable,
7557
+ lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
7558
+ upperReferenceImage: await terrainReferenceImage(spec, "upper"),
7559
+ transitionReferenceImage: await terrainReferenceImage(spec, "transition")
7405
7560
  });
7406
7561
  return {
7407
7562
  jobId: res2.tileset_id,
@@ -8580,6 +8735,16 @@ function sendsTargetPalette(spec) {
8580
8735
  return false;
8581
8736
  }
8582
8737
  }
8738
+ async function terrainReferenceImage(spec, side) {
8739
+ const reference = spec.terrainReferences?.[side];
8740
+ if (!reference) return void 0;
8741
+ if (!(0, import_node_fs4.existsSync)(reference.file)) throw new Error(`terrain ${side} reference is missing: ${reference.file}`);
8742
+ const bytes = (0, import_node_fs4.readFileSync)(reference.file);
8743
+ if (sha256(bytes) !== reference.sha256) {
8744
+ throw new Error(`terrain ${side} reference changed after the manifest was resolved: ${reference.file}; run the command again`);
8745
+ }
8746
+ return { base64: bytes.toString("base64"), format: "png" };
8747
+ }
8583
8748
  function targetPaletteFor(spec) {
8584
8749
  if (!sendsTargetPalette(spec)) return void 0;
8585
8750
  if (!spec.palette.length && spec.maxColors == null) return void 0;
@@ -11862,6 +12027,13 @@ async function resolveSpecs(loaded, filter) {
11862
12027
  terrainBoundarySeed: generator === "terrain" ? style.terrainBoundarySeed : void 0,
11863
12028
  terrainStepSlope: generator === "terrain" ? style.terrainStepSlope : void 0,
11864
12029
  terrainConnectDiagonals: generator === "terrain" ? style.terrainConnectDiagonals : void 0,
12030
+ terrainShapeSeed: generator === "terrain" ? style.terrainShapeSeed : void 0,
12031
+ terrainSideWallThickness: generator === "terrain" ? style.terrainSideWallThickness : void 0,
12032
+ terrainSideWallPlacement: generator === "terrain" ? style.terrainSideWallPlacement : void 0,
12033
+ terrainEnhance: generator === "terrain" ? style.terrainEnhance : void 0,
12034
+ terrainPlatformThickness: generator === "terrain" ? style.terrainPlatformThickness : void 0,
12035
+ terrainLowerWalkable: generator === "terrain" ? style.terrainLowerWalkable : void 0,
12036
+ terrainUpperWalkable: generator === "terrain" ? style.terrainUpperWalkable : void 0,
11865
12037
  terrainTransitionSize: generator === "terrain" ? style.terrainTransitionSize : void 0,
11866
12038
  terrainView: generator === "terrain" ? style.terrainView : void 0,
11867
12039
  terrainOrientation: generator === "terrain" ? style.terrainOrientation : void 0,
@@ -12294,6 +12466,20 @@ async function resolveSpecs(loaded, filter) {
12294
12466
  }
12295
12467
  resolved.terrainConnect = links;
12296
12468
  }
12469
+ if (asset.terrainReferences) {
12470
+ if (resolved.generator !== "terrain") {
12471
+ throw new Error(`assets.${assetId}.terrainReferences: only a terrain set takes terrain references; style "${styleId}" uses "${resolved.generator}"`);
12472
+ }
12473
+ const references = {};
12474
+ for (const side of ["lower", "upper", "transition"]) {
12475
+ const relative = asset.terrainReferences[side];
12476
+ if (!relative) continue;
12477
+ const file = import_node_path8.default.resolve(root, relative);
12478
+ const image = await optionalRevisionImage(file, `terrain ${side} reference`, "png");
12479
+ references[side] = { file, sha256: image?.hash ?? null, width: image?.width ?? null, height: image?.height ?? null };
12480
+ }
12481
+ if (Object.keys(references).length) resolved.terrainReferences = references;
12482
+ }
12297
12483
  if (asset.scene) resolved.scene = await resolveMapScene(root, styleId, assetId, resolved.generator, asset.scene, activeProvider);
12298
12484
  resolved.specHash = specHash(
12299
12485
  resolved,