Let pixel art and vector art be nine-sliced and sorted (#308)
Nine-slice and the sort line hung on the texture frame alone. Drawing and sorting already read both off the TextureRef every picture hands out, but the generated pictures always said "no slice, no line". So the feature moves from the frame to the picture, without a second copy of any rule. - PictureCut (border, fill, sortLine) is one type. TextureFrame extends it, PixelArtAsset and VectorArtAsset carry it as a whole. The texture file format does not change, and no migration is needed. - The rules in texture.ts take a cut and a size: cutSortLine, setCutSlice, rawCutSlice and the rest replace the frame* versions. serialize.ts reads all three through one readCut. - cutTarget.ts resolves a target to cut and size: a texture frame, a pixel frame's size or the vector canvas. It lives apart from texture.ts because vectorart.ts reaches texture.ts itself. - SetSliceCommand and SetSortLineCommand take that target instead of (assetId, frameId). They refuse an asset that draws no picture. - generatedRef fills slice and sortLine from the drawing. The whole strip of a pixel art asset with several frames gets none, it is no picture of that size. With one frame asset and frame are the same. - Nine-slice scale is one shared schema row, now also on pixel art and vector art. - cutSection.ts holds the NINE-SLICE and SORTING rows once. The frame inspector and the drawing inspector both build them. - SheetCanvas draws a drawing's lines that are set, dashed as in the Texture tab. They are not dragged there, the painting tools own the canvas (as proposed in the issue). - drawOrder falls back to the picture's height when a ref has no rect, or a sort line on vector art would have been ignored. Tests: - Gate: 232 files, 3542 tests (+8: drawing-cut.test.ts, and vector art in sort-by-y.test.ts). Three counter-proofs bite: no cut on a drawing, a cut on the whole strip, no height fallback. - e2e 48: 44 checks (+1, sum 1732). 48l-ii reads red and blue where 12-pixel borders at scale 2 put them. Without borders both spots read green. - Looked at: the Pixel art tab with the lines, and the sliced sprite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9c6bbfa4d
commit
3e05cbbed5
20 files changed
+666
-300
No files matched your search
+33
-22
@@ -26,6 +26,8 @@ import type {
|
||||
Asset,
|
||||
BehaviorAsset,
|
||||
ContainerAsset,
|
||||
PictureCut,
|
||||
PixelArtAsset,
|
||||
PixelFrame,
|
||||
PixelLayer,
|
||||
SceneAsset,
|
||||
@@ -34,6 +36,7 @@ import type {
|
||||
GradientStop,
|
||||
TilemapLayer,
|
||||
VariablesAsset,
|
||||
VectorArtAsset,
|
||||
VectorGradient,
|
||||
VectorPaint,
|
||||
VectorPoint,
|
||||
@@ -59,14 +62,15 @@ import { PROJECT_FORMAT_VERSION, type Project } from '../model/Project';
|
||||
import { readScope, readSharedScope } from '../model/Scope';
|
||||
import type { ObjectGroup, SceneObject } from '../model/SceneObject';
|
||||
import {
|
||||
type CutSize,
|
||||
DEFAULT_FILL,
|
||||
isTextureFile,
|
||||
normalizeBorders,
|
||||
normalizeFrameRect,
|
||||
setCutSlice,
|
||||
setCutSortLine,
|
||||
setFrameCollision,
|
||||
setFrameSlice,
|
||||
setFrameSortLine,
|
||||
} from '../model/texture';
|
||||
import { drawnCutSize } from '../model/cutTarget';
|
||||
import { pointsOf } from '../model/polygon';
|
||||
import { canvasSide, PALETTE_MAX } from '../model/pixelart';
|
||||
import { isCelFile } from '../model/pixelCel';
|
||||
@@ -248,9 +252,13 @@ export function deserializeProject(raw: unknown, fallbackId = ''): Project {
|
||||
} else if (type === 'tilemap') {
|
||||
assets.push({ id, type, name, props, layers: normalizeLayers(a.layers) });
|
||||
} else if (type === 'vectorart') {
|
||||
assets.push({ id, type, name, props, layers: normalizeVectorLayers(a) });
|
||||
const drawing: VectorArtAsset = { id, type, name, props, layers: normalizeVectorLayers(a) };
|
||||
readCut(drawing, drawnCutSize(drawing), a);
|
||||
assets.push(drawing);
|
||||
} else if (type === 'pixelart') {
|
||||
assets.push({ id, type, name, props, ...normalizePixelArt(a, takenIds) });
|
||||
const drawing: PixelArtAsset = { id, type, name, props, ...normalizePixelArt(a, takenIds) };
|
||||
readCut(drawing, drawnCutSize(drawing), a);
|
||||
assets.push(drawing);
|
||||
} else if (type === 'palette') {
|
||||
assets.push({ id, type, name, props, colors: normalizePalette(a.colors) });
|
||||
} else if (type === 'curve') {
|
||||
@@ -664,31 +672,34 @@ function normalizeTexture(
|
||||
height,
|
||||
);
|
||||
const frame: TextureFrame = { id, name: typeof f.name === 'string' ? f.name : '', ...rect };
|
||||
// Against the frame, not the image: the borders are distances inside the cut-out. A frame
|
||||
// without them is one nobody sliced, and keeps saying so.
|
||||
const border = asRecord(f.border);
|
||||
setFrameSlice(frame, {
|
||||
border: normalizeBorders(
|
||||
{
|
||||
left: toNumber(border.left),
|
||||
top: toNumber(border.top),
|
||||
right: toNumber(border.right),
|
||||
bottom: toNumber(border.bottom),
|
||||
},
|
||||
rect.w,
|
||||
rect.h,
|
||||
),
|
||||
fill: f.fill === 'stretch' ? 'stretch' : DEFAULT_FILL,
|
||||
});
|
||||
// Against the frame, not the image: the borders are distances inside the cut-out.
|
||||
readCut(frame, rect, f);
|
||||
// Corners that are no numbers fall away; what is left is kept only as an outline (#141).
|
||||
const outlines = collisionOutlines(f.collision).filter((outline) => outline.length >= 3);
|
||||
if (outlines.length > 0) setFrameCollision(frame, outlines);
|
||||
setFrameSortLine(frame, toNumber(f.sortLine));
|
||||
frames.push(frame);
|
||||
}
|
||||
return { file, width, height, frames };
|
||||
}
|
||||
|
||||
/**
|
||||
* The nine-slice and the sort line of a texture frame or a drawing (#308), measured against `size`.
|
||||
* A picture without them is one nobody sliced, and keeps saying so.
|
||||
*/
|
||||
function readCut(cut: PictureCut, size: CutSize, raw: Record<string, unknown>): void {
|
||||
const border = asRecord(raw.border);
|
||||
setCutSlice(cut, size, {
|
||||
border: {
|
||||
left: toNumber(border.left),
|
||||
top: toNumber(border.top),
|
||||
right: toNumber(border.right),
|
||||
bottom: toNumber(border.bottom),
|
||||
},
|
||||
fill: raw.fill === 'stretch' ? 'stretch' : DEFAULT_FILL,
|
||||
});
|
||||
setCutSortLine(cut, size, toNumber(raw.sortLine));
|
||||
}
|
||||
|
||||
/**
|
||||
* A frame's stored outlines: a list of corner lists, or – as saved before a frame held several –
|
||||
* one corner list, which is one outline.
|
||||
|
||||
Reference in new issue
Block a user