-
Notifications
You must be signed in to change notification settings - Fork 1
/
editGate.js
124 lines (97 loc) · 2.46 KB
/
editGate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//////////////////////////////////////////////////////////////////////
// editGate //
//////////////////////////////////////////////////////////////////////
function editGate() {
this.name = 'edit gate'
var panel, gate, img, sceneSelect, buffer, frameContainer;
this.setup = function(){
buffer = 10 // user can click 10px outside the canvas
panel = createDiv()
.parent(toolPanelsContainer)
.hide();
createButton('reset polygon')
.mousePressed(resetPoly)
.parent(panel);
createButton('remove gate')
.mousePressed(removeGate)
.parent(panel)
createElement('hr')
.parent(panel);
createSpan('target scene:')
.parent(panel);
sceneSelect = createSelect()
.changed(sceneSelectChanged)
.parent(panel);
createElement('hr')
.parent(panel);
createButton('ok')
.mousePressed(next)
.parent(panel);
}
this.exit = function(){
panel.hide();
};
this.enter = function(){
panel.show();
img = loadImage(game.scenes[sceneIndex].imageData);
gate = game.scenes[sceneIndex].gates[gateIndex];
resetSceneSelect(sceneSelect, gate.sceneId);
};
this.draw = function(){
background(0);
cursor('crosshair');
if(img){
imageMode(CORNER)
image(img, 0, 0, width, height);
}
stroke(0,0,0)
fill(127,127,127,150)
strokeWeight(4)
beginShape();
for(let i = 0; i < gate.poly.length ; i+=2){
vertex(gate.poly[i], gate.poly[i+1]);
}
endShape(CLOSE);
stroke(0,0,0)
fill(255,255,255)
strokeWeight(1)
strokeJoin(BEVEL);
for(let i = 0; i < gate.poly.length ; i+=2){
ellipse(gate.poly[i], gate.poly[i+1],7,7);
}
stroke(255,255)
noFill();
strokeWeight(2)
beginShape();
for(let i = 0; i < gate.poly.length ; i+=2){
vertex(gate.poly[i], gate.poly[i+1]);
}
endShape(CLOSE);
};
this.mousePressed = function(){
if(mouseX+buffer > 0 && mouseY+buffer > 0 && mouseX-buffer < width && mouseY-buffer < height){
addPoint(constrain(mouseX,0,width), constrain(mouseY,0,height));
}
}
function removeGate(){
game.scenes[sceneIndex].gates.splice(gateIndex, 1);
mgr.showScene(editScene)
}
function sceneSelectChanged(){
let sceneId = int(sceneSelect.value());
if(sceneId == game.scenes.length){
newScene();
}
gate.sceneId = sceneId;
resetSceneSelect(sceneSelect, sceneId);
}
function resetPoly(){
gate.poly = [];
}
function addPoint(x, y){
gate.poly.push(x, y);
}
function next(){
mgr.showScene(editScene);
}
}