(node: BlueprintNode, context: unknown)
| 256 | |
| 257 | export 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 | // ============================================================================= |
nothing calls this directly
no test coverage detected