https://github.com/konradlinkowski/grafjs
2D graph for chunk-based games
https://github.com/konradlinkowski/grafjs
2d board chunk chunks game games graph map nodes
Last synced: 7 months ago
JSON representation
2D graph for chunk-based games
- Host: GitHub
- URL: https://github.com/konradlinkowski/grafjs
- Owner: KonradLinkowski
- License: isc
- Created: 2018-07-04T21:59:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-10T17:47:00.000Z (about 7 years ago)
- Last Synced: 2025-03-01T00:07:56.783Z (7 months ago)
- Topics: 2d, board, chunk, chunks, game, games, graph, map, nodes
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/grafjs
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GrafJS
[](https://npmjs.org/package/grafjs)
[](https://travis-ci.org/KonradLinkowski/GrafJS)
[](https://david-dm.org/KonradLinkowski/GrafJS)
[](https://david-dm.org/KonradLinkowski/GrafJS#info=devDependencies)
[](https://snyk.io/test/github/KonradLinkowski/GrafJS?targetFile=package.json)
[](https://codeclimate.com/github/KonradLinkowski/GrafJS/maintainability)
## Features
2D graph for chunk-based games.
- No dependencies
- Easy to use
- Lightweight
## Installing
```bash
$ npm install grafjs
```
## Example
Import
```js
const Graf = require('grafjs')
```
Creating a board where each chunk is 20 x 20.
```js
// creates 20 x 20 grid filled with 0's
const grid = new Array(20).fill(null).map(a => new Array(20).fill(0))
// creates the board with a default value for each chunk
const board = new Graf(grid)
// adds examplary chunk
board.addChunk(0, 0)
```
Getting specified chunk and adjacent chunks.
```js
// returns chunk at position (1, 3)
const chunk = board.getChunk(1, 3)
const left = chunk.getLeft()
const right = chunk.getRight()
const up = chunk.getUp()
const down = chunk.getDown()
```
Getting and setting chunk's content.
```js
// gets value
const content = chunk.getValue()
// sets value
chunk.setValue([1])
```
Removing a chunk
```js
// removes the chunk at (3, 4)
board.removeChunk(3, 4)
```