# ViewsSplitEvent

> Talos next · Since 0.7

`views-split`'s `data`: the shared camera ({@link ViewsHandle.shared}) split the window.

## Signature

```ts
export interface ViewsSplitEvent {
  /** The layout it split into. */
  layout: ViewLayout
  /** How many views: one per live target, two to four. */
  views: number
  /** The targets' spread when it split: the widest distance between two of them, metres. */
  spread: number
  /** The id of the target each view frames, view 1 first. */
  targets: string[]
}
```

Import: `import type { ViewsSplitEvent } from "@argus/api"`

## Members

| Member | Signature | Description |
|---|---|---|
| `layout` | `layout: ViewLayout` | The layout it split into. |
| `views` | `views: number` | How many views: one per live target, two to four. |
| `spread` | `spread: number` | The targets' spread when it split: the widest distance between two of them, metres. |
| `targets` | `targets: string[]` | The id of the target each view frames, view 1 first. |

## Example

The tested fixture `fixtures/recipes/couch-coop/scenes/behaviors/couch.ts`.

```ts
import type { Behavior } from "@argus/api"

/**
 * Two players on one keyboard, one screen split down the middle.
 *
 * The scene's `meta.players` (`max: 2`, `keyboard: "split"`) gives player 1 the keys on the left
 * half (WASD) and player 2 the right half (the arrows), and `spawn { for: "player", player: N }`
 * makes `p1` and `p2` theirs; the engine walks each one's controller from their own keys. This
 * behaviour does the rest: it seats player 2 and gives each player a view.
 *
 * Seating: `join: "script"` means only a script seats anyone. A lobby would wait for a press; this
 * seats the right half at once, which is also what lets a headless self-test drive player 2
 * (headless, no key or pad ever joins anyone).
 *
 * Both players home is a win: each pad emits `goal-reached` (`home.ts`), and this counts them.
 */
interface State {
  home: string[]
  won: boolean
  layout: string
  views: number
  seated: number
}

export default {
  init(ctx) {
    // No number is no seat: under `keyboard: "player"` (the default) the keyboard has no halves.
    if (ctx.players.count < 2 && typeof ctx.players.join("keyboard-right") !== "number") {
      throw new Error('player 2 was not seated: "keyboard-right" needs meta.players.keyboard "split"')
    }
    // View 1 is `ctx.camera`; view 2 has a rig of its own. Each follows its player from behind.
    ctx.views.setLayout("left-right")
    for (const [view, id] of [[1, "p1"], [2, "p2"]] as const) {
      ctx.views.set(view, "third-person", { distance: 6, yaw: 0, pitch: -15 })
      ctx.views.follow(view, id)
    }
    ctx.state.home = []
    ctx.state.won = false
    // Kept so a test can read what was set up.
    ctx.state.layout = ctx.views.layout
    ctx.state.views = ctx.views.count
    ctx.state.seated = ctx.players.count
    ctx.events.on("goal-reached", (event) => {
      const goal = (event.data as { goal?: string }).goal
      if (goal === undefined || ctx.state.home.includes(goal)) return
      ctx.state.home.push(goal)
      if (ctx.state.home.length === 2 && !ctx.state.won) {
        ctx.state.won = true
        ctx.events.emit("both-home", { home: ctx.state.home })
      }
    })
  },
} satisfies Behavior<State>
```
