| 310 | * jedes aktiven Akteurs, und was `none` ergibt, steht darin, neuestes zuerst. |
| 311 | */ |
| 312 | export function buildAgentsView(input: AgentsViewInput): AgentsView { |
| 313 | const index = input.index ?? buildPlacementIndex(input.nodes); |
| 314 | const byId = nodeById(input.nodes); |
| 315 | const active = activeActors(input.state, input.now); |
| 316 | const letters = agentLetters(active.map((actor) => ({ id: actor.id, name: actor.name }))); |
| 317 | |
| 318 | const all = active.map((actor) => |
| 319 | viewOf(actor, letters.get(actor.id) ?? '?', input, index, byId)); |
| 320 | |
| 321 | const shown = all.filter((actor) => { |
| 322 | if (input.filter === 'both') { |
| 323 | return true; |
| 324 | } |
| 325 | return input.filter === 'you' ? actor.you : !actor.you; |
| 326 | }); |
| 327 | |
| 328 | /* |
| 329 | * Der Deckel greift an der GEZEICHNETEN Liste und nicht an der gezeigten. |
| 330 | * |
| 331 | * Die Reihenfolge ist die von `activeActors`: die juengste Bewegung zuerst. |
| 332 | * Wer ueber den Deckel faellt, ist damit der, dessen letztes Ereignis am |
| 333 | * laengsten her ist, und er steht weiter im Instrument, mit allen Zahlen. |
| 334 | * Was fehlt, ist sein Koerper auf dem Graphen, und genau das sagt das |
| 335 | * Instrument in einer eigenen Zeile. |
| 336 | */ |
| 337 | const cap = input.cap ?? DRAWN_BODIES_CAP; |
| 338 | const actors = shown.map((actor, position) => ({ ...actor, drawn: position < cap })); |
| 339 | const capped = Math.max(0, shown.length - cap); |
| 340 | /* |
| 341 | * Auch die ungefilterte Liste traegt den Deckel, damit sie nicht behauptet, |
| 342 | * es waeren neun Koerper gezeichnet, wo acht stehen. Sie ist die Liste, an |
| 343 | * der der Kopf zaehlt und an der der Beweislauf liest. |
| 344 | */ |
| 345 | const drawnIds = new Set(actors.filter((actor) => actor.drawn).map((actor) => actor.id)); |
| 346 | const allWithCap = all.map((actor) => ({ ...actor, drawn: drawnIds.has(actor.id) })); |
| 347 | |
| 348 | const unmapped: UnmappedEvent[] = []; |
| 349 | const seen = new Set<string>(); |
| 350 | for (const actor of active) { |
| 351 | for (let i = actor.events.length - 1; i >= 0; i -= 1) { |
| 352 | const event = actor.events[i] as AgentEvent; |
| 353 | // Die Art wird je Ereignis gefragt und nicht vom Akteur genommen: |
| 354 | // die Art des Akteurs ist die seines LETZTEN Ereignisses, und ein |
| 355 | // Testlauf von eben macht ein Lesen von vorhin nicht zu einem. |
| 356 | const placement = placeEvent(event, workKindOf(event.tool, event.detail), index); |
| 357 | if (placement.kind !== 'none') { |
| 358 | continue; |
| 359 | } |
| 360 | const key = `${event.run}:${event.seq}`; |
| 361 | if (seen.has(key)) { |
| 362 | continue; |
| 363 | } |
| 364 | seen.add(key); |
| 365 | unmapped.push({ |
| 366 | ts: event.ts, |
| 367 | agent: event.agent, |
| 368 | tool: event.tool, |
| 369 | path: event.path, |