Class: MenuVectorField

menulib~MenuVectorField(selectables, initialPos)

Not actually a vector field (https://en.wikipedia.org/wiki/Vector_field), but a sloppy interpretation of one. Basically, given a 2D grid of positions, a present position, and a given direction, where will you go based on the direction?

Constructor

Parameters:
Name Type Description
selectables Array:.<Selectable:>
initialPos number
Source:

Members

(private) currPos :number

The current selectable we're at.
Type:
  • number
Source:

currPos

Source:

(private) selectables :Array:.<Selectable:>

List of selectables associated with this MenuVectorField.
Type:
  • Array:.<Selectable:>
Source:

Methods

getFromDir(direction) → {number}

Given our current selector (module:menulib~MenuVectorField#currPos), pick another close-by selector in the given direction.
Parameters:
Name Type Description
direction MenuVector A unit vector.
Source:
Returns:
Type
number

raycastEstimate(from, direction, threshold) → {number}

Like a raycast, except this also accounts for rays that are CLOSE enough for the MenuVector field to qualify as "good enough". So that means that this raycast returns some kind of Selectable, provided that Selectable is either: Hit by the ray (the ray at some point is within its rectangle). This will return the selectable that has the closest distance to where the raycast "hits", provided the distance is within the "threshold". We prioritize elements that are closer to the current element, since this is meant to be used for navigation.
Parameters:
Name Type Default Description
from MenuVector
direction MenuVector
threshold number 100 The maximum distance a given Selectable from `from` can have to be selected.
Source:
Returns:
Index of closest selectable from raycast.
Type
number