UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 2.53 kB
import*as Common from"../../../core/common/common.js";import*as Platform from"../../../core/platform/platform.js";import{EdgeTypes,EdgeView,generateEdgePortIdsByData}from"./EdgeView.js";import{NodeLabelGenerator,NodeView}from"./NodeView.js";export class GraphView extends Common.ObjectWrapper.ObjectWrapper{contextId;nodes;edges;outboundEdgeMap;inboundEdgeMap;nodeLabelGenerator;paramIdToNodeIdMap;constructor(e){super(),this.contextId=e,this.nodes=new Map,this.edges=new Map,this.outboundEdgeMap=new Platform.MapUtilities.Multimap,this.inboundEdgeMap=new Platform.MapUtilities.Multimap,this.nodeLabelGenerator=new NodeLabelGenerator,this.paramIdToNodeIdMap=new Map}addNode(e){const d=this.nodeLabelGenerator.generateLabel(e.nodeType),o=new NodeView(e,d);this.nodes.set(e.nodeId,o),this.notifyShouldRedraw()}removeNode(e){this.outboundEdgeMap.get(e).forEach((e=>this.removeEdge(e))),this.inboundEdgeMap.get(e).forEach((e=>this.removeEdge(e))),this.nodes.delete(e),this.notifyShouldRedraw()}addParam(e){const d=this.getNodeById(e.nodeId);d?(d.addParamPort(e.paramId,e.paramType),this.paramIdToNodeIdMap.set(e.paramId,e.nodeId),this.notifyShouldRedraw()):console.error("AudioNode should be added before AudioParam")}removeParam(e){this.paramIdToNodeIdMap.delete(e)}addNodeToNodeConnection(e){const d=new EdgeView(e,EdgeTypes.NodeToNode);this.addEdge(d)}removeNodeToNodeConnection(e){if(e.destinationId){const d=generateEdgePortIdsByData(e,EdgeTypes.NodeToNode);if(!d)throw new Error("Unable to generate edge port IDs");const{edgeId:o}=d;this.removeEdge(o)}else this.outboundEdgeMap.get(e.sourceId).forEach((e=>this.removeEdge(e)))}addNodeToParamConnection(e){const d=new EdgeView(e,EdgeTypes.NodeToParam);this.addEdge(d)}removeNodeToParamConnection(e){const d=generateEdgePortIdsByData(e,EdgeTypes.NodeToParam);if(!d)throw new Error("Unable to generate edge port IDs");const{edgeId:o}=d;this.removeEdge(o)}getNodeById(e){return this.nodes.get(e)||null}getNodes(){return this.nodes}getEdges(){return this.edges}getNodeIdByParamId(e){return this.paramIdToNodeIdMap.get(e)||null}addEdge(e){const d=e.sourceId;this.outboundEdgeMap.hasValue(d,e.id)||(this.edges.set(e.id,e),this.outboundEdgeMap.set(d,e.id),this.inboundEdgeMap.set(e.destinationId,e.id),this.notifyShouldRedraw())}removeEdge(e){const d=this.edges.get(e);d&&(this.outboundEdgeMap.delete(d.sourceId,e),this.inboundEdgeMap.delete(d.destinationId,e),this.edges.delete(e),this.notifyShouldRedraw())}notifyShouldRedraw(){this.dispatchEventToListeners("ShouldRedraw",this)}}