import { untag } from '../../../model/Properties'; import type { NodeDef } from '../../NodeRegistry'; import { asList, asNumber, isEntity } from '../../values'; import { any, int, list } from '../shared'; export const ItemAt: NodeDef = { type: 'ItemAt', label: 'Item at', category: 'data', description: 'The item at an index, counting from 0. Out of range gives 0.', inputs: [list('list'), int('index')], outputs: [any('item')], // A color item reads as its number: the graph has no color of its own (see `portKindOf`). run: (_ctx, inputs) => { const items = asList(inputs.list); const i = Math.floor(asNumber(inputs.index)); const item = items[i]; // An object comes out as the object it is, not as its name: that is the point of a list of // objects, as `Raycast all` hands one out (#157). if (isEntity(item)) return { outputs: { item } }; return { outputs: { item: untag(item) ?? 0 } }; }, params: [], };