@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
70 lines (58 loc) • 1.36 kB
JavaScript
import List from "../../../collection/list/List.js";
import Rectangle from "../../../geom/2d/Rectangle.js";
import { PortVisualData } from "./PortVisualData.js";
export class NodeVisualData {
/**
*
* @type {number}
*/
id = 0;
/**
*
* @type {Rectangle}
*/
dimensions = new Rectangle();
/**
*
* @type {List<PortVisualData>}
*/
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);
}
}