TrainsAndRoads/interface/types/ExternalNode.ts

25 lines
664 B
TypeScript

import { Direction } from "../constants/Direction";
import { Border } from "./Border";
import { Cell } from "./Cell";
import { Exit } from "./Exit";
import { Node } from "./Node";
export class ExternalNode extends Node {
public readonly direction: Direction;
private border?: Border;
constructor(cell: Cell, direction: Direction) {
super(cell);
this.direction = direction;
}
public linkToNode(other: ExternalNode | Exit) {
this.border = new Border(this, other);
}
public traverseBorder(): ExternalNode | Exit {
if (!this.border) throw Error(`Missing border for node`);
return (this.border as Border).traverseFrom(this);
}
}