MCPcopy Create free account
hub / github.com/esengine/esengine / execute

Method execute

packages/procgen/src/nodes/ProcGenNodes.ts:258–280  ·  view source on GitHub ↗
(node: BlueprintNode, context: unknown)

Source from the content-addressed store, hash-verified

256
257export class WeightedPickExecutor implements INodeExecutor {
258 execute(node: BlueprintNode, context: unknown): ExecutionResult {
259 const ctx = context as ProcGenContext;
260 const seed = ctx.evaluateInput(node.id, 'seed', 0) as number;
261 const index = ctx.evaluateInput(node.id, 'index', 0) as number;
262 const items = ctx.evaluateInput(node.id, 'items', []) as unknown[];
263 const weights = ctx.evaluateInput(node.id, 'weights', []) as number[];
264
265 if (items.length === 0) {
266 return { outputs: { value: null, selectedIndex: -1 } };
267 }
268
269 const rng = new SeededRandom(seed + index * 12345);
270
271 // Build weighted items
272 const weightedItems: WeightedItem<{ value: unknown; index: number }>[] = items.map((item, i) => ({
273 value: { value: item, index: i },
274 weight: weights[i] ?? 1
275 }));
276
277 const result = weightedPick(weightedItems, rng);
278
279 return { outputs: { value: result.value, selectedIndex: result.index } };
280 }
281}
282
283// =============================================================================

Callers

nothing calls this directly

Calls 3

weightedPickFunction · 0.90
evaluateInputMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected