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:
-
x1
Number -
y1
Number -
x2
Number -
y2
Number
Returns:
getOffsetCoordsFromDirection
-
direction
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
];.
- 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:
-
x1
Number -
y1
Number -
x2
Number -
y2
Number -
[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:
-
destination
Object- The object to copy properties to.
-
source
Object multiple- The object to copy properties from.
Returns:
The destination
object.
mergeDefaults
-
defaults
-
settings
Merges settings with default values.
Parameters:
-
defaults
Object- Default values to merge with.
-
settings
Object- 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'
};