pixelkiln 0.117.0 → 0.118.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 +112 -24
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +111 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +110 -21
- package/dist/index.js.map +1 -1
- package/docs/ENDPOINTS.md +30 -1
- package/docs/LIBRARY.md +4 -0
- package/docs/TILES.md +87 -14
- package/package.json +1 -1
- package/skills/pixelkiln/references/tiles.md +30 -6
package/dist/cli.js
CHANGED
|
@@ -928,9 +928,9 @@ Options
|
|
|
928
928
|
|
|
929
929
|
Examples
|
|
930
930
|
pixelkiln plan
|
|
931
|
-
pixelkiln gen --style
|
|
931
|
+
pixelkiln gen --style premium --budget 400
|
|
932
932
|
pixelkiln gen --only first_review --force
|
|
933
|
-
pixelkiln gallery --style
|
|
933
|
+
pixelkiln gallery --style premium
|
|
934
934
|
pixelkiln gallery --workspace pixelkiln.workspace.json
|
|
935
935
|
pixelkiln gallery --edit --budget 80
|
|
936
936
|
pixelkiln edit --style base --only anvil
|
|
@@ -941,7 +941,7 @@ Examples
|
|
|
941
941
|
pixelkiln model normal-map knight --dry-run
|
|
942
942
|
pixelkiln model normal-map knight --source sprites --sprites art/knight/rotations --dry-run
|
|
943
943
|
pixelkiln adopt --tag
|
|
944
|
-
pixelkiln pack --style
|
|
944
|
+
pixelkiln pack --style premium
|
|
945
945
|
pixelkiln pack --inputs sprites.json --out dist/sheet # no manifest needed
|
|
946
946
|
pixelkiln pack --style hero --format aseprite # sheet JSON engines load
|
|
947
947
|
pixelkiln mount --style ground
|
|
@@ -29755,7 +29755,12 @@ function exportTileset(entry, spec, options) {
|
|
|
29755
29755
|
packed.atlas,
|
|
29756
29756
|
frames,
|
|
29757
29757
|
providerRules,
|
|
29758
|
-
rules
|
|
29758
|
+
rules,
|
|
29759
|
+
// A `terrain` set names each tile's corners in the order of its `terrainTiles`; find a
|
|
29760
|
+
// tile's entry by role. Its role ends in a number of the provider's own (`wang-13`), which
|
|
29761
|
+
// is not its place in that list.
|
|
29762
|
+
terrainRules && !normalizeTileRules(rawRules) ? terrainTileIndexes(metadata, outputs) : void 0,
|
|
29763
|
+
spec.tileType === "isometric" ? isometricFootprint(packed.png, frames) : null
|
|
29759
29764
|
);
|
|
29760
29765
|
if (options.format === "generic") {
|
|
29761
29766
|
return {
|
|
@@ -29782,13 +29787,22 @@ function exportTileset(entry, spec, options) {
|
|
|
29782
29787
|
`${options.format} export cannot infer adjacency from outline/stamp-only rules; use --format generic`
|
|
29783
29788
|
);
|
|
29784
29789
|
}
|
|
29785
|
-
if (options.format === "godot" && rules?.ruleType === "edge" && godotTileShape(spec.tileType ?? "isometric") !== 0) {
|
|
29790
|
+
if (options.format === "godot" && rules?.ruleType === "edge" && godotTileShape(spec.tileType ?? "isometric") !== 0 && (spec.tileType ?? "isometric") !== "isometric") {
|
|
29786
29791
|
throw new Error(
|
|
29787
|
-
"godot export does not yet map edge/side adjacency onto an
|
|
29792
|
+
"godot export does not yet map edge/side adjacency onto an oblique tile's diagonal peering bits safely; use --format generic or --format tiled"
|
|
29788
29793
|
);
|
|
29789
29794
|
}
|
|
29790
29795
|
return renderTileset(generic, packed, spec.tileType, options);
|
|
29791
29796
|
}
|
|
29797
|
+
function terrainTileIndexes(metadata, outputs) {
|
|
29798
|
+
const tiles = isRecord3(metadata) && Array.isArray(metadata.terrainTiles) ? metadata.terrainTiles : [];
|
|
29799
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
29800
|
+
for (const output of outputs) {
|
|
29801
|
+
const byRole = output.role ? tiles.findIndex((tile) => isRecord3(tile) && tile.role === output.role) : -1;
|
|
29802
|
+
indexes.set(output.role ?? fallbackOutputRole(output.index), byRole >= 0 ? byRole : output.index);
|
|
29803
|
+
}
|
|
29804
|
+
return indexes;
|
|
29805
|
+
}
|
|
29792
29806
|
function renderTileset(generic, packed, tileType, options) {
|
|
29793
29807
|
if (options.format === "tiled") {
|
|
29794
29808
|
return {
|
|
@@ -29858,7 +29872,56 @@ function exportMergedTilesets(members, options) {
|
|
|
29858
29872
|
assertUniformTiles(generic);
|
|
29859
29873
|
return renderTileset(generic, packed, merged.tileType, options);
|
|
29860
29874
|
}
|
|
29861
|
-
function
|
|
29875
|
+
function isometricFootprint(png, frames) {
|
|
29876
|
+
const image = decodePng(png);
|
|
29877
|
+
let best = null;
|
|
29878
|
+
for (const frame of frames) {
|
|
29879
|
+
let apex = -1;
|
|
29880
|
+
let widest = -1;
|
|
29881
|
+
let widestRow = -1;
|
|
29882
|
+
let left = frame.width;
|
|
29883
|
+
let right = -1;
|
|
29884
|
+
let count = 0;
|
|
29885
|
+
for (let row = 0; row < frame.height; row++) {
|
|
29886
|
+
let first = -1;
|
|
29887
|
+
let last = -1;
|
|
29888
|
+
let opaque2 = 0;
|
|
29889
|
+
for (let column = 0; column < frame.width; column++) {
|
|
29890
|
+
if (image.pixels[((frame.y + row) * image.width + frame.x + column) * 4 + 3] > 8) {
|
|
29891
|
+
if (first < 0) first = column;
|
|
29892
|
+
last = column;
|
|
29893
|
+
opaque2++;
|
|
29894
|
+
}
|
|
29895
|
+
}
|
|
29896
|
+
count += opaque2;
|
|
29897
|
+
if (opaque2 === 0) continue;
|
|
29898
|
+
if (apex < 0) apex = row;
|
|
29899
|
+
if (opaque2 > widest * 1 + 0.5 && last - first + 1 >= widest) {
|
|
29900
|
+
widest = opaque2;
|
|
29901
|
+
widestRow = row;
|
|
29902
|
+
left = first;
|
|
29903
|
+
right = last;
|
|
29904
|
+
}
|
|
29905
|
+
}
|
|
29906
|
+
if (apex < 0 || best && count <= best.count) continue;
|
|
29907
|
+
const apexWidth = (() => {
|
|
29908
|
+
let w = 0;
|
|
29909
|
+
for (let column = 0; column < frame.width; column++) {
|
|
29910
|
+
if (image.pixels[((frame.y + apex) * image.width + frame.x + column) * 4 + 3] > 8) w++;
|
|
29911
|
+
}
|
|
29912
|
+
return w;
|
|
29913
|
+
})();
|
|
29914
|
+
if (apexWidth * 2 > frame.width) continue;
|
|
29915
|
+
best = { apex, widest: widestRow, left, right, width: frame.width, height: frame.height, count };
|
|
29916
|
+
}
|
|
29917
|
+
if (!best) return null;
|
|
29918
|
+
const width = best.right - best.left + 1;
|
|
29919
|
+
const measured = 2 * (best.widest - best.apex) + 2;
|
|
29920
|
+
const height = Math.abs(measured - width / 2) <= Math.max(2, width * 0.1) ? Math.round(width / 2) : measured;
|
|
29921
|
+
if (height < 2 || best.apex + height > best.height) return null;
|
|
29922
|
+
return { x: best.left, y: best.apex, width, height };
|
|
29923
|
+
}
|
|
29924
|
+
function buildGeneric(identity2, imageName, atlas, frames, providerRules, rules, indexOf, footprint) {
|
|
29862
29925
|
return {
|
|
29863
29926
|
format: "pixelkiln-tileset",
|
|
29864
29927
|
version: 1,
|
|
@@ -29868,6 +29931,7 @@ function buildGeneric(identity2, imageName, atlas, frames, providerRules, rules,
|
|
|
29868
29931
|
...identity2.sets ? { sets: identity2.sets } : {},
|
|
29869
29932
|
image: imageName,
|
|
29870
29933
|
tile: { ...atlas.cell },
|
|
29934
|
+
...footprint ? { footprint } : {},
|
|
29871
29935
|
sheet: { ...atlas.sheet, columns: atlas.columns },
|
|
29872
29936
|
tiles: frames.map((frame, index) => {
|
|
29873
29937
|
const sourceIndex = indexOf?.get(frame.id) ?? tileIndex(frame.id) ?? index;
|
|
@@ -29906,6 +29970,14 @@ function buildTiled(generic) {
|
|
|
29906
29970
|
margin: 0,
|
|
29907
29971
|
spacing: 0
|
|
29908
29972
|
};
|
|
29973
|
+
if (generic.footprint) {
|
|
29974
|
+
const { x, y, width, height } = generic.footprint;
|
|
29975
|
+
tiled.tileoffset = {
|
|
29976
|
+
x: Math.round(generic.tile.width / 2 - (x + width / 2)),
|
|
29977
|
+
y: generic.tile.height - (y + height)
|
|
29978
|
+
};
|
|
29979
|
+
tiled.grid = { orientation: "isometric", width, height };
|
|
29980
|
+
}
|
|
29909
29981
|
if (!rules || rules.ruleType === "outline") return tiled;
|
|
29910
29982
|
const terrainNames = terrainNamesFor(rules);
|
|
29911
29983
|
tiled.wangsets = [{
|
|
@@ -29945,21 +30017,37 @@ function buildGodot(generic, tileType) {
|
|
|
29945
30017
|
`texture = ExtResource("1_texture")`,
|
|
29946
30018
|
`texture_region_size = Vector2i(${generic.tile.width}, ${generic.tile.height})`
|
|
29947
30019
|
];
|
|
30020
|
+
const footprint = generic.footprint;
|
|
30021
|
+
const origin = footprint ? {
|
|
30022
|
+
x: Math.round(footprint.x + footprint.width / 2 - generic.tile.width / 2),
|
|
30023
|
+
y: Math.round(footprint.y + footprint.height / 2 - generic.tile.height / 2)
|
|
30024
|
+
} : null;
|
|
29948
30025
|
for (const tile of generic.tiles) {
|
|
29949
30026
|
const x = tile.id % generic.sheet.columns;
|
|
29950
30027
|
const y = Math.floor(tile.id / generic.sheet.columns);
|
|
29951
|
-
|
|
29952
|
-
if (!rules || tile.bitmask === void 0 && tile.corners === void 0 || rules.ruleType === "outline")
|
|
30028
|
+
const shifted = origin && (origin.x !== 0 || origin.y !== 0);
|
|
30029
|
+
if (!rules || tile.bitmask === void 0 && tile.corners === void 0 || rules.ruleType === "outline") {
|
|
30030
|
+
lines.push(`${x}:${y}/0 = 0`);
|
|
30031
|
+
if (shifted) lines.push(`${x}:${y}/0/texture_origin = Vector2i(${origin.x}, ${origin.y})`);
|
|
30032
|
+
continue;
|
|
30033
|
+
}
|
|
29953
30034
|
const values = godotTerrainBits(rules, tile, shape);
|
|
29954
|
-
|
|
29955
|
-
lines.push(`${x}:${y}/
|
|
29956
|
-
for (const [
|
|
29957
|
-
lines.push(`${x}:${y}
|
|
30035
|
+
const centres = centreTerrains(values);
|
|
30036
|
+
if (centres.length > 1) lines.push(`${x}:${y}/next_alternative_id = ${centres.length}`);
|
|
30037
|
+
for (const [alternative, centre] of centres.entries()) {
|
|
30038
|
+
lines.push(`${x}:${y}/${alternative} = ${alternative}`);
|
|
30039
|
+
if (shifted) lines.push(`${x}:${y}/${alternative}/texture_origin = Vector2i(${origin.x}, ${origin.y})`);
|
|
30040
|
+
lines.push(`${x}:${y}/${alternative}/terrain_set = 0`);
|
|
30041
|
+
lines.push(`${x}:${y}/${alternative}/terrain = ${centre}`);
|
|
30042
|
+
for (const [side, value] of Object.entries(values)) {
|
|
30043
|
+
lines.push(`${x}:${y}/${alternative}/terrains_peering_bit/${side} = ${value}`);
|
|
30044
|
+
}
|
|
29958
30045
|
}
|
|
29959
30046
|
}
|
|
29960
30047
|
lines.push("", "[resource]");
|
|
29961
|
-
lines.push(`tile_size = Vector2i(${generic.tile.width}, ${generic.tile.height})`);
|
|
30048
|
+
lines.push(`tile_size = Vector2i(${footprint ? footprint.width : generic.tile.width}, ${footprint ? footprint.height : generic.tile.height})`);
|
|
29962
30049
|
if (shape !== 0) lines.push(`tile_shape = ${shape}`);
|
|
30050
|
+
if (tileType === "isometric") lines.push("tile_layout = 5");
|
|
29963
30051
|
if (rules && rules.ruleType !== "outline") {
|
|
29964
30052
|
lines.push(`terrain_set_0/mode = ${rules.ruleType === "corner" ? 1 : 2}`);
|
|
29965
30053
|
for (const [index, name] of terrainNamesFor(rules).entries()) {
|
|
@@ -29981,6 +30069,14 @@ function godotTerrainBits(rules, tile, shape) {
|
|
|
29981
30069
|
}
|
|
29982
30070
|
const mask = tile.bitmask;
|
|
29983
30071
|
const terrain = (bit) => (mask & 1 << bit) !== 0 ? 0 : 1;
|
|
30072
|
+
if (shape === 1) {
|
|
30073
|
+
return {
|
|
30074
|
+
top_right_side: terrain(0),
|
|
30075
|
+
bottom_right_side: terrain(1),
|
|
30076
|
+
bottom_left_side: terrain(2),
|
|
30077
|
+
top_left_side: terrain(3)
|
|
30078
|
+
};
|
|
30079
|
+
}
|
|
29984
30080
|
return {
|
|
29985
30081
|
top_side: terrain(0),
|
|
29986
30082
|
right_side: terrain(1),
|
|
@@ -29988,18 +30084,10 @@ function godotTerrainBits(rules, tile, shape) {
|
|
|
29988
30084
|
left_side: terrain(3)
|
|
29989
30085
|
};
|
|
29990
30086
|
}
|
|
29991
|
-
function
|
|
30087
|
+
function centreTerrains(values) {
|
|
29992
30088
|
const counts = /* @__PURE__ */ new Map();
|
|
29993
30089
|
for (const value of Object.values(values)) counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
29994
|
-
|
|
29995
|
-
let bestCount = -1;
|
|
29996
|
-
for (const [terrain, count] of [...counts].sort(([a], [b]) => a - b)) {
|
|
29997
|
-
if (count > bestCount) {
|
|
29998
|
-
best = terrain;
|
|
29999
|
-
bestCount = count;
|
|
30000
|
-
}
|
|
30001
|
-
}
|
|
30002
|
-
return best;
|
|
30090
|
+
return [...counts].sort(([a, countA], [b, countB]) => countB - countA || a - b).map(([terrain]) => terrain);
|
|
30003
30091
|
}
|
|
30004
30092
|
function godotTileShape(tileType) {
|
|
30005
30093
|
if (tileType === "isometric" || tileType === "oblique") return 1;
|