Util Class
Utility functions.
Item Index
Methods
- getDistance
- getOffsetCoordsFromDirection static
- getTileMoveDistance
- merge static
- mergeDefaults static
Properties
- DIRECTIONS_4 static
- DIRECTIONS_8 static
- DIRECTIONS_OPPOSITES static
- DIRECTIONS_TO_OFFSETS static
Methods
getDistance
-
x1 -
y1 -
x2 -
y2
Gets the distance from point 1 to point 2.
Parameters:
-
x1Number -
y1Number -
x2Number -
y2Number
Returns:
getOffsetCoordsFromDirection
-
direction
Gets the offset coords of a given direction.
Parameters:
-
directionString- valid directions: [
up,down,left,right,up_left,up_right,down_left,down_right];.
- valid directions: [
Returns:
{x: 0, y: 0}
getTileMoveDistance
-
x1 -
y1 -
x2 -
y2 -
[diagonalMovement=false]
Gets the distance in tile moves from point 1 to point 2.
Parameters:
-
x1Number -
y1Number -
x2Number -
y2Number -
[diagonalMovement=false]Bool optionaltrue, calculate the distance taking into account diagonal movement.
Returns:
merge
-
destination -
source
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:
-
destinationObject- The object to copy properties to.
-
sourceObject multiple- The object to copy properties from.
Returns:
The destination object.
mergeDefaults
-
defaults -
settings
Merges settings with default values.
Parameters:
-
defaultsObject- Default values to merge with.
-
settingsObject- Settings to merge with default values.
Returns:
A new object with settings replacing defaults.
Properties
DIRECTIONS_4
Array
final
static
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
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
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
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'
};
