Skip to content

five-on-it / packages/world/src/signals

packages/world/src/signals ​

Junctions and traffic signals: where the roads of the road graph meet (a node with three or more neighbours: a T, a crossing, a roundabout's entry), how far each one's box reaches, and the traffic lights that rule some of them. A junction is signalled when a traffic light piece of the level (a placement of a traffic-light mesh, such as the downtown kit's) stands within SIGNAL_REACH of it, nearer to it than to any other junction. Its approaches (the lanes coming in) fall into two groups by their direction (those along the first approach's axis, and the others), and the groups take turns: green, amber, then red for both while the box clears, then the other group's green. The plan is fixed and a pure function of the level and the tick (signalColour), each junction shifted by its own offset, so the server's drivers and every client's lamps agree without a byte on the wire. Each light shows its junction's colour for the approach whose lane passes under its signal head (the arm's head, found from the mesh: signalHead). A mission (a phone app's button, a terminal) may switch a junction by hand for a while (GAME_DESIGN §5.5): green for one group and red for the other, red for both, or flashing amber (nobody's light: the drivers give way as at a junction without one); the SignalOverride sits on the junction, the plan reads it, and the server sends it to the clients once, not the lamps. Isomorphic: no DOM, no Node.

Interfaces ​

Type Aliases ​

Variables ​

Functions ​