import { routeConnector, type ConnectorRoutingMode } from "./connectorRouting.ts"; import { hexLine, type AxialCoord, type HexCell } from "./hex.ts"; import type { TopologyNodeOperationalStateLike } from "./nodeStatus.ts"; export interface SignalRoutingOptions { mode: ConnectorRoutingMode; cells: Pick[]; occupants: Array; from: AxialCoord; to: AxialCoord; radius: number; } function sameCoordinate(first: AxialCoord, second: AxialCoord) { return first.q === second.q && first.r === second.r; } export function createSignalRoute({ mode, cells, occupants, from, to, radius, }: SignalRoutingOptions): AxialCoord[] { if (sameCoordinate(from, to)) { return [{ q: from.q, r: from.r }]; } // A straight SVG connector has no intermediate cell geometry. Signals still // need contiguous cells to communicate progression across the world. if (mode === "straight") { return hexLine(from, to); } const blocked = occupants.filter( (coordinate) => !sameCoordinate(coordinate, from) && !sameCoordinate(coordinate, to), ); const route = routeConnector({ mode, cells, from, to, radius, blocked, }); return route.cells.length > 1 ? route.cells : hexLine(from, to); }