Query objects in bulk and filter, count or test a list (#259)
The object queries only ever returned one object: Object by name, Child by name and Find all stop at the first hit. Getting every coin, every child or every item that passes a test needed a For each with its own bookkeeping. These nodes return the whole set as a list of Object, so For each and Find can use item straight away. - Objects by name returns every scene object with that name in scene order. - Children by name returns every match below object, nearer levels first, the same order as the singular node. - Children returns the direct children, with recursive all of them level by level. - Objects of asset returns every instance of an object asset or container by the same rule as Is asset, spawned ones included. - All four take a snapshot. Destroyed objects are never in it, disabled ones are, as with the singular nodes. - Find has a Mode setting: First, All, Any and Count. First is the default and hides the row, so existing graphs look the same. - Match follows the mode of its paired Find: done with items and indices, done with any, or done with count. An unpaired Match shows First, since the pairing only comes from the wiring. - First and Any stop at the first hit, All and Count walk the list. - Changing the mode drops edges at outputs the Match no longer has, in one undo step. SetNodeParamCommand now cleans the whole graph, but only edges that were valid before the change. - The palette entry "filter" adds a Find set to All with its Match. Found on the way: - After adding the filter entry, "find" + Enter picked Filter. The entry has node type Find, counted as an exact hit, and the tie went to the alphabet. The search now ranks by the entry id. e2e 6z-v caught it. Tests: - ./check.sh: 188 files, 2746 tests, CHECK EXIT 0. - find-modes.test.ts with 11 tests, 11 catalog cases for the four nodes, the asset input guard now expects 3. - e2e 6z-vii with 3 checks: filter from the palette, Count picked in the inspector drops the items edge, a run logs 2, 2, 2, 3, 4, "0, 2". - GM_STEPS=1-6: all passed, 278 checks. - Counter-checks fail as expected: every mode stopping early (2), Match ignoring the mode (6), cleanup on the own node only (1), no recursion (2), no inOrder (2), old ranking (1). In the browser a Match ignoring the mode fails both editor checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f84defb9b6
commit
4e6aeb5f72
22 files changed
+671
-35
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { blockProblem, MATCH_INPUT, matchOf } from './findBlock';
|
||||
import { blockProblem, findMode, MATCH_INPUT, matchOf, searchOutcome, stopsAtHit } from './findBlock';
|
||||
import { edgesInto, edgesOutOf, type Graph, type GraphNode } from './Graph';
|
||||
import { type GraphLookup, NO_LOOKUP } from './lookup';
|
||||
import { BEHAVIOR_END, callEntries, runDef, terminalNode } from './nested';
|
||||
@@ -252,8 +252,9 @@ export class GraphInterpreter {
|
||||
|
||||
/**
|
||||
* A Find's rounds: its `item` and `index` are set to one element after the other, and the Match
|
||||
* closing the block reads its test anew each time, the way a loop's stop input is read. The first
|
||||
* true one ends the search. Both nodes then hold the hit, and the flow goes on from the Match.
|
||||
* closing the block reads its test anew each time, the way a loop's stop input is read. Its mode
|
||||
* says whether the first true one ends the search; the Match then holds the outcome, and the flow
|
||||
* goes on from there.
|
||||
*/
|
||||
private search(find: GraphNode, values: readonly Value[], ctx: NodeContext, depth: number): void {
|
||||
const match = matchOf(this.frame.graph, find.id);
|
||||
@@ -262,7 +263,8 @@ export class GraphInterpreter {
|
||||
ctx.log(`Find: ${blockProblem(this.frame.graph, find) ?? 'no Match closes it'}`);
|
||||
return;
|
||||
}
|
||||
let hit = -1;
|
||||
const mode = findMode(find);
|
||||
const hits: number[] = [];
|
||||
for (let round = 0; round < values.length; round++) {
|
||||
if (++this.steps > MAX_STEPS_PER_FIRE)
|
||||
throw new Error('Behavior graph exceeded the step limit (endless loop?)');
|
||||
@@ -271,18 +273,17 @@ export class GraphInterpreter {
|
||||
this.frame.outputCache.set(find.id, roundOutputs);
|
||||
this.record(find.id, roundOutputs);
|
||||
if (asBoolean(this.inputValue(match, test, ctx))) {
|
||||
hit = round;
|
||||
break;
|
||||
hits.push(round);
|
||||
if (stopsAtHit(mode)) break;
|
||||
}
|
||||
}
|
||||
this.frame.dataCache.clear();
|
||||
const found = hit >= 0;
|
||||
const outputs = found ? { item: values[hit] ?? null, index: hit } : { item: null, index: -1 };
|
||||
this.frame.outputCache.set(find.id, outputs);
|
||||
this.frame.outputCache.set(match.id, outputs);
|
||||
const outcome = searchOutcome(mode, values, hits);
|
||||
this.frame.outputCache.set(find.id, outcome.find);
|
||||
this.frame.outputCache.set(match.id, outcome.match);
|
||||
this.trace?.onNode(match.id);
|
||||
this.record(match.id, outputs);
|
||||
this.follow(match, found ? 'found' : 'notFound', ctx, depth);
|
||||
this.record(match.id, outcome.match);
|
||||
this.follow(match, outcome.next, ctx, depth);
|
||||
}
|
||||
|
||||
/** Resolves every data input: connected → pulled from the source, else the inline param. */
|
||||
|
||||
Reference in new issue
Block a user