import { KIND, kindLabel, type VariableKind } from '../../../properties/kinds'; import { coerceValue, flatDef, type PropertyDef } from '../../../properties/PropertySchema'; import type { NodeDef } from '../../NodeRegistry'; /** A node handing out one constant of a kind: its one setting, edited as that kind, is its output. */ function literal(type: string, kind: Exclude, description: string): NodeDef { const value: PropertyDef = kind === 'list' ? { key: 'value', label: 'Value', kind, default: [] } : kind === 'number' ? { ...flatDef('value', kind, { label: 'Value' }), step: 1 } : flatDef('value', kind, { label: 'Value' }); return { type, label: kindLabel(kind), category: 'data', description, inputs: [], outputs: [{ key: 'value', label: 'value', type: KIND[kind].travels }], params: [value], run: (_ctx, _inputs, params) => ({ outputs: { value: coerceValue(value, params.value ?? value.default) } }), }; } export const NumberLiteral = literal('Number', 'number', 'A constant number.'); export const BooleanLiteral = literal('Boolean', 'boolean', 'A constant true/false.'); export const StringLiteral = literal('String', 'text', 'A constant text.'); export const TextureLiteral = literal( 'Texture', 'texture', 'A constant picture: a texture or one of its frames, as a sprite wears it.', ); export const StateMachineLiteral = literal( 'StateMachine', 'statemachine', 'A constant state machine, for a "State branch" or a "Set state" to work on.', ); export const SoundLiteral = literal( 'Sound', 'sound', 'A constant sound, for a "Play sound" or a "Stop sound" to work on.', ); export const SceneLiteral = literal( 'Scene', 'scene', 'A constant scene, for a "Load scene" to work on.', ); export const AnimationLiteral = literal( 'Animation', 'animation', 'A constant animation, for a "Play animation", "Pause animation" or "Stop animation" to work on.', ); export const ListLiteral = literal( 'List', 'list', 'A constant list, edited item by item in the List tab – each item with its own kind.', );