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.js CHANGED
@@ -98,7 +98,7 @@ function terrainTileCount(transitionSize, mode2, orientation) {
98
98
  return transitionSize === 1 ? 25 : 16;
99
99
  }
100
100
  function terrainCost(mode2, tileSize, orientation) {
101
- if (orientation === "sidescroller") return 3;
101
+ if (orientation === "sidescroller") return mode2 === "pro" ? 15 : 1;
102
102
  if (mode2 === "pro") return tileSize <= 32 ? 15 : 25;
103
103
  return 4;
104
104
  }
@@ -886,6 +886,48 @@ var StyleObjectSchema = z.object({
886
886
  * lower terrain between them.
887
887
  */
888
888
  terrainConnectDiagonals: z.boolean().optional(),
889
+ /**
890
+ * `terrain` generator only, standard mode, top-down. Which ragged border
891
+ * `terrainRaggedness` draws, 0 to 99 (the website's Reshuffle): another
892
+ * number gives a different boundary at the same raggedness. API default 0.
893
+ */
894
+ terrainShapeSeed: z.number().int().min(0).max(99).optional(),
895
+ /**
896
+ * `terrain` generator only, standard mode, top-down, with
897
+ * `terrainTransitionSize` above 0. How thick the wall reads on the top
898
+ * rim and down both sides of the front face, 0 to 1. The website starts
899
+ * at 0.1.
900
+ */
901
+ terrainSideWallThickness: z.number().min(0).max(1).optional(),
902
+ /**
903
+ * `terrain` generator only, standard mode, top-down, with
904
+ * `terrainTransitionSize` above 0. Which side of the border the wall sits
905
+ * on: 0 sticks out past the terrain (the API default), 1 is carved into
906
+ * it so the shape stays put. The website starts at 0.5.
907
+ */
908
+ terrainSideWallPlacement: z.number().min(0).max(1).optional(),
909
+ /**
910
+ * `terrain` generator only, standard mode. PixelLab rewrites the terrain
911
+ * descriptions and picks base colors before drawing unless this is
912
+ * false. On by default upstream; set false to have your wording used as
913
+ * written.
914
+ */
915
+ terrainEnhance: z.boolean().optional(),
916
+ /**
917
+ * `terrain` generator only, a standard sidescroller set. How thick the
918
+ * platform body is, 0 thin to 1 thick. Left out, PixelLab fits it to
919
+ * `terrainTransitionSize`.
920
+ */
921
+ terrainPlatformThickness: z.number().min(0).max(1).optional(),
922
+ /**
923
+ * `terrain` generator only, top-down. Whether each terrain can be walked
924
+ * on, stored with the set for PixelLab's maps and engine exports (left
925
+ * out, those guess from the terrain's name). They change no pixel, so
926
+ * they are sent when the set is generated and are not part of its
927
+ * identity: changing one later does not make the set stale.
928
+ */
929
+ terrainLowerWalkable: z.boolean().optional(),
930
+ terrainUpperWalkable: z.boolean().optional(),
889
931
  /**
890
932
  * `terrain` generator only. Visual height of the step between lower and
891
933
  * upper terrain. Without `terrainShapeStyle`, only 0, 0.25, 0.5, or 1 are
@@ -1278,6 +1320,18 @@ var AssetSchema = z.object({
1278
1320
  * (a sword hand, a parted fringe) comes out the other way round.
1279
1321
  */
1280
1322
  mirror: z.string().min(1).optional(),
1323
+ /**
1324
+ * `terrain` styles only: a PNG per terrain for PixelLab to take that
1325
+ * terrain's look from, paths relative to the manifest. Top-down sets
1326
+ * take `lower`, `upper` and `transition`. A sidescroller set takes
1327
+ * `lower` (the platform body, pro mode) or `transition` (the surface
1328
+ * layer, standard mode), each a square PNG of the tile size.
1329
+ */
1330
+ terrainReferences: z.object({
1331
+ lower: z.string().min(1).optional(),
1332
+ upper: z.string().min(1).optional(),
1333
+ transition: z.string().min(1).optional()
1334
+ }).strict().optional(),
1281
1335
  /** Made from existing pixels by a local transform; see AssetDeriveSchema. Free; the provider is never called. */
1282
1336
  derive: AssetDeriveSchema.optional(),
1283
1337
  /** Built by a tool outside pixelkiln; see AssetExternalSchema. Never generated. */
@@ -2301,7 +2355,12 @@ function refusalReason(status, body) {
2301
2355
  if (status < 400 || status >= 500 || !body.startsWith("{")) return "";
2302
2356
  try {
2303
2357
  const detail = JSON.parse(body).detail;
2304
- return typeof detail === "string" && detail ? `: ${detail.slice(0, 400)}` : "";
2358
+ if (typeof detail === "string" && detail) return `: ${detail.slice(0, 400)}`;
2359
+ if (Array.isArray(detail)) {
2360
+ const messages = detail.map((item) => item && typeof item === "object" && typeof item.msg === "string" ? item.msg : "").filter(Boolean).map((msg) => msg.replace(/^Value error, /, ""));
2361
+ if (messages.length) return `: ${messages.join("; ").slice(0, 400)}`;
2362
+ }
2363
+ return "";
2305
2364
  } catch {
2306
2365
  return "";
2307
2366
  }
@@ -2503,6 +2562,16 @@ var PixelLabClient = class {
2503
2562
  lower_description: args.lowerDescription,
2504
2563
  upper_description: args.upperDescription
2505
2564
  };
2565
+ const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
2566
+ if (args.shapeSeed != null) body.shape_seed = args.shapeSeed;
2567
+ if (args.sideWallThickness != null) body.side_wall_thickness = args.sideWallThickness;
2568
+ if (args.sideWallPlacement != null) body.side_wall_placement = args.sideWallPlacement;
2569
+ if (args.enhance != null) body.enhance = args.enhance;
2570
+ if (args.lowerWalkable != null) body.lower_walkable = args.lowerWalkable;
2571
+ if (args.upperWalkable != null) body.upper_walkable = args.upperWalkable;
2572
+ if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
2573
+ if (args.upperReferenceImage) body.upper_reference_image = image(args.upperReferenceImage);
2574
+ if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
2506
2575
  if (args.transitionDescription) body.transition_description = args.transitionDescription;
2507
2576
  if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
2508
2577
  if (args.upperBaseTileId) body.upper_base_tile_id = args.upperBaseTileId;
@@ -2540,6 +2609,12 @@ var PixelLabClient = class {
2540
2609
  */
2541
2610
  async createTilesetSidescroller(args) {
2542
2611
  const body = { lower_description: args.lowerDescription };
2612
+ const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
2613
+ if (args.mode) body.mode = args.mode;
2614
+ if (args.enhance != null) body.enhance = args.enhance;
2615
+ if (args.platformThickness != null) body.platform_thickness = args.platformThickness;
2616
+ if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
2617
+ if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
2543
2618
  if (args.transitionDescription) body.transition_description = args.transitionDescription;
2544
2619
  if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
2545
2620
  if (args.tileSize != null) body.tile_size = { width: args.tileSize, height: args.tileSize };
@@ -4515,6 +4590,21 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
4515
4590
  terrainBoundarySeed: spec.terrainBoundarySeed,
4516
4591
  terrainStepSlope: spec.terrainStepSlope,
4517
4592
  terrainConnectDiagonals: spec.terrainConnectDiagonals,
4593
+ // Added after the fields above, each only when set, so no terrain entry
4594
+ // written before them changes hash. The walkable flags change no pixel
4595
+ // and are deliberately not here.
4596
+ terrainShapeSeed: spec.terrainShapeSeed,
4597
+ terrainSideWallThickness: spec.terrainSideWallThickness,
4598
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
4599
+ terrainEnhance: spec.terrainEnhance,
4600
+ terrainPlatformThickness: spec.terrainPlatformThickness,
4601
+ // Reference images enter as their bytes' hashes, never their paths.
4602
+ terrainReferences: spec.terrainReferences && Object.keys(spec.terrainReferences).length ? Object.fromEntries(
4603
+ ["lower", "upper", "transition"].flatMap((side) => {
4604
+ const reference = spec.terrainReferences[side];
4605
+ return reference ? [[side, reference.sha256]] : [];
4606
+ })
4607
+ ) : void 0,
4518
4608
  // "top-down" is the default and draws the same set as leaving it out.
4519
4609
  terrainOrientation: spec.terrainOrientation === "sidescroller" ? spec.terrainOrientation : void 0,
4520
4610
  // Which set and which of its terrains, not that terrain's id: the id
@@ -6100,6 +6190,23 @@ var PixelLabProvider = class _PixelLabProvider {
6100
6190
  if (spec.terrainTileSize === 64 && spec.terrainMode !== "pro") {
6101
6191
  throw new Error('PixelLab terrain: a 64px tile needs terrainMode: "pro"');
6102
6192
  }
6193
+ const standardOnly = {
6194
+ terrainShapeSeed: spec.terrainShapeSeed,
6195
+ terrainSideWallThickness: spec.terrainSideWallThickness,
6196
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
6197
+ terrainEnhance: spec.terrainEnhance
6198
+ };
6199
+ const proSet = Object.entries(standardOnly).filter(([, value]) => value != null).map(([field]) => field);
6200
+ if (pro && proSet.length) {
6201
+ throw new Error(`PixelLab terrain: ${proSet.join(", ")} shape a standard set; terrainMode: "pro" ignores them`);
6202
+ }
6203
+ if ((spec.terrainSideWallThickness != null || spec.terrainSideWallPlacement != null) && !(spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0)) {
6204
+ throw new Error("PixelLab terrain: terrainSideWallThickness and terrainSideWallPlacement shape the wall, which needs a terrainTransitionSize above 0");
6205
+ }
6206
+ if (spec.terrainPlatformThickness != null) {
6207
+ throw new Error("PixelLab terrain: terrainPlatformThickness is a sidescroller control");
6208
+ }
6209
+ this.requireTerrainReferences(spec);
6103
6210
  if (spec.terrainShapeStyle && spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0.5) {
6104
6211
  throw new Error(
6105
6212
  "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"
@@ -6118,7 +6225,6 @@ var PixelLabProvider = class _PixelLabProvider {
6118
6225
  */
6119
6226
  validateSidescrollerTerrain(spec) {
6120
6227
  const topDownOnly = {
6121
- terrainMode: spec.terrainMode,
6122
6228
  terrainShapeStyle: spec.terrainShapeStyle,
6123
6229
  terrainView: spec.terrainView,
6124
6230
  terrainSpreadX: spec.terrainSpreadX,
@@ -6128,7 +6234,12 @@ var PixelLabProvider = class _PixelLabProvider {
6128
6234
  terrainBoundaryAmplitude: spec.terrainBoundaryAmplitude,
6129
6235
  terrainBoundarySeed: spec.terrainBoundarySeed,
6130
6236
  terrainStepSlope: spec.terrainStepSlope,
6131
- terrainConnectDiagonals: spec.terrainConnectDiagonals
6237
+ terrainConnectDiagonals: spec.terrainConnectDiagonals,
6238
+ terrainShapeSeed: spec.terrainShapeSeed,
6239
+ terrainSideWallThickness: spec.terrainSideWallThickness,
6240
+ terrainSideWallPlacement: spec.terrainSideWallPlacement,
6241
+ terrainLowerWalkable: spec.terrainLowerWalkable,
6242
+ terrainUpperWalkable: spec.terrainUpperWalkable
6132
6243
  };
6133
6244
  const set = Object.entries(topDownOnly).filter(([, value]) => value != null).map(([field]) => field);
6134
6245
  if (set.length) {
@@ -6137,9 +6248,26 @@ var PixelLabProvider = class _PixelLabProvider {
6137
6248
  if (spec.terrainTileSize !== 16 && spec.terrainTileSize !== 32) {
6138
6249
  throw new Error(`PixelLab terrain: a sidescroller set's tiles are 16 or 32px, got ${spec.terrainTileSize}`);
6139
6250
  }
6140
- if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5, 1].includes(spec.terrainTransitionSize)) {
6141
- throw new Error("PixelLab terrain: a sidescroller set's terrainTransitionSize must be 0, 0.25, 0.5, or 1");
6251
+ if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5].includes(spec.terrainTransitionSize)) {
6252
+ 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)");
6253
+ }
6254
+ const pro = spec.terrainMode === "pro";
6255
+ if (pro && (spec.terrainEnhance != null || spec.terrainPlatformThickness != null)) {
6256
+ throw new Error('PixelLab terrain: terrainEnhance and terrainPlatformThickness shape a standard sidescroller set; terrainMode: "pro" ignores them');
6257
+ }
6258
+ if (spec.terrainConnect?.lower && !pro) {
6259
+ throw new Error(`PixelLab terrain: a sidescroller set connects to another set's platform only with terrainMode: "pro"`);
6260
+ }
6261
+ if (spec.terrainReferences?.upper) {
6262
+ throw new Error("PixelLab terrain: a sidescroller set's upper terrain is empty air; it takes no upper reference");
6142
6263
  }
6264
+ if (spec.terrainReferences?.lower && !pro) {
6265
+ throw new Error('PixelLab terrain: a sidescroller set keeps a lower (platform body) reference only with terrainMode: "pro"');
6266
+ }
6267
+ if (spec.terrainReferences?.transition && pro) {
6268
+ 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"');
6269
+ }
6270
+ this.requireTerrainReferences(spec, spec.terrainTileSize);
6143
6271
  if (spec.terrainConnect?.upper) {
6144
6272
  throw new Error(
6145
6273
  "PixelLab terrain: a sidescroller set's upper terrain is empty air; only its lower (platform) terrain can connect"
@@ -6152,6 +6280,19 @@ var PixelLabProvider = class _PixelLabProvider {
6152
6280
  );
6153
6281
  }
6154
6282
  }
6283
+ /** Reference files must exist; a sidescroller's must be a square PNG of the tile size. */
6284
+ requireTerrainReferences(spec, tileSize) {
6285
+ for (const [side, reference] of Object.entries(spec.terrainReferences ?? {})) {
6286
+ if (!reference?.sha256) {
6287
+ throw new Error(`PixelLab terrain: the ${side} reference is missing or not a PNG: ${reference?.file}`);
6288
+ }
6289
+ if (tileSize != null && (reference.width !== tileSize || reference.height !== tileSize)) {
6290
+ throw new Error(
6291
+ `PixelLab terrain: a sidescroller set's ${side} reference must be a ${tileSize}x${tileSize} PNG; ${reference.file} is ${reference.width}x${reference.height}`
6292
+ );
6293
+ }
6294
+ }
6295
+ }
6155
6296
  validateCharacter(spec, styleImages = []) {
6156
6297
  const character = spec.character;
6157
6298
  if (!character) throw new Error(`${spec.styleId}/${spec.assetId} has no character shape`);
@@ -6929,7 +7070,12 @@ var PixelLabProvider = class _PixelLabProvider {
6929
7070
  outline: spec.outline,
6930
7071
  shading: spec.shading,
6931
7072
  detail: spec.detail,
6932
- seed: spec.seed
7073
+ seed: spec.seed,
7074
+ mode: spec.terrainMode,
7075
+ enhance: spec.terrainEnhance,
7076
+ platformThickness: spec.terrainPlatformThickness,
7077
+ lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
7078
+ transitionReferenceImage: await terrainReferenceImage(spec, "transition")
6933
7079
  });
6934
7080
  return {
6935
7081
  jobId: res2.tileset_id,
@@ -6964,7 +7110,16 @@ var PixelLabProvider = class _PixelLabProvider {
6964
7110
  shading: spec.shading,
6965
7111
  detail: spec.detail,
6966
7112
  seed: spec.seed,
6967
- targetPalette: targetPaletteFor(spec)
7113
+ targetPalette: targetPaletteFor(spec),
7114
+ shapeSeed: spec.terrainShapeSeed,
7115
+ sideWallThickness: spec.terrainSideWallThickness,
7116
+ sideWallPlacement: spec.terrainSideWallPlacement,
7117
+ enhance: spec.terrainEnhance,
7118
+ lowerWalkable: spec.terrainLowerWalkable,
7119
+ upperWalkable: spec.terrainUpperWalkable,
7120
+ lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
7121
+ upperReferenceImage: await terrainReferenceImage(spec, "upper"),
7122
+ transitionReferenceImage: await terrainReferenceImage(spec, "transition")
6968
7123
  });
6969
7124
  return {
6970
7125
  jobId: res2.tileset_id,
@@ -8143,6 +8298,16 @@ function sendsTargetPalette(spec) {
8143
8298
  return false;
8144
8299
  }
8145
8300
  }
8301
+ async function terrainReferenceImage(spec, side) {
8302
+ const reference = spec.terrainReferences?.[side];
8303
+ if (!reference) return void 0;
8304
+ if (!existsSync3(reference.file)) throw new Error(`terrain ${side} reference is missing: ${reference.file}`);
8305
+ const bytes = readFileSync(reference.file);
8306
+ if (sha256(bytes) !== reference.sha256) {
8307
+ throw new Error(`terrain ${side} reference changed after the manifest was resolved: ${reference.file}; run the command again`);
8308
+ }
8309
+ return { base64: bytes.toString("base64"), format: "png" };
8310
+ }
8146
8311
  function targetPaletteFor(spec) {
8147
8312
  if (!sendsTargetPalette(spec)) return void 0;
8148
8313
  if (!spec.palette.length && spec.maxColors == null) return void 0;
@@ -11425,6 +11590,13 @@ async function resolveSpecs(loaded, filter) {
11425
11590
  terrainBoundarySeed: generator === "terrain" ? style.terrainBoundarySeed : void 0,
11426
11591
  terrainStepSlope: generator === "terrain" ? style.terrainStepSlope : void 0,
11427
11592
  terrainConnectDiagonals: generator === "terrain" ? style.terrainConnectDiagonals : void 0,
11593
+ terrainShapeSeed: generator === "terrain" ? style.terrainShapeSeed : void 0,
11594
+ terrainSideWallThickness: generator === "terrain" ? style.terrainSideWallThickness : void 0,
11595
+ terrainSideWallPlacement: generator === "terrain" ? style.terrainSideWallPlacement : void 0,
11596
+ terrainEnhance: generator === "terrain" ? style.terrainEnhance : void 0,
11597
+ terrainPlatformThickness: generator === "terrain" ? style.terrainPlatformThickness : void 0,
11598
+ terrainLowerWalkable: generator === "terrain" ? style.terrainLowerWalkable : void 0,
11599
+ terrainUpperWalkable: generator === "terrain" ? style.terrainUpperWalkable : void 0,
11428
11600
  terrainTransitionSize: generator === "terrain" ? style.terrainTransitionSize : void 0,
11429
11601
  terrainView: generator === "terrain" ? style.terrainView : void 0,
11430
11602
  terrainOrientation: generator === "terrain" ? style.terrainOrientation : void 0,
@@ -11857,6 +12029,20 @@ async function resolveSpecs(loaded, filter) {
11857
12029
  }
11858
12030
  resolved.terrainConnect = links;
11859
12031
  }
12032
+ if (asset.terrainReferences) {
12033
+ if (resolved.generator !== "terrain") {
12034
+ throw new Error(`assets.${assetId}.terrainReferences: only a terrain set takes terrain references; style "${styleId}" uses "${resolved.generator}"`);
12035
+ }
12036
+ const references = {};
12037
+ for (const side of ["lower", "upper", "transition"]) {
12038
+ const relative = asset.terrainReferences[side];
12039
+ if (!relative) continue;
12040
+ const file = path8.resolve(root, relative);
12041
+ const image = await optionalRevisionImage(file, `terrain ${side} reference`, "png");
12042
+ references[side] = { file, sha256: image?.hash ?? null, width: image?.width ?? null, height: image?.height ?? null };
12043
+ }
12044
+ if (Object.keys(references).length) resolved.terrainReferences = references;
12045
+ }
11860
12046
  if (asset.scene) resolved.scene = await resolveMapScene(root, styleId, assetId, resolved.generator, asset.scene, activeProvider);
11861
12047
  resolved.specHash = specHash(
11862
12048
  resolved,