# AuthorEntitySpec

> Talos 0.7 · Since 0.6

A plain entity: {@link AuthorPlacement}, its tags and its components.

## Signature

```ts
export interface AuthorEntitySpec extends AuthorPlacement {
  /** Labels that queries and scripts can find the entity by. */
  tags?: string[];
  /** The scene contract's components, each with its `type` (the resource argus://contract/scene). */
  components?: Array<{ type: string; [field: string]: unknown }>;
}
```

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

## Members

| Member | Signature | Description |
|---|---|---|
| `tags` | `tags?: string[]` | Labels that queries and scripts can find the entity by. |
| `components` | `components?: Array<{ type: string; [field: string]: unknown }>` | The scene contract's components, each with its `type` (the resource argus://contract/scene). |

## Example

The tested fixture `fixtures/recipes/collectible-and-goal/scenes/behaviors/goal-exit.ts`.

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

/**
 * The exit, which the player wins at once every coin is collected.
 *
 * It counts the `collected` events, and once `required` are in, the player walking into it wins.
 * Entering it early does nothing, so the order the coins are taken in is free.
 *
 * `goal-reached` is the event the built-in `hud` behaviour marks a goal done on. The scene's
 * `goal` components (coin-1, coin-2, exit, in that order) are what `critic.play` walks to.
 */
interface State {
  collected: string[]
  won: boolean
}

interface Props {
  /** Coins needed before the exit counts. Default 1. */
  required?: number
  /** String key shown as the objective on a win. Default `exit.won`. */
  wonKey?: string
  /** Tag the player carries. Default `player`. */
  playerTag?: string
}

export default {
  init(ctx) {
    if (!Array.isArray(ctx.state.collected)) ctx.state.collected = []
    if (typeof ctx.state.won !== "boolean") ctx.state.won = false
  },

  onEvent(ctx, event) {
    if (event.name !== "collected") return
    const goal = (event.data as { goal?: string } | null)?.goal
    if (typeof goal !== "string" || ctx.state.collected.includes(goal)) return
    ctx.state.collected.push(goal)
    ctx.events.emit("goal-reached", { goal })
  },

  onTrigger(ctx, trigger) {
    if (ctx.state.won || !trigger.entering) return
    if (!trigger.other.hasTag(ctx.props.playerTag ?? "player")) return
    if (ctx.state.collected.length < (ctx.props.required ?? 1)) return
    ctx.state.won = true
    ctx.events.emit("goal-reached", { goal: ctx.entity.id })
    // A HUD text value is a key into `meta.strings`, not the text itself.
    ctx.hud.objective(ctx.props.wonKey ?? "exit.won")
  },
} satisfies Behavior<State, Props>
```
