Files
feuerwerk/src/core/graph/lookup.ts
T
adminandClaude Opus 5.5 ef2600493f 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>
2026-09-29 06:01:27 +02:00

65 lines
2.1 KiB
TypeScript

import type { VectorPoint } from '../model/Asset';
import type { PropertyBag } from '../model/Properties';
import type { Graph } from './Graph';
/** What running another behavior's graph in place needs: its nodes, its variable defaults, its name. */
export interface BehaviorProgram {
name: string;
graph: Graph;
defaults: PropertyBag;
/** The variables a call hands on to the next call from the same site (#229); absent is none. */
kept?: readonly string[];
}
/** One state of a machine: the node id is what a port and the runtime hold, the name is the label. */
export interface MachineState {
id: string;
name: string;
}
/**
* An allowed move between two states, both named by state node id, under the name `State
* transition` asks for. The name is empty until someone gives the transition one.
*/
export interface MachineTransition {
from: string;
to: string;
name: string;
}
export interface StateMachine {
name: string;
states: MachineState[];
transitions: MachineTransition[];
/** Id of the state every instance begins in, empty when the machine has no start (see #55). */
start: string;
}
/**
* What a node may look up in the project around its graph: the behaviors it can run, the state
* machines it can read, the curves a `Lerp` eases along (#247) and the struct types `Add item`
* checks (#254). One handle, so no caller can resolve a node with half of it.
*/
export interface GraphLookup {
behavior(assetId: string): BehaviorProgram | null;
machine(assetId: string): StateMachine | null;
curve(assetId: string): readonly VectorPoint[] | null;
/** A Struct asset as a run knows it: a name and field names, nothing else travels (#254). */
structType(assetId: string): StructShape | null;
/** A texture's, frame's or pixel-art frame's own size in pixels; null for no picture. */
textureSize(pictureId: string): { w: number; h: number } | null;
}
export interface StructShape {
name: string;
fields: readonly string[];
}
export const NO_LOOKUP: GraphLookup = {
behavior: () => null,
machine: () => null,
curve: () => null,
structType: () => null,
textureSize: () => null,
};