UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

71 lines (60 loc) 1.46 kB
import List from "../../../collection/list/List.js"; import Rectangle from "../../../geom/2d/Rectangle.js"; import { PortVisualData } from "./PortVisualData.js"; export class NodeVisualData { constructor() { /** * * @type {number} */ this.id = 0; /** * * @type {Rectangle} */ this.dimensions = new Rectangle(); /** * * @type {List<PortVisualData>} */ this.ports = new List(); } /** * * @param {number} id * @returns {PortVisualData|undefined} */ getPort(id) { return this.ports.find(port => port.id === id); } /** * * @param {NodeVisualData} other */ copy(other) { this.id = other.id; this.dimensions.copy(other.dimensions); this.ports.deepCopy(other.ports, PortVisualData); } /** * * @returns {NodeVisualData} */ clone() { const r = new NodeVisualData(); r.copy(this); return r; } toJSON() { return { id: this.id, dimensions: this.dimensions.toJSON(), ports: this.ports.toJSON() }; } fromJSON(json) { this.id = json.id; this.dimensions.fromJSON(json.dimensions); this.ports.fromJSON(json, PortVisualData); } }