Skip to content

Commit

Permalink
refactor: rename navigation() to pathfinder() (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Oct 6, 2024
1 parent 8e9bee1 commit 74a2382
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions examples/ghosthunting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/level/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./agent";
export * from "./navigation";
export * from "./pathfinder";
export * from "./patrol";
export * from "./sentry";
export * from "./tile";
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -18,27 +18,27 @@ 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;
},
set graph(value) {
graph = value;
},
navigate(
this: GameObj<NavigationMapComp>,
this: GameObj<PathfinderMapComp>,
origin: Vec2,
target: Vec2,
navigationOpt: any = {},
Expand All @@ -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.
*/
Expand All @@ -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;
/*
Expand All @@ -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<NavigationComp | PosComp>,
this: GameObj<PathfinderComp | PosComp>,
target: Vec2,
): Vec2[] | undefined {
const graph: Graph | undefined = this.graph;
Expand All @@ -89,9 +89,9 @@ export function navigation(
return graph;
}
let parent: GameObj<any> | null =
(this as unknown as GameObj<NavigationComp>).parent;
(this as unknown as GameObj<PathfinderComp>).parent;
while (parent) {
if (parent.is("navigatormap")) {
if (parent.is("pathfinderMap")) {
return parent.graph;
}
parent = parent.parent;
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/kaplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ import {
mask,
move,
named,
navigation,
offscreen,
opacity,
outline,
particles,
pathfinder,
patrol,
pointEffector,
polygon,
Expand Down Expand Up @@ -1123,7 +1123,7 @@ const kaplay = <
agent,
sentry,
patrol,
navigation,
pathfinder,
// group events
on,
onFixedUpdate,
Expand Down
2 changes: 1 addition & 1 deletion src/math/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BinaryHeap } from "../utils/";
import { BinaryHeap } from "../utils";
import { Vec2 } from "./math";

export interface Graph {
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import type {
LifespanCompOpt,
MaskComp,
NamedComp,
NavigationComp,
NavigationCompOpt,
OffScreenComp,
OffScreenCompOpt,
OpacityComp,
OutlineComp,
PathfinderComp,
PathfinderCompOpt,
PatrolComp,
PatrolCompOpt,
PointEffectorComp,
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 74a2382

Please sign in to comment.