Path: blob/main/projects/HexGL/libs/Editor_files/Node.js
4627 views
var pgli = pgli || {};1pgli.diagram = pgli.diagram || {};23pgli.diagram.Node = gamecore.Base.extend('Node',4{ // static5layersWidth: 20,6layersMargin: 20,7layersHeight: 16,8headerHeight: 40,9slotX: 10,10slotY: 14,11slotRadius: 612},13{ // instance14module: null,1516key: null,1718shape: null,19background: null,20name: null,21layers: null,22slot: null,2324sockets: [],2526width: 150,27height: 200,2829init: function(key, module, x, y)30{31var static = pgli.diagram.Node;3233this.key = key;34this.module = module;3536this.shape = new Kinetic.Group({37x: x == undefined ? 0 : x,38y: y == undefined ? 0 : y,39draggable: true40});4142var layerCount = (module.layers != undefined ? module.layers.length : 0) + 1;4344this.height = static.headerHeight + layerCount * static.layersHeight;4546this.background = new Kinetic.Rect({47x: 0,48y: 0,49width: this.width,50height: this.height,51fill: "#222",52stroke: "#000",53strokeWidth: 0.5,54shadow: {55color: "black",56blur: 6,57offset: [0, 0],58opacity: 0.559}60});6162this.layers = new Kinetic.Shape({63drawFunc: function(ctx){64ctx.beginPath();65for(var i=0, len = this.attrs.count; i < len; ++i)66ctx.arc(10, 10+i*static.layersHeight, static.slotRadius, 0, Math.PI*2, true);67ctx.closePath();68this.fill(ctx);69},70x: this.width-static.layersWidth,71y: static.layersMargin,72count: layerCount,73fill: "#111"74});7576this.slot = new Kinetic.Circle({77x: static.slotX,78y: static.slotY,79radius: static.slotRadius,80fill: "#111"81});8283this.name = new Kinetic.Text({84x: 20,85y: 6,86text: module.name,87fontSize: 13,88fontFamily: "Ubuntu Mono",89textFill: "#aaa"90});9192this.shape.on('mousedown', function(){93this.moveToTop();94});9596this.shape.add(this.background);97this.shape.add(this.name);98this.shape.add(this.layers);99this.shape.add(this.slot);100},101102updateLayers: function()103{104var layerCount = (module.layers != undefined ? module.layers.length : 0) + 1;105this.layers.attrs.count = layerCount;106},107108getSlot: function()109{110var static = pgli.diagram.Node;111return [this.shape.getX()+static.slotX,112this.shape.getY()+static.slotY];113},114115getLayerSlot: function(index)116{117var static = pgli.diagram.Node;118return [this.shape.getX()+this.width-static.layersWidth/2,119this.shape.getY()+10+index*static.layersHeight+static.layersMargin];120}121});122123