Put one item into a list, a struct staying whole, with Add item (#250)

A list could only grow through Join lists, and that takes its b apart:
a struct becomes one item per field and a list is joined. A list of
structs such as loot could not grow at all.

- Add item returns a new list with value as exactly one more item. A
  struct or a list goes in whole. The list that came in is left alone,
  like with Set item.
- index -1 or unset appends. Otherwise the item goes in before that
  index. An index outside the list appends, so the value is not lost.
- The rule that an item takes the kind of its slot moved out of Set item
  into fitToSlot. Both nodes use it, Set item behaves as before.
- No e2e check and no browser look. The node is covered by unit tests.

Tests:
- ./check.sh: 180 files, 2634 tests, CHECK EXIT 0
- 7 catalog cases, 4 cases in list-of-structs.test.ts, and index in the
  whole-number inputs of texture-kind.test.ts
- Counter-check: taking the value apart like Join lists fails 3 tests
- This commit alone: tsc and the three touched unit files pass
  (337 tests)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-09-27 21:07:04 +02:00
1 parent cb8a2d029a
commit b90b62886b
6 files changed
+102 -5

No files matched your search

+8 -5
View File
@@ -18,16 +18,19 @@ export const SetItem: NodeDef = {
const next = [...items];
// The slot keeps its kind: writing a number into a color item leaves a color behind, the same
// way writing into a number variable leaves a number (see `asTypeOf`).
const value = asValueItem(inputs.value);
const slot = items[i];
// An object has no kind to keep and none to take on, so it is written as it is (#157).
if (isEntity(value) || isEntity(slot)) next[i] = value;
else next[i] = nestedKind(slot) ? sameNested(slot, value) : itemLike(slot, value);
next[i] = fitToSlot(items[i], asValueItem(inputs.value));
return { outputs: { result: next } };
},
params: [],
};
/** `value` as the kind `slot` holds, the way `Set item` and `Add item` write into a list. */
export function fitToSlot(slot: ValueList[number] | undefined, value: ValueList[number]): ValueList[number] {
// An object has no kind to keep and none to take on, so it is written as it is (#157).
if (isEntity(value) || isEntity(slot)) return value;
return nestedKind(slot) ? sameNested(slot, value) : itemLike(slot, value);
}
/** Whether a slot holds a list or a struct, which may carry objects `itemLike` would not keep. */
const nestedKind = (slot: ValueList[number] | undefined): boolean => {
const kind = itemKindOf(slot as PropertyValue);