diff --git a/examples/ghosthunting.js b/examples/ghosthunting.js index e7effd7b..963fe143 100644 --- a/examples/ghosthunting.js +++ b/examples/ghosthunting.js @@ -256,8 +256,8 @@ function addEnemy(p) { }), // Patrol can make the enemy follow a computed path patrol({ speed: 100 }), - // Navigator can compute a path given a graph - navigation({ + // Pathfinder can compute a path given a graph + pathfinder({ graph: nav, navigationOpt: { type: "edges", diff --git a/src/components/level/index.ts b/src/components/level/index.ts index e6cbbb7b..b49f382b 100644 --- a/src/components/level/index.ts +++ b/src/components/level/index.ts @@ -1,5 +1,5 @@ export * from "./agent"; -export * from "./navigation"; +export * from "./pathfinder"; export * from "./patrol"; export * from "./sentry"; export * from "./tile"; diff --git a/src/components/level/navigation.ts b/src/components/level/pathfinder.ts similarity index 75% rename from src/components/level/navigation.ts rename to src/components/level/pathfinder.ts index e0741167..7f8bbdde 100644 --- a/src/components/level/navigation.ts +++ b/src/components/level/pathfinder.ts @@ -3,7 +3,7 @@ import { type Graph } from "../../math/navigation"; import type { Comp, GameObj } from "../../types"; import type { PosComp } from "../transform/pos"; -export interface NavigationMapComp extends Comp { +export interface PathfinderMapComp extends Comp { /* * Get navigation waypoints to reach the given target from the given origin. */ @@ -18,19 +18,19 @@ export interface NavigationMapComp extends Comp { graph: Graph | undefined; } -export interface NavigationMapCompOpt { +export interface PathfinderMapCompOpt { /* - * The graph to use for navigation. If null, the ancestors are queried for a navigatorMap component. + * The graph to use for navigation. If null, the ancestors are queried for a pathfinderMap component. */ graph?: Graph; } -export function navigationMap( - opts: NavigationMapCompOpt, -): NavigationMapComp { +export function pathfinderMap( + opts: PathfinderMapCompOpt, +): PathfinderMapComp { let graph = opts.graph; return { - id: "navigatorMap", + id: "pathfinderMap", get graph(): Graph | undefined { return graph; }, @@ -38,7 +38,7 @@ export function navigationMap( graph = value; }, navigate( - this: GameObj, + this: GameObj, origin: Vec2, target: Vec2, navigationOpt: any = {}, @@ -48,7 +48,7 @@ export function navigationMap( }; } -export interface NavigationComp extends Comp { +export interface PathfinderComp extends Comp { /* * Get navigation waypoints to reach the given target from the current position. */ @@ -59,9 +59,9 @@ export interface NavigationComp extends Comp { graph: Graph | undefined; } -export interface NavigationCompOpt { +export interface PathfinderCompOpt { /* - * The graph to use for navigation. If null, the ancestors are queried for a navigatorMap component. + * The graph to use for navigation. If null, the ancestors are queried for a pathfinderMap component. */ graph?: Graph; /* @@ -70,15 +70,15 @@ export interface NavigationCompOpt { navigationOpt?: any; } -export function navigation( - opts: NavigationCompOpt, -): NavigationComp { +export function pathfinder( + opts: PathfinderCompOpt, +): PathfinderComp { let graph = opts.graph; return { - id: "navigator", + id: "pathfinder", require: ["pos"], navigateTo( - this: GameObj, + this: GameObj, target: Vec2, ): Vec2[] | undefined { const graph: Graph | undefined = this.graph; @@ -89,9 +89,9 @@ export function navigation( return graph; } let parent: GameObj | null = - (this as unknown as GameObj).parent; + (this as unknown as GameObj).parent; while (parent) { - if (parent.is("navigatormap")) { + if (parent.is("pathfinderMap")) { return parent.graph; } parent = parent.parent; diff --git a/src/index.ts b/src/index.ts index 999ff223..6eedcf26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,16 +57,16 @@ export type { LifespanCompOpt, MaskComp, NamedComp, - NavigationComp, - NavigationCompOpt, - NavigationMapComp, - NavigationMapCompOpt, OffScreenComp, OffScreenCompOpt, OpacityComp, OutlineComp, ParticlesComp, ParticlesOpt, + PathfinderComp, + PathfinderCompOpt, + PathfinderMapComp, + PathfinderMapCompOpt, PatrolComp, PatrolCompOpt, PlatformEffectorComp, diff --git a/src/kaplay.ts b/src/kaplay.ts index ea999222..c84c2755 100644 --- a/src/kaplay.ts +++ b/src/kaplay.ts @@ -189,11 +189,11 @@ import { mask, move, named, - navigation, offscreen, opacity, outline, particles, + pathfinder, patrol, pointEffector, polygon, @@ -1123,7 +1123,7 @@ const kaplay = < agent, sentry, patrol, - navigation, + pathfinder, // group events on, onFixedUpdate, diff --git a/src/math/navigation.ts b/src/math/navigation.ts index 6807e66b..07e39b49 100644 --- a/src/math/navigation.ts +++ b/src/math/navigation.ts @@ -1,4 +1,4 @@ -import { BinaryHeap } from "../utils/"; +import { BinaryHeap } from "../utils"; import { Vec2 } from "./math"; export interface Graph { diff --git a/src/types.ts b/src/types.ts index ee5cebb5..92bc16e7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -40,12 +40,12 @@ import type { LifespanCompOpt, MaskComp, NamedComp, - NavigationComp, - NavigationCompOpt, OffScreenComp, OffScreenCompOpt, OpacityComp, OutlineComp, + PathfinderComp, + PathfinderCompOpt, PatrolComp, PatrolCompOpt, PointEffectorComp, @@ -977,12 +977,12 @@ export interface KAPLAYCtx< */ patrol(opts: PatrolCompOpt): PatrolComp; /** - * A navigator which can calculate waypoints to a goal. + * A navigator pathfinder which can calculate waypoints to a goal. * * @since v3001.0 * @group Components */ - navigation(opts: NavigationCompOpt): NavigationComp; + pathfinder(opts: PathfinderCompOpt): PathfinderComp; /** * @group Math */