Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename navigation() to pathfinder() #430

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
- added `sentry()` component to notify when certain objects are in sight.
(**v3001/4000**)
- added `NavMesh` class for pathfinding on a mesh. (**v3001/4000**)
- added `navigation()` component to calculate a list of waypoints on a graph.
- added `pathfinder()` component to calculate a list of waypoints on a graph.
(**v3001/4000**)
- now collision checks are only done if there's area objects. (**v3001/4000**)

Expand Down
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,16 +18,16 @@ 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.
*/
graph?: Graph;
}

export function navigationMap(
opts: NavigationMapCompOpt,
): NavigationMapComp {
export function pathfinderMap(
opts: PathfinderMapCompOpt,
): PathfinderMapComp {
let graph = opts.graph;
return {
id: "navigatorMap",
Expand All @@ -38,7 +38,7 @@ export function navigationMap(
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,7 +59,7 @@ 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.
*/
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",
require: ["pos"],
navigateTo(
this: GameObj<NavigationComp | PosComp>,
this: GameObj<PathfinderComp | PosComp>,
target: Vec2,
): Vec2[] | undefined {
const graph: Graph | undefined = this.graph;
Expand All @@ -89,7 +89,7 @@ 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")) {
return parent.graph;
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ export type {
LifespanCompOpt,
MaskComp,
NamedComp,
NavigationComp,
NavigationCompOpt,
NavigationMapComp,
NavigationMapCompOpt,
OffScreenComp,
OffScreenCompOpt,
OpacityComp,
OutlineComp,
ParticlesComp,
ParticlesOpt,
PathfinderComp,
PathfinderCompOpt,
PathfinderMapComp,
PathfinderMapCompOpt,
PatrolComp,
PatrolCompOpt,
PolygonComp,
Expand Down
6 changes: 3 additions & 3 deletions src/kaplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ import {
mask,
move,
named,
navigation,
offscreen,
opacity,
outline,
particles,
pathfinder,
patrol,
pointEffector,
platformEffector,
pointEffector,
polygon,
pos,
raycast,
Expand Down Expand Up @@ -1130,7 +1130,7 @@ const kaplay = <
agent,
sentry,
patrol,
navigation,
pathfinder,
fakeMouse,
// group events
on,
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 @@ -42,12 +42,12 @@ import type {
LifespanCompOpt,
MaskComp,
NamedComp,
NavigationComp,
NavigationCompOpt,
OffScreenComp,
OffScreenCompOpt,
OpacityComp,
OutlineComp,
PathfinderComp,
PathfinderCompOpt,
PatrolComp,
PatrolCompOpt,
PlatformEffectorComp,
Expand Down Expand Up @@ -1036,12 +1036,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