1.2.0 • Published 7 years ago

netwalk-core v1.2.0

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
7 years ago

netwalk-core

Netwalk game (aka pipes, network) core.

Installation

npm i -S netwalk-core

Usage

ES6 import

import * as netwalkCore from 'netwalk-core';
const { Netwalk } = netwalkCore;

const params = {};
const instance = new Netwalk(params);

Script tag in HTML

<script src="netwalk-core.min.js"></script>

then in js

const { Netwalk } = window.netwalkCore

const params = {}
const instance = new Netwalk(params)

By default, instance create matrix, then fill and randomize it.

You can change this behavior by passing params object with fill and randomize boolean fields.

API

Netwalk class

Init params

const params = {
    template,
    rows,
    columns,
    matrix,

    fill,
    fillAnimationDelay,

    randomize,
    randomizeAnimationDelay,


    matrixChangeCallback,
    
    stopwatchChangeCallback,
    movesChangeCallback,
    
    startedChangeCallback,
    finishedChangeCallback,
    
    readyChangeCallback,
    
    matrixRandomizedChangeCallback,
    matrixFilledChangeCallback,
    matrixFillingChangeCallback,
    matrixRandomizingChangeCallback,
}
template (Two dimensional array)
  • 0 is empty cell
  • 1 is consumer or simple cell
  • 'provider' is initial provider cell

The template must be resolvable, otherwise an error will be thrown.

Template examples:

const P = 'provider'

const goodTemplate1 = [
     [1, 1, 1, 1, 1],
     [1, 1, 1, 1, 1],
     [1, 1, 1, 1, 1],
     [1, 1, 1, 1, 1]
 ]
     
const goodTemplate2 = [
     [1, 1, 1, 1, 0],
     [1, 1, P, 1, 0],
     [1, 1, 1, 1, 0],
     [1, 1, 1, 1, 0]
 ]

const badTemplate = [
   [1, 1, 1, 1, 0],
   [1, 1, 1, 1, 0],
   [1, 1, 1, 0, 0],
   [1, 1, 1, 0, 1] // error in last cell 
]
rows (number)
columns (number)
matrix (Matrix with Cells)

if you already have a Matrix instance.

fill (boolean)

Default = true

randomize (boolean)

Default = true

fillAnimationDelay (number)

Delay (in ms) before filling every cell.

Default = 0

randomizeAnimationDelay (number)

Delay (in ms) before randomizing every cell.

Default = 0

Callbacks
  • matrixChangeCallback
  • stopwatchChangeCallback
  • movesChangeCallback
  • startedChangeCallback
  • finishedChangeCallback,
  • readyChangeCallback
  • matrixFillingChangeCallback
  • matrixFilledChangeCallback
  • matrixRandomizingChangeCallback
  • matrixRandomizedChangeCallback

Every callback will be called with the changed value (except matrixChangeCallback).

Instance methods

fillMatrix ()

return Promise

Creates provider (if it doesn't exist), consumers and nodes.

randomizeMatrix ()

return Promise

Randomly changes rotate position of the node.

destroy ()

Stop stopwatch and another internal processes.

rotateNode (id)

Matrix consist of Cell class objects with IDs.

Example:

instance.rotate(Cell.id)

Instance props

  • matrix
  • started
  • finished
  • ready
  • moves
  • stopwatch

Auxiliary constants

import {directions, oppositeConnections, nextConnections, connectionTypes} from 'netwalk-core' 

Can help you in building a view.

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago