API Docs for:
Show:

Util Class

Defined in: src/util.js:44

Utility functions.

Methods

getDistance

(
  • x1
  • y1
  • x2
  • y2
)
Number

Defined in src/util.js:201

Gets the distance from point 1 to point 2.

Parameters:

  • x1 Number
  • y1 Number
  • x2 Number
  • y2 Number

Returns:

Number:

getOffsetCoordsFromDirection

(
  • direction
)
Object static

Defined in src/util.js:169

Gets the offset coords of a given direction.

Parameters:

  • direction String
    • valid directions: [up, down, left, right, up_left, up_right, down_left, down_right];.

Returns:

Object:

{x: 0, y: 0}

getTileMoveDistance

(
  • x1
  • y1
  • x2
  • y2
  • [diagonalMovement=false]
)
Number

Defined in src/util.js:183

Gets the distance in tile moves from point 1 to point 2.

Parameters:

  • x1 Number
  • y1 Number
  • x2 Number
  • y2 Number
  • [diagonalMovement=false] Bool optional

    true, calculate the distance taking into account diagonal movement.

Returns:

Number:

merge

(
  • destination
  • source
)
Object static

Defined in src/util.js:149

Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.

Parameters:

  • destination Object
    • The object to copy properties to.
  • source Object multiple
    • The object to copy properties from.

Returns:

Object:

The destination object.

mergeDefaults

(
  • defaults
  • settings
)
Object static

Defined in src/util.js:129

Merges settings with default values.

Parameters:

  • defaults Object
    • Default values to merge with.
  • settings Object
    • Settings to merge with default values.

Returns:

Object:

A new object with settings replacing defaults.

Properties

DIRECTIONS_4

Array final static

Defined in src/util.js:51

List of 4 directions as strings. Used to match property keys of Util.DIRECTIONS_TO_OFFSETS.

Example:

[
    'up',
    'right',
    'down',
    'left',
]

DIRECTIONS_8

Array final static

Defined in src/util.js:68

List of 8 directions as strings. Used to match property keys of Util.DIRECTIONS_TO_OFFSETS.

Example:

[
    'up',
    'up_right',
    'right',
    'down_right',
    'down',
    'down_left',
    'left',
    'up_left',
]

DIRECTIONS_OPPOSITES

Object final static

Defined in src/util.js:89

Maps direction names their opposite direction name.

Example:

{
   up:           {x:  0, y: -1},
   up_right:     {x:  1, y: -1},
   right:        {x:  1, y:  0},
   down_right:   {x:  1, y:  1},
   down:         {x:  0, y:  1},
   down_left:    {x: -1, y:  1},
   left:         {x: -1, y:  0},
   up_left:      {x: -1, y: -1}
}

DIRECTIONS_TO_OFFSETS

Object final static

Defined in src/util.js:109

Maps direction names to coord offsets.

Example:

{
    'up': 'down',
    'down': 'up',
    'left': 'right',
    'right': 'left',
    'up_right': 'down_left',
    'down_left': 'up_right',
    'up_left': 'down_right',
    'down_right': 'up_left'
};