Skip to content

Commit

Permalink
tidy: update README & docs & clean up comments and straggly code
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleactii committed Apr 11, 2024
1 parent 5c9883c commit f8a09bd
Show file tree
Hide file tree
Showing 7 changed files with 18,238 additions and 18,232 deletions.
97 changes: 55 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,72 @@
# Pathway
A module that will enable pathfinding functionality in the Vylocity Game Engine
# Pathway Module

The Pathway module smoothly integrates pathfinding into the Vylocity Game Engine, allowing map instances to navigate environments more efficiently.

Uses [easystar](https://github.com/prettymuchbryce/easystarjs) under the hood.

## Installation

### ES Module

# ES Module
```js
// Importing as an ES module
import { Pathway } from './pathway.mjs';
```

# IIFE (Immediately Invoked Function Expression)
```js
<!-- Including the IIFE bundle in an HTML file -->
<script src="pathway.js"></script>
### IIFE (Immediately Invoked Function Expression)

```js
<script src="pathway.js"></script>;
// ...
window.PathwayBundle.Pathway
window.PathwayBundle.Pathway;
```

# CommonJS (CJS) Module
### CommonJS (CJS) Module

```js
// Importing as a CommonJS module (Node.js)
const { Pathway } = require('./pathway.cjs.js');
```

## API

### instance.pathwayWeight
- `type`: `number`
- `desc`: The weight of this instance in the pathfinder system, higher values will try to make the pathfinder generate paths that do not include this instance. A weight of `0` is converying that is is passable. A weight of `-1` means it is impassable. Weights are optional!

### Pathway.to(pInstance, pDestination, pOptions)
- `pInstance`: The instance to move. `object`
- `pDestination.x`: The xCoordinate to move to `integer`
- `pDestination.y`: The yCoordinate to move to `integer`
- `pOptions.diagonal`: Whether or not the pathfinder allows diagonal moves `boolean`
- `pOptions.mode`: How this instance will move. `collision` for moving with collisions in mind (movePos). `position` for moving with no collisions in mind (setPos). `string`
- `pOptions.pixelsPerSecond`: The speed in pixels this instance moves per second. This setting only works when `pOptions.mode` is set to `position`.`number`
- `pOptions.exclude`: An array of diobs that will be excluded when calculating the path `array`
- `pOptions.minDistance`: The minimum distance this pathway system will use to calculate if you have reached the (next) node. `number`
- `pOptions.maxStuckCounter`: The maximum amount of ticks of pInstance being in the same position as the last tick before its considered stuck. `number`
- `pOptions.onPathComplete`: Callback for when pInstance makes it to the `function`
- `pOptions.onPathFound`: Callback for when pInstance finds a path. The first parameter is the path that was generated. `function`
- `pOptions.onPathStuck`: Callback for when pInstance gets stuck on a path. `function`
- `pOptions.onPathNotFound`: Callback for when no path is found. `function`
- `desc`: Moves `pInstance` to the provided coordinates by walking along a generated path free of obstacles.

### Pathway.end(pInstance)
- `pInstance`: The instance to end the pathfinding on.
- `desc`: Cancels the current path if there is one and stops this instance from moving

### Pathway.setTileSize(pTileSize)
- `pTileSize`: The size of the tileset. `number` | `object` `pTileSize.width` and `pTileSize.height` when using an object.
- `desc`: Sets the tile size internally for this pathway system to reference. This is how pathway will determine node positions.

This module expects the `VYLO` variable to be exposed globally.
## API

### MapInstance Properties

#### `pathwayWeight`

- **Type**: `number`
- **Description**: Represents the importance of an element in pathfinding. Higher values indicate that paths should avoid this element. A weight of `0` means it's easy to traverse, while `-1` indicates an impassable obstacle. This property is optional.

### Methods

#### `Pathway.to(pInstance, pDestination, pOptions)`

- **Parameters**:
- `pInstance`: The moving element.
- `pDestination.x`: The destination's x-coordinate.
- `pDestination.y`: The destination's y-coordinate.
- `pOptions.diagonal`: Whether diagonal movement is allowed.
- `pOptions.mode`: Movement style (`collision` considers obstacles, `position` ignores obstacles).
- `pOptions.pixelsPerSecond`: Speed of movement in pixels per second (applies only in `position` mode).
- `pOptions.exclude`: An array of obstacles to avoid when planning the path.
- `pOptions.minDistance`: Minimum distance to determine node proximity.
- `pOptions.maxStuckCounter`: Maximum consecutive ticks without movement before considering the instance stuck.
- `pOptions.onPathComplete`: Callback executed when the element reaches its destination.
- `pOptions.onPathFound`: Callback executed when a viable path is found.
- `pOptions.onPathStuck`: Callback executed when an element gets stuck on its path.
- `pOptions.onPathNotFound`: Callback executed when no path is found.
- **Description**: Guides an element to a destination along a clear path, avoiding obstacles as necessary.

#### `Pathway.end(pInstance)`

- **Parameters**:
- `pInstance`: The element to stop pathfinding for.
- **Description**: Halts the current path and stops the element's movement.

#### `Pathway.setTileSize(pTileSize)`

- **Parameters**:
- `pTileSize`: The dimensions of the tileset.
- **Description**: Sets the size of tiles for the pathway system to reference.

### Global Dependency

Pathway relies on the `VYLO` variable being globally accessible.
Loading

0 comments on commit f8a09bd

Please sign in to comment.