Files
feuerwerk/src/editor/debug/vectorArtHooks.ts
T
adminandClaude Opus 5.5 808e1eefc2
game-maker / gate (push) Successful in 3m2s
game-maker / suite (push) Successful in 15m29s
Clean up duplicates and dead code, and fix the + menu check (#85)
Refactoring round 9 covers everything since round 8 (14972d0): 62
commits with about 29 000 new lines in src, api, tools and tests.
Behaviour is unchanged. The one fix is in a check: e2e 04 counted 25
asset types, and the shader function from #303 makes 26, so the run
of a526e1b failed there.

Duplicate code (jscpd over src, 50 tokens, without the two licence
texts: 35 clones / 289 lines before, 29 / 232 after):

- ShaderPicture (new, viewport/shaderPicture.ts) is the picture a
  camera's shader and a particle field's shader are laid over. It
  keeps the render texture while its size holds and frees the
  replaced one once the shader holds the new one. CameraShade and
  ParticleField.shadeField drew it the same way, line for line.
- CameraShade builds its mesh on the first draw. Before, every redraw
  of a view without a camera shader built a mesh and threw it away.
- emptyHost in inspector/host.ts builds the empty host the Inspector,
  the Variables tab and the Tilemap panel start from.
- paddedQuad(null) is the plain unit quad. symbols.ts and
  shaderPasses.ts each wrote it out by hand.
- In graph/nested.ts, calls of shader functions and On behavior
  nodes are followed by one walk, `reaches`, over ids `namedBy` a
  node type.

Dead code:

- ShaderEditor.colorFieldOf and the getter CurveCanvas.snapping had
  no reader.
- 22 values used only in their own file lose their `export`. Types
  and the node catalogues of shaders and particles stay exported.
- Kept on purpose: PhysicsSystem.holdsJoint is read by tests only,
  but it is their one view of whether a joint holds.
- A pass with stricter lint rules over every file changed since
  round 8 found no bug. PixelArtEditor.started is now readonly.

Comments and docs:

- Ten comments told history ("since #190", "used to", "any more").
  They now describe what is. The bundle is md5-identical before and
  after, and the four e2e files minify to the same bytes.
- README: joint and shader function in the asset list, joints on the
  Physics row, what the Shaders page covers, two CI runners.
- e2e 04 keeps the number of asset types once, as ASSET_TYPE_COUNT.
- screenshot.png in the README is a new picture of the editor
  (3840x2160 instead of 1825x1140), taken by the user.

Tests:
- Gate on melektaus-atx: 229 files, 3514 tests, CHECK EXIT 0
  (+3 for emptyHost, +1 for the unit quad).
- e2e 1-4, 31, 63 on melektaus-atx: ALL PASSED, 195 checks. That is
  the + menu of 04, the field shader of 31 and the camera shader of
  63, both through ShaderPicture.
- No new e2e check, so the sum stays 1728.
- Counter-checks, each put back and compared with cmp: reaches that
  never goes on fails 1 test, listensTo reading the wrong parameter
  fails 1, emptyHost dropping what a panel hands in fails 1, folding
  without a relayout fails 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 17:38:39 +02:00

124 lines
6.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { findAsset } from '../../core/model/Project';
import { allShapes, treeRows } from '../../core/model/vectorTree';
import { currentGradientBar, currentLayerList, currentShapeList } from '../inspector/shapeSection';
import { activeLayerOf } from '../vectorart/activeLayer';
import { centreOf, snapButton, type HookContext } from './hookHelpers';
/** The Vector art tab (#129). */
export function vectorArtHooks({ state, editor }: HookContext) {
const { vectorArtEditor, inspector } = editor;
/** The two lists, scrolled into view first: the layers stand over the shapes. */
const shapeList = () => {
const list = currentShapeList();
if (list) inspector.reveal(list);
return list;
};
const layerList = () => {
const list = currentLayerList();
if (list) inspector.reveal(list);
return list;
};
return {
/** The Vector art tab (#129, stage 3): where a canvas pixel is, and which tool a press uses. */
vectorArt: {
current: () => vectorArtEditor.currentAssetId,
info: () => vectorArtEditor.shownInfo,
pointAt: (x: number, y: number) => vectorArtEditor.canvasToScreen(x, y),
rect: () => vectorArtEditor.canvasRect(),
tool: () => vectorArtEditor.canvas.currentTool,
snapping: () => vectorArtEditor.canvas.snapping,
cursor: () => vectorArtEditor.canvas.cursor,
snapButton: () => snapButton(vectorArtEditor.snap),
/** The picked point of the selected shape (#288), `{ ring, index }` or null. */
picked: () => vectorArtEditor.canvas.pickedAt,
/** Whether the pen has a line open that the next click would add a point to. */
drawing: () => vectorArtEditor.canvas.drawing,
/** The header's point type (#195): where to click it, what it says, and the type it reads. */
pointButton: () => ({
...centreOf(vectorArtEditor.pointButton),
text: vectorArtEditor.pointButton.text,
enabled: vectorArtEditor.pointButton.enabled,
kind: vectorArtEditor.canvas.pickedKind,
}),
/** The shapes as the model holds them, in drawing order, so a check can read points and handles exactly. */
shapes: (assetId: string) => {
const asset = findAsset(state.project, assetId);
if (!asset || asset.type !== 'vectorart') return null;
return allShapes(asset).map((shape) => ({
id: shape.id,
name: shape.name,
fill: shape.fill,
opacity: shape.opacity,
stroke: shape.stroke ? (JSON.parse(JSON.stringify(shape.stroke)) as unknown) : null,
paint: shape.paint ? (JSON.parse(JSON.stringify(shape.paint)) as unknown) : null,
rings: shape.rings.map((ring) => ({
closed: ring.closed,
points: ring.points.map((point) => ({
x: point.x,
y: point.y,
in: point.in ? { ...point.in } : null,
out: point.out ? { ...point.out } : null,
mode: point.mode ?? null,
})),
})),
}));
},
/**
* The layers (#190), lowest first: which one is worked on, and the tree of each as the list
* shows it – top row first, a group's rows one step deeper.
*/
layers: (assetId: string) => {
const asset = findAsset(state.project, assetId);
if (!asset || asset.type !== 'vectorart') return null;
const active = activeLayerOf(state, asset)?.id ?? '';
return asset.layers.map((layer) => ({
id: layer.id,
name: layer.name,
hidden: layer.hidden === true,
active: layer.id === active,
rows: treeRows(layer.items),
}));
},
/** The layer list in the inspector: the order it shows, top first, and where its parts sit. */
layerRows: () => currentLayerList()?.shownIds ?? null,
layerRowAt: (layerId: string) => layerList()?.rowGlobal(layerId) ?? null,
layerEyeAt: (layerId: string) => layerList()?.eyeGlobal(layerId) ?? null,
layerRemoveAt: (layerId: string) => layerList()?.removeGlobal(layerId) ?? null,
layerAddAt: () => layerList()?.addGlobal() ?? null,
/**
* The frame round the selection (#291) where it is drawn: its corners (top left first,
* clockwise), the middle of each edge (top first) and the knob; null while there is none.
*/
frame: () => vectorArtEditor.canvas.frameInfo,
selected: () => (state.selection?.kind === 'shape' ? state.selection.shapeId : ''),
selectedIds: () => state.selectedShapeIds,
/**
* The shape list in the inspector (#129, stage 4): the order it shows, top first, and where a
* row sits. A row carries a name that also stands in the tab, so a check cannot click it by text.
*/
shapeRows: () => currentShapeList()?.shownIds ?? null,
shapeRowAt: (shapeId: string) => shapeList()?.rowGlobal(shapeId) ?? null,
/** The cross on a shape's row. */
shapeRemoveAt: (shapeId: string) => shapeList()?.removeGlobal(shapeId) ?? null,
/** The duplicate mark on a shape's row, and where a double-click edits its name. */
shapeDuplicateAt: (shapeId: string) => shapeList()?.duplicateGlobal(shapeId) ?? null,
shapeNameAt: (shapeId: string) => shapeList()?.nameGlobal(shapeId) ?? null,
/** The field a shape's name is being edited in, with what it holds; null while none is. */
shapeRenaming: () => {
const field = currentShapeList()?.renameField;
return field ? { ...centreOf(field), value: field.value } : null;
},
/** The Paint tool (#186): its button, the "Handles" menu, and which part it shows. */
paintButton: () => centreOf(vectorArtEditor.paintButton),
paintTarget: () => ({
...centreOf(vectorArtEditor.paintTargetButton),
text: vectorArtEditor.paintTargetButton.text,
target: vectorArtEditor.canvas.paintTarget,
}),
/** A colour stop's marker, or the bar at an offset, in the inspector's fill or outline bar. */
stopAt: (part: 'fill' | 'stroke', index: number) => currentGradientBar(part)?.stopGlobal(index) ?? null,
barAt: (part: 'fill' | 'stroke', offset: number) => currentGradientBar(part)?.barGlobal(offset) ?? null,
},
};
}