pixelkiln 0.111.0 → 0.113.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
@@ -507,7 +507,7 @@ function parseArgs(argv) {
507
507
  }
508
508
  const manifest = get("--manifest") ?? "pixelkiln.manifest.json";
509
509
  const rawFormat = get("--format");
510
- const formats = command === "export" ? ["generic", "tiled", "godot"] : command === "asset" ? ["zip", "spritesheet", "aseprite", "gif"] : ["generic", "aseprite", "godot"];
510
+ const formats = command === "export" ? ["generic", "tiled", "godot", "ldtk"] : command === "asset" ? ["zip", "spritesheet", "aseprite", "gif"] : ["generic", "aseprite", "godot"];
511
511
  if (rawFormat && !formats.includes(rawFormat)) {
512
512
  throw new UsageError(`--format must be ${formats.slice(0, -1).join(", ")}, or ${formats.at(-1)}, got "${rawFormat}"`);
513
513
  }
@@ -803,7 +803,7 @@ Options
803
803
  --columns <n> pack/export: sprites or tiles per row (default: near-square)
804
804
  --port <n> Local review/gallery server port (default: choose a free port)
805
805
  --inputs <path> pack/quality snapshot: JSON input list; needs --out
806
- --format <format> export: generic (default), tiled, or godot (TileSet)
806
+ --format <format> export: generic (default), tiled, godot (TileSet), or ldtk
807
807
  pack/mount: generic (default), aseprite, or godot (SpriteFrames)
808
808
  --output-role <r> pack: include only this output role (repeatable)
809
809
  --primary-only pack: include only unambiguous primary/single outputs
@@ -29074,6 +29074,374 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
29074
29074
  };
29075
29075
  }
29076
29076
 
