45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
|
|
import { defineComponent } from "../component";
|
||
|
|
import { defineRelationship } from "../relationship";
|
||
|
|
|
||
|
|
// ── Task component ────────────────────────────────────
|
||
|
|
/**
|
||
|
|
* Core component for behaviour-tree tasks.
|
||
|
|
*
|
||
|
|
* `kind` determines how the task evaluates its children:
|
||
|
|
* - `"leaf"` — terminal node; external logic drives it to completion.
|
||
|
|
* - `"sequential"` — runs children one at a time, left to right.
|
||
|
|
* Succeeds when all children succeed; fails when any child fails.
|
||
|
|
* - `"parallel"` — schedules all children at once.
|
||
|
|
* Succeeds when all children succeed; fails when any child fails.
|
||
|
|
* - `"random"` — picks one child at random each time it's scheduled.
|
||
|
|
* Succeeds/fails with that child's result.
|
||
|
|
*/
|
||
|
|
export const Task = defineComponent("task", {
|
||
|
|
kind: "leaf" as "leaf" | "sequential" | "parallel" | "random",
|
||
|
|
});
|
||
|
|
|
||
|
|
export type TaskKind = typeof Task.type["kind"];
|
||
|
|
|
||
|
|
// ── Status tags (zero-size — presence is the signal) ──
|
||
|
|
/** A task that should be executed this tick. */
|
||
|
|
export const Scheduled = defineComponent("scheduled", {});
|
||
|
|
|
||
|
|
/** A task that is currently executing (multi-frame leaves). */
|
||
|
|
export const Running = defineComponent("running", {});
|
||
|
|
|
||
|
|
/** The task completed successfully. */
|
||
|
|
export const Succeeded = defineComponent("succeeded", {});
|
||
|
|
|
||
|
|
/** The task failed. */
|
||
|
|
export const Failed = defineComponent("failed", {});
|
||
|
|
|
||
|
|
/** The task was cancelled externally. */
|
||
|
|
export const Cancelled = defineComponent("cancelled", {});
|
||
|
|
|
||
|
|
/** All terminal status tags. */
|
||
|
|
export const TERMINAL_TAGS = [Succeeded, Failed, Cancelled] as const;
|
||
|
|
|
||
|
|
// ── Relationship ──────────────────────────────────────
|
||
|
|
/** Parent → child edge in the task tree. */
|
||
|
|
export const ChildOf = defineRelationship("taskChild");
|