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>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import type { GraphLookup } from '../graph/lookup';
|
|
import { startStateOf, statesOf, transitionsOf } from '../graph/stateMachine';
|
|
import { pictureSize } from '../properties/aspect';
|
|
import { resolveAssetProps } from '../properties/resolve';
|
|
import { bagWithoutItemTypes } from './Properties';
|
|
import { typeFields } from './structTypes';
|
|
import { findAssetOf, type Project } from './Project';
|
|
import { resolvePicture } from './texture';
|
|
|
|
/**
|
|
* What a graph may see of the project around it. A behavior's `defaults` are its variable values;
|
|
* every call starts from a copy of them, except for the variables it keeps (#229).
|
|
*/
|
|
export function graphLookup(project: Project): GraphLookup {
|
|
return {
|
|
behavior: (assetId) => {
|
|
const asset = findAssetOf(project, assetId, 'behavior');
|
|
if (!asset) return null;
|
|
return {
|
|
name: asset.name,
|
|
graph: asset.graph,
|
|
defaults: bagWithoutItemTypes(resolveAssetProps(project, asset)),
|
|
kept: asset.keptVariables ?? [],
|
|
};
|
|
},
|
|
machine: (assetId) => {
|
|
const asset = findAssetOf(project, assetId, 'statemachine');
|
|
if (!asset) return null;
|
|
return {
|
|
name: asset.name,
|
|
states: statesOf(asset.graph),
|
|
transitions: transitionsOf(asset.graph),
|
|
start: startStateOf(asset.graph, asset.start),
|
|
};
|
|
},
|
|
curve: (assetId) => findAssetOf(project, assetId, 'curve')?.points ?? null,
|
|
structType: (assetId) => {
|
|
const asset = findAssetOf(project, assetId, 'struct');
|
|
return asset ? { name: asset.name, fields: typeFields(asset).map((f) => f.key) } : null;
|
|
},
|
|
textureSize: (pictureId) => {
|
|
const ref = resolvePicture(project, pictureId);
|
|
return ref ? pictureSize(ref) : null;
|
|
},
|
|
};
|
|
}
|