29077
+ // src/pipeline/ldtk-export.ts
29078
+ import { createHash as createHash7 } from "crypto";
29079
+ var LDTK_JSON_VERSION = "1.5.3";
29080
+ var FIRST = 1;
29081
+ var SECOND = 2;
29082
+ var DEMO_WIDTH = 12;
29083
+ var DEMO_HEIGHT = 9;
29084
+ function ldtkRuleMatches(rule, grid, cx, cy) {
29085
+ const radius = Math.floor(rule.size / 2);
29086
+ for (let py = 0; py < rule.size; py++) {
29087
+ for (let px = 0; px < rule.size; px++) {
29088
+ const wanted = rule.pattern[px + py * rule.size];
29089
+ if (wanted === 0) continue;
29090
+ const x = cx + px - radius;
29091
+ const y = cy + py - radius;
29092
+ const inside2 = x >= 0 && y >= 0 && x < grid.width && y < grid.height;
29093
+ const value = inside2 ? grid.cells[y * grid.width + x] : rule.outOfBoundsValue;
29094
+ if (wanted > 0 && value !== wanted) return false;
29095
+ if (wanted < 0 && value === -wanted) return false;
29096
+ }
29097
+ }
29098
+ return true;
29099
+ }
29100
+ function iid(...parts) {
29101
+ const hex2 = createHash7("sha256").update(parts.join("\0")).digest("hex");
29102
+ return `${hex2.slice(0, 8)}-${hex2.slice(8, 12)}-4${hex2.slice(13, 16)}-8${hex2.slice(17, 20)}-${hex2.slice(20, 32)}`;
29103
+ }
29104
+ function identifier(text, fallback) {
29105
+ const slug3 = text.replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
29106
+ return /^[A-Za-z]/.test(slug3) ? slug3 : slug3 ? `${fallback}_${slug3}` : fallback;
29107
+ }
29108
+ function dominantValue(mask) {
29109
+ const first = [0, 1, 2, 3].filter((bit) => (mask & 1 << bit) !== 0).length;
29110
+ return first * 2 >= 4 ? FIRST : SECOND;
29111
+ }
29112
+ function ldtkPattern(rules, mask) {
29113
+ const value = (bit) => (mask & 1 << bit) !== 0 ? FIRST : SECOND;
29114
+ const pattern = new Array(9).fill(0);
29115
+ if (rules.ruleType === "corner") {
29116
+ pattern[4] = value(3);
29117
+ pattern[5] = value(2);
29118
+ pattern[7] = value(1);
29119
+ pattern[8] = value(0);
29120
+ return pattern;
29121
+ }
29122
+ pattern[4] = dominantValue(mask);
29123
+ pattern[1] = value(0);
29124
+ pattern[5] = value(1);
29125
+ pattern[7] = value(2);
29126
+ pattern[3] = value(3);
29127
+ return pattern;
29128
+ }
29129
+ function resolveLdtkTiles(rules, grid) {
29130
+ const out = [];
29131
+ for (let cy = 0; cy < grid.height; cy++) {
29132
+ for (let cx = 0; cx < grid.width; cx++) {
29133
+ const rule = rules.find((candidate) => ldtkRuleMatches(candidate, grid, cx, cy));
29134
+ if (rule) out.push({ cx, cy, rule, tile: rule.tileRectsIds[(cx * 7 + cy * 13) % rule.tileRectsIds.length][0] });
29135
+ }
29136
+ }
29137
+ return out;
29138
+ }
29139
+ function demoGrid(rules, wanted) {
29140
+ let best = null;
29141
+ let bestCovered = -1;
29142
+ for (let seed = 1; seed <= 400; seed++) {
29143
+ let state = seed * 2654435761 >>> 0;
29144
+ const cells = Array.from({ length: DEMO_WIDTH * DEMO_HEIGHT }, () => {
29145
+ state = Math.imul(state, 1664525) + 1013904223 >>> 0;
29146
+ return (state >>> 16) % 100 < 52 ? FIRST : SECOND;
29147
+ });
29148
+ const grid = { width: DEMO_WIDTH, height: DEMO_HEIGHT, cells };
29149
+ const covered = new Set(resolveLdtkTiles(rules, grid).map((hit) => hit.rule.uid)).size;
29150
+ if (covered > bestCovered) {
29151
+ best = grid;
29152
+ bestCovered = covered;
29153
+ }
29154
+ if (covered >= wanted) break;
29155
+ }
29156
+ return best;
29157
+ }
29158
+ var TERRAIN_COLORS = ["#5AB552", "#4C78A8"];
29159
+ function buildLdtk(generic, tileType) {
29160
+ const rules = generic.rules;
29161
+ if (!rules || rules.ruleType === "outline") {
29162
+ throw new Error("ldtk export needs recognized corner or edge adjacency rules; use --format generic");
29163
+ }
29164
+ if (tileType === void 0 || tileType === "isometric" || tileType === "oblique" || tileType === "hex" || tileType === "hex_pointy") {
29165
+ throw new Error(
29166
+ `ldtk export needs square tiles on an orthogonal grid, and this set is ${tileType ?? "isometric"}; use --format generic or --format tiled`
29167
+ );
29168
+ }
29169
+ const grid = generic.tile.width;
29170
+ if (generic.tile.width !== generic.tile.height) {
29171
+ throw new Error(`ldtk grids are square; these tiles are ${generic.tile.width}x${generic.tile.height}`);
29172
+ }
29173
+ const corner = rules.ruleType === "corner";
29174
+ const base = identifier(generic.name.replace("/", "_"), "Tileset");
29175
+ const name = base.charAt(0).toUpperCase() + base.slice(1);
29176
+ const terrainNames = [rules.terrains[0] ?? "feature", rules.terrains[1] ?? "background"];
29177
+ const columns = generic.sheet.columns;
29178
+ const rows = Math.ceil(generic.tiles.length / columns);
29179
+ const byMask = /* @__PURE__ */ new Map();
29180
+ for (const tile of generic.tiles) {
29181
+ if (tile.bitmask === void 0) continue;
29182
+ byMask.set(tile.bitmask, [...byMask.get(tile.bitmask) ?? [], tile.id]);
29183
+ }
29184
+ if (!byMask.size) throw new Error("ldtk export found no tiles with adjacency masks; use --format generic");
29185
+ const tilesetUid = 1;
29186
+ const sourceUid = 2;
29187
+ const autoUid = 3;
29188
+ const groupUid = 4;
29189
+ const ruleList = [...byMask.entries()].map(([mask, ids], index) => ({
29190
+ uid: 5 + index,
29191
+ active: true,
29192
+ size: 3,
29193
+ tileRectsIds: ids.map((id) => [id]),
29194
+ alpha: 1,
29195
+ chance: 1,
29196
+ breakOnMatch: true,
29197
+ pattern: ldtkPattern(rules, mask),
29198
+ flipX: false,
29199
+ flipY: false,
29200
+ xModulo: 1,
29201
+ yModulo: 1,
29202
+ xOffset: 0,
29203
+ yOffset: 0,
29204
+ tileXOffset: 0,
29205
+ tileYOffset: 0,
29206
+ tileRandomXMin: 0,
29207
+ tileRandomXMax: 0,
29208
+ tileRandomYMin: 0,
29209
+ tileRandomYMax: 0,
29210
+ checker: "None",
29211
+ tileMode: "Single",
29212
+ pivotX: 0,
29213
+ pivotY: 0,
29214
+ outOfBoundsValue: SECOND,
29215
+ invalidated: false,
29216
+ perlinActive: false,
29217
+ perlinSeed: 1,
29218
+ perlinScale: 0.2,
29219
+ perlinOctaves: 2
29220
+ }));
29221
+ const levelUid = 5 + ruleList.length;
29222
+ const nextUid = levelUid + 1;
29223
+ const tileRect = (id) => {
29224
+ const tile = generic.tiles.find((candidate) => candidate.id === id);
29225
+ return tile ? { tilesetUid, x: tile.x, y: tile.y, w: tile.width, h: tile.height } : null;
29226
+ };
29227
+ const full = (1 << rules.arity) - 1;
29228
+ const representative = (terrain) => generic.tiles.find((tile) => tile.bitmask === (terrain === 0 ? full : 0))?.id;
29229
+ const shift = corner ? -Math.floor(grid / 2) : 0;
29230
+ const sourceName = `${name}_${corner ? "corners" : "cells"}`;
29231
+ const autoName = name;
29232
+ const layerBase = {
29233
+ guideGridWid: 0,
29234
+ guideGridHei: 0,
29235
+ displayOpacity: 1,
29236
+ inactiveOpacity: 1,
29237
+ hideInList: false,
29238
+ hideFieldsWhenInactive: false,
29239
+ canSelectWhenInactive: true,
29240
+ parallaxFactorX: 0,
29241
+ parallaxFactorY: 0,
29242
+ parallaxScaling: true,
29243
+ requiredTags: [],
29244
+ excludedTags: [],
29245
+ autoTilesKilledByOtherLayerUid: null,
29246
+ uiFilterTags: [],
29247
+ useAsyncRender: false,
29248
+ tilePivotX: 0,
29249
+ tilePivotY: 0,
29250
+ biomeFieldUid: null,
29251
+ gridSize: grid,
29252
+ tilesetDefUid: tilesetUid
29253
+ };
29254
+ const sourceLayer = {
29255
+ __type: "IntGrid",
29256
+ identifier: sourceName,
29257
+ type: "IntGrid",
29258
+ uid: sourceUid,
29259
+ doc: corner ? `Paint ${terrainNames[0]} (1) and ${terrainNames[1]} (2). Each cell is a corner where four tiles meet, so it is drawn half a tile up and left of the tiles it controls.` : `Paint ${terrainNames[0]} (1) and ${terrainNames[1]} (2). Each tile looks at its own cell and the four around it.`,
29260
+ uiColor: TERRAIN_COLORS[0],
29261
+ ...layerBase,
29262
+ renderInWorldView: true,
29263
+ pxOffsetX: shift,
29264
+ pxOffsetY: shift,
29265
+ intGridValues: [FIRST, SECOND].map((value, index) => ({
29266
+ value,
29267
+ identifier: identifier(terrainNames[index], `terrain${value}`),
29268
+ color: TERRAIN_COLORS[index],
29269
+ tile: tileRect(representative(index)),
29270
+ groupUid: 0
29271
+ })),
29272
+ intGridValuesGroups: [],
29273
+ autoRuleGroups: [],
29274
+ autoSourceLayerDefUid: null
29275
+ };
29276
+ const autoLayer = {
29277
+ __type: "AutoLayer",
29278
+ identifier: autoName,
29279
+ type: "AutoLayer",
29280
+ uid: autoUid,
29281
+ doc: `Drawn by rules from ${sourceName}: one rule for each way the two terrains can meet.`,
29282
+ uiColor: TERRAIN_COLORS[1],
29283
+ ...layerBase,
29284
+ renderInWorldView: true,
29285
+ pxOffsetX: 0,
29286
+ pxOffsetY: 0,
29287
+ intGridValues: [],
29288
+ intGridValuesGroups: [],
29289
+ autoRuleGroups: [{
29290
+ uid: groupUid,
29291
+ name: "Borders",
29292
+ color: null,
29293
+ icon: null,
29294
+ active: true,
29295
+ isOptional: false,
29296
+ rules: ruleList,
29297
+ usesWizard: false,
29298
+ requiredBiomeValues: [],
29299
+ biomeRequirementMode: 0
29300
+ }],
29301
+ autoSourceLayerDefUid: sourceUid
29302
+ };
29303
+ const level = demoGrid(ruleList, ruleList.length);
29304
+ const hits = resolveLdtkTiles(ruleList, level);
29305
+ const tileAt = (id) => ({ x: id % columns * grid, y: Math.floor(id / columns) * grid });
29306
+ const instanceBase = (layerDef, offset) => ({
29307
+ __identifier: layerDef.identifier,
29308
+ __type: layerDef.__type,
29309
+ __cWid: DEMO_WIDTH,
29310
+ __cHei: DEMO_HEIGHT,
29311
+ __gridSize: grid,
29312
+ __opacity: 1,
29313
+ __pxTotalOffsetX: offset,
29314
+ __pxTotalOffsetY: offset,
29315
+ __tilesetDefUid: tilesetUid,
29316
+ __tilesetRelPath: generic.image,
29317
+ iid: iid(generic.name, "layer", layerDef.uid),
29318
+ levelId: levelUid,
29319
+ layerDefUid: layerDef.uid,
29320
+ pxOffsetX: 0,
29321
+ pxOffsetY: 0,
29322
+ visible: true,
29323
+ optionalRules: [],
29324
+ seed: 1e3 + layerDef.uid,
29325
+ overrideTilesetUid: null,
29326
+ gridTiles: [],
29327
+ entityInstances: []
29328
+ });
29329
+ const project2 = {
29330
+ __header__: {
29331
+ fileType: "LDtk Project JSON",
29332
+ app: "LDtk",
29333
+ doc: "https://ldtk.io/json",
29334
+ schema: "https://ldtk.io/files/JSON_SCHEMA.json",
29335
+ appAuthor: "Sebastien 'deepnight' Benard",
29336
+ appVersion: LDTK_JSON_VERSION,
29337
+ url: "https://ldtk.io"
29338
+ },
29339
+ iid: iid(generic.name, "project"),
29340
+ jsonVersion: LDTK_JSON_VERSION,
29341
+ appBuildId: 473702,
29342
+ nextUid,
29343
+ identifierStyle: "Capitalize",
29344
+ toc: [],
29345
+ worldLayout: "LinearHorizontal",
29346
+ worldGridWidth: 256,
29347
+ worldGridHeight: 256,
29348
+ defaultLevelWidth: DEMO_WIDTH * grid,
29349
+ defaultLevelHeight: DEMO_HEIGHT * grid,
29350
+ defaultPivotX: 0,
29351
+ defaultPivotY: 0,
29352
+ defaultGridSize: grid,
29353
+ defaultEntityWidth: grid,
29354
+ defaultEntityHeight: grid,
29355
+ bgColor: "#4A5066",
29356
+ defaultLevelBgColor: "#474B67",
29357
+ minifyJson: false,
29358
+ externalLevels: false,
29359
+ exportTiled: false,
29360
+ simplifiedExport: false,
29361
+ imageExportMode: "None",
29362
+ exportLevelBg: true,
29363
+ pngFilePattern: null,
29364
+ backupOnSave: false,
29365
+ backupLimit: 10,
29366
+ backupRelPath: null,
29367
+ levelNamePattern: "%world_Level_%idx",
29368
+ tutorialDesc: null,
29369
+ customCommands: [],
29370
+ flags: ["ExportOldTableOfContentData", "UseMultilinesType"],
29371
+ defs: {
29372
+ layers: [autoLayer, sourceLayer],
29373
+ entities: [],
29374
+ tilesets: [{
29375
+ __cWid: columns,
29376
+ __cHei: rows,
29377
+ identifier: `${name}_tiles`,
29378
+ uid: tilesetUid,
29379
+ relPath: generic.image,
29380
+ embedAtlas: null,
29381
+ pxWid: generic.sheet.width,
29382
+ pxHei: generic.sheet.height,
29383
+ tileGridSize: grid,
29384
+ spacing: 0,
29385
+ padding: 0,
29386
+ tags: [],
29387
+ tagsSourceEnumUid: null,
29388
+ enumTags: [],
29389
+ customData: generic.tiles.filter((tile) => tile.bitmask !== void 0).map((tile) => ({ tileId: tile.id, data: `mask=${tile.bitmask}` })),
29390
+ savedSelections: [],
29391
+ cachedPixelData: null
29392
+ }],
29393
+ enums: [],
29394
+ externalEnums: [],
29395
+ levelFields: []
29396
+ },
29397
+ levels: [{
29398
+ identifier: "Preview",
29399
+ iid: iid(generic.name, "level"),
29400
+ uid: levelUid,
29401
+ // A linear world ignores the position; LDtk itself writes -1 for it.
29402
+ worldX: -1,
29403
+ worldY: -1,
29404
+ worldDepth: 0,
29405
+ pxWid: DEMO_WIDTH * grid,
29406
+ pxHei: DEMO_HEIGHT * grid,
29407
+ __bgColor: "#474B67",
29408
+ bgColor: null,
29409
+ useAutoIdentifier: false,
29410
+ bgRelPath: null,
29411
+ bgPos: null,
29412
+ bgPivotX: 0.5,
29413
+ bgPivotY: 0.5,
29414
+ __smartColor: "#9A9CAB",
29415
+ __bgPos: null,
29416
+ externalRelPath: null,
29417
+ fieldInstances: [],
29418
+ layerInstances: [
29419
+ {
29420
+ ...instanceBase(autoLayer, 0),
29421
+ intGridCsv: [],
29422
+ autoLayerTiles: hits.map((hit) => ({
29423
+ px: [hit.cx * grid, hit.cy * grid],
29424
+ src: [tileAt(hit.tile).x, tileAt(hit.tile).y],
29425
+ f: 0,
29426
+ t: hit.tile,
29427
+ d: [hit.rule.uid, hit.cy * DEMO_WIDTH + hit.cx],
29428
+ a: 1
29429
+ }))
29430
+ },
29431
+ {
29432
+ ...instanceBase(sourceLayer, shift),
29433
+ intGridCsv: level.cells,
29434
+ autoLayerTiles: []
29435
+ }
29436
+ ],
29437
+ __neighbours: []
29438
+ }],
29439
+ worlds: [],
29440
+ dummyWorldIid: iid(generic.name, "world")
29441
+ };
29442
+ return JSON.stringify(project2, null, 2) + "\n";
29443
+ }
29444
+
29077
29445
  // src/pipeline/tileset-export.ts
