Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mamayaya1
GitHub Repository: mamayaya1/game
Path: blob/main/projects/HexGL/libs/Editor_files/Node.js
4627 views
1
var pgli = pgli || {};
2
pgli.diagram = pgli.diagram || {};
3
4
pgli.diagram.Node = gamecore.Base.extend('Node',
5
{ // static
6
layersWidth: 20,
7
layersMargin: 20,
8
layersHeight: 16,
9
headerHeight: 40,
10
slotX: 10,
11
slotY: 14,
12
slotRadius: 6
13
},
14
{ // instance
15
module: null,
16
17
key: null,
18
19
shape: null,
20
background: null,
21
name: null,
22
layers: null,
23
slot: null,
24
25
sockets: [],
26
27
width: 150,
28
height: 200,
29
30
init: function(key, module, x, y)
31
{
32
var static = pgli.diagram.Node;
33
34
this.key = key;
35
this.module = module;
36
37
this.shape = new Kinetic.Group({
38
x: x == undefined ? 0 : x,
39
y: y == undefined ? 0 : y,
40
draggable: true
41
});
42
43
var layerCount = (module.layers != undefined ? module.layers.length : 0) + 1;
44
45
this.height = static.headerHeight + layerCount * static.layersHeight;
46
47
this.background = new Kinetic.Rect({
48
x: 0,
49
y: 0,
50
width: this.width,
51
height: this.height,
52
fill: "#222",
53
stroke: "#000",
54
strokeWidth: 0.5,
55
shadow: {
56
color: "black",
57
blur: 6,
58
offset: [0, 0],
59
opacity: 0.5
60
}
61
});
62
63
this.layers = new Kinetic.Shape({
64
drawFunc: function(ctx){
65
ctx.beginPath();
66
for(var i=0, len = this.attrs.count; i < len; ++i)
67
ctx.arc(10, 10+i*static.layersHeight, static.slotRadius, 0, Math.PI*2, true);
68
ctx.closePath();
69
this.fill(ctx);
70
},
71
x: this.width-static.layersWidth,
72
y: static.layersMargin,
73
count: layerCount,
74
fill: "#111"
75
});
76
77
this.slot = new Kinetic.Circle({
78
x: static.slotX,
79
y: static.slotY,
80
radius: static.slotRadius,
81
fill: "#111"
82
});
83
84
this.name = new Kinetic.Text({
85
x: 20,
86
y: 6,
87
text: module.name,
88
fontSize: 13,
89
fontFamily: "Ubuntu Mono",
90
textFill: "#aaa"
91
});
92
93
this.shape.on('mousedown', function(){
94
this.moveToTop();
95
});
96
97
this.shape.add(this.background);
98
this.shape.add(this.name);
99
this.shape.add(this.layers);
100
this.shape.add(this.slot);
101
},
102
103
updateLayers: function()
104
{
105
var layerCount = (module.layers != undefined ? module.layers.length : 0) + 1;
106
this.layers.attrs.count = layerCount;
107
},
108
109
getSlot: function()
110
{
111
var static = pgli.diagram.Node;
112
return [this.shape.getX()+static.slotX,
113
this.shape.getY()+static.slotY];
114
},
115
116
getLayerSlot: function(index)
117
{
118
var static = pgli.diagram.Node;
119
return [this.shape.getX()+this.width-static.layersWidth/2,
120
this.shape.getY()+10+index*static.layersHeight+static.layersMargin];
121
}
122
});
123