Read the pixel size of a texture in a graph (#262)

A graph had no way to know how big a picture is. An icon sprite with a
fixed size therefore stretched every icon of another size, an 8x8
pixel-art icon in a 16x16 slot was drawn twice as big.

- New data node Texture size. It takes a texture, a frame or a pixel
  art and hands out width and height in pixels, 0 x 0 for none.
  Wired into a sprite's width and height, the picture shows pixel for
  pixel.
- GraphLookup gets textureSize. The project answers it with the same
  pictureSize rule a sprite uses to size itself.

Tests:

- ./check.sh: 2749 tests, CHECK EXIT 0.
- 2 catalog cases (a picture, no picture) and one test against a real
  project: pixel-art sheet, single frame, missing texture.
- No e2e check and no counter-check for this node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-09-29 06:01:27 +02:00
1 parent d7d0a6e7d4
commit ef2600493f
6 files changed
+71

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import type { NodeDef } from '../../NodeRegistry';
import { asString } from '../../values';
import { num } from '../shared';
/**
* A picture's own pixel size: a texture, one of its frames or a pixel-art frame, as a sprite wears
* it. Written into a sprite's `width` and `height`, the picture shows pixel for pixel – an icon slot
* that holds pictures of different sizes stretches none of them. 0 × 0 for no picture.
*/
export const TextureSize: NodeDef = {
type: 'TextureSize',
label: 'Texture size',
category: 'data',
description: "The picture's own size in pixels, 0 × 0 for none – to show a sprite pixel for pixel.",
inputs: [
{
key: 'texture',
label: 'texture',
type: 'string',
field: { key: 'texture', label: 'Texture', kind: 'texture', default: '' },
},
],
outputs: [num('width'), num('height')],
params: [],
read: (_ctx, _params, input, _def, lookup) => {
const size = lookup.textureSize(asString(input('texture')));
return { width: size?.w ?? 0, height: size?.h ?? 0 };
},
};
+2
View File
@@ -99,6 +99,7 @@ import { IndexOf } from './data/IndexOf';
import { ItemAt } from './data/ItemAt';
import { SetItem } from './data/SetItem';
import { SubList } from './data/SubList';
import { TextureSize } from './data/TextureSize';
import { OnAnimationFinished } from './events/OnAnimationFinished';
import { OnClick } from './events/OnClick';
import { OnCollisionEnter } from './events/OnCollisionEnter';
@@ -184,6 +185,7 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
IsEnabled,
Properties,
GetPosition,
TextureSize,
NumberLiteral,
BooleanLiteral,
StringLiteral,