29078
29446
  function normalizeTileRules(raw) {
29079
29447
  if (!isRecord2(raw)) return null;
@@ -29190,6 +29558,15 @@ function exportTileset(entry, spec, options) {
29190
29558
  sources: packed.sources
29191
29559
  };
29192
29560
  }
29561
+ if (options.format === "ldtk") {
29562
+ return {
29563
+ png: packed.png,
29564
+ extension: ".ldtk",
29565
+ document: buildLdtk(generic, spec.tileType),
29566
+ generic,
29567
+ sources: packed.sources
29568
+ };
29569
+ }
29193
29570
  return {
29194
29571
  png: packed.png,
29195
29572
  extension: ".tres",
@@ -29649,7 +30026,7 @@ async function runExport(args) {
29649
30026
  const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
29650
30027
  const style = loaded.manifest.styles[spec.styleId];
29651
30028
  const defaultBase = path53.resolve(manifestDir, style.outDir, `${spec.assetId}-tileset`);
29652
- const base = args.out ? path53.resolve(args.out.replace(/\.(?:png|json|tsj|tres)$/i, "")) : defaultBase;
30029
+ const base = args.out ? path53.resolve(args.out.replace(/\.(?:png|json|tsj|tres|ldtk)$/i, "")) : defaultBase;
29653
30030
  const result = exportTileset(entry, spec, {
29654
30031
  format,
29655
30032
  manifestDir,
@@ -29698,7 +30075,7 @@ import { readFile as readFile40 } from "fs/promises";
29698
30075
  import path57 from "path";
29699
30076
 
29700
30077
  // src/codex-vfx.ts
29701
- import { createHash as createHash7 } from "crypto";
30078
+ import { createHash as createHash8 } from "crypto";
29702
30079
  import { existsSync as existsSync46, readFileSync as readFileSync9, readdirSync as readdirSync2 } from "fs";
29703
30080
  import { readFile as readFile38 } from "fs/promises";
29704
30081
  import { createRequire as createRequire2 } from "module";
@@ -29867,7 +30244,7 @@ function loadCodex(from) {
29867
30244
  }] : []
29868
30245
  );
29869
30246
  if (!catalogue.length) throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) loaded no effects`, "capability");
29870
- const engineSha256 = createHash7("sha256").update(sources.join("\n")).digest("hex").slice(0, 12);
30247
+ const engineSha256 = createHash8("sha256").update(sources.join("\n")).digest("hex").slice(0, 12);
29871
30248
  return { version, engineSha256, engine, catalogue, loadErrors };
29872
30249
  }
29873
30250
  function listCodexEffects(lib) {