Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
2.1 kB · 86 lines
TypeScript
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import type { DockLocation } from "../DockLocation";import type { DropInfo } from "../DropInfo";import { BorderNode } from "./BorderNode";import type { IDraggable } from "./IDraggable";import type { Model } from "./Model";import type { Node } from "./Node";
export class BorderSet { /** @internal */ static fromJson(json: any, model: Model) { const borderSet = new BorderSet(model); borderSet.borders = json.map((borderJson: any) => BorderNode.fromJson(borderJson, model)); for (const border of borderSet.borders) { borderSet.borderMap.set(border.getLocation(), border); } return borderSet; } /** @internal */ private borders: BorderNode[]; /** @internal */ private borderMap: Map<DockLocation, BorderNode>; /** @internal */ private layoutHorizontal: boolean;
/** @internal */ constructor(_model: Model) { this.borders = []; this.borderMap = new Map<DockLocation, BorderNode>(); this.layoutHorizontal = true; }
toJson() { return this.borders.map((borderNode) => borderNode.toJson()); }
/** @internal */ getLayoutHorizontal() { return this.layoutHorizontal; }
/** @internal */ getBorders() { return this.borders; }
/** @internal */ getBorderMap() { return this.borderMap; }
/** @internal */ forEachNode(fn: (node: Node, level: number) => void) { for (const borderNode of this.borders) { fn(borderNode, 0); for (const node of borderNode.getChildren()) { node.forEachNode(fn, 1); } } }
/** @internal */ setPaths() { for (const borderNode of this.borders) { const path = `/border/${borderNode.getLocation().getName()}`; borderNode.setPath(path); let i = 0; for (const node of borderNode.getChildren()) { node.setPath(`${path}/t${i}`); i++; } } }
/** @internal */ findDropTargetNode(dragNode: Node & IDraggable, x: number, y: number): DropInfo | undefined { for (const border of this.borders) { if (border.isShowing()) { const dropInfo = border.canDrop(dragNode, x, y); if (dropInfo !== undefined) { return dropInfo; } } } return undefined; }}