Constructor
new FlexMultiTrafficLight(trafficLights)
Creates a new instance of this class.
Starts off using the first traffic light in the provided trafficLights
.
Tries to check out the provided traffic lights.
Parameters:
Name | Type | Description |
---|---|---|
trafficLights |
Array.<trafficLight.TrafficLight> | Traffic lights composed. |
Extends
Members
green :trafficLight.Light
- Source:
- Overrides:
The green light.
Type:
isAvailable :boolean
- Source:
- Overrides:
If the traffic light is available: enabled and not checked-out.
Type:
- boolean
isCheckedOut :boolean
- Source:
- Overrides:
If the traffic light is checked-out or reserved.
Type:
- boolean
isEnabled :boolean
- Source:
- Overrides:
If there are composed traffic lights and any of them is enabled.
Type:
- boolean
red :trafficLight.Light
- Source:
- Overrides:
The red light.
Type:
yellow :trafficLight.Light
- Source:
- Overrides:
The yellow light.
Type:
Methods
add(trafficLight)
Adds a traffic light to the composite. Tries to exclusively check it out first and because of that won't add any duplicates.
Parameters:
Name | Type | Description |
---|---|---|
trafficLight |
trafficLight.TrafficLight | Traffic light to add. Must not be null. |
checkIn()
- Source:
- Overrides:
Checks-in the traffic light, making it available for checking out again.
checkOut() → {boolean}
- Source:
- Overrides:
Checks-out or reserve the traffic light for exclusive usage, making it unavailable for other users.
Returns:
True if the traffic light was successfully checked out. False if it was already checked out.
- Type
- boolean
last()
Selects the last traffic light to use.
near()
Selects the nearest traffic light to use, remembering the direction of movement (forwards or backwards). Also works with multiple selected traffic lights, moving all to the nearest, following a single direction (so it's possible to wrap around at the last if both the first and last indexes are in use).
next()
Selects the next traffic light to use, going back to the first one if the currently selected one is the last. Also works with multiple selected traffic lights, moving all to the next.
previous()
Selects the previous traffic light to use, going to the last one if the currently selected one is the first. Also works with multiple selected traffic lights, moving all to the previous.
reset()
- Source:
- Overrides:
Resets all active traffic lights.
use(activeIndexes)
Selects which traffic lights to use given their indexes (0-based), only considering enabled traffic lights. Indexes wrap around from the last to the first.
Parameters:
Name | Type | Description |
---|---|---|
activeIndexes |
Array.<number> | Traffic light indexes to use. Must not be empty. |
useAll()
Selects all traffic lights to use simultaneously.
using() → {Array.<number>}
Gets the traffic light indexes that are in use. If there are no traffic lights in use, or no traffic lights are useable, returns an empty array.
Returns:
The traffic light indexes that are in use.
- Type
- Array.<number>
Events
disabled
- Source:
- Overrides:
Traffic light disabled event.
enabled
- Source:
- Overrides:
Traffic light enabled event.
interrupted
Interrupted event. In a FlexMultiTrafficLight
, if an active traffic
light gets disabled, and there are still enabled traffic lights left,
this event is raised. If no more traffic lights are enabled,
then the disabled
event is raised.