2022-11-10 22:26:41 +00:00
|
|
|
class Gate {
|
2022-11-12 09:24:04 +00:00
|
|
|
constructor(x, y, type, image) {
|
2022-11-11 16:36:38 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2022-11-12 09:24:04 +00:00
|
|
|
this.image = image;
|
2022-11-11 16:36:38 +00:00
|
|
|
this.types = new Types(type);
|
|
|
|
this.selected = false;
|
|
|
|
|
2022-11-12 09:24:04 +00:00
|
|
|
this.width = 50;
|
|
|
|
this.height = 50;
|
|
|
|
|
2022-11-11 16:36:38 +00:00
|
|
|
this.inputs = [];
|
|
|
|
this.outputs = [];
|
2022-11-12 09:24:04 +00:00
|
|
|
for (var i = 0; i < this.types.type.inputs; i++) {
|
2022-11-11 16:36:38 +00:00
|
|
|
//TODO calculate postions for ankors based on this.x and this.y
|
|
|
|
this.inputs.push(new Ankor(this.x - 10, this.y));
|
2022-11-10 22:26:41 +00:00
|
|
|
}
|
2022-11-12 09:24:04 +00:00
|
|
|
for (var i = 0; i < this.types.type.outputs; i++) {
|
2022-11-11 16:36:38 +00:00
|
|
|
//TODO calculate postions for ankors based on this.x and this.y
|
|
|
|
this.outputs.push(new Ankor(this.x + 10, this.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw() {
|
2022-11-12 09:24:04 +00:00
|
|
|
//TODO draw ankors add exception for light and switch
|
|
|
|
//draw gate and load image
|
|
|
|
fill(255);
|
|
|
|
image(this.image, this.x, this.y);
|
|
|
|
noFill();
|
|
|
|
noStroke();
|
|
|
|
rect(this.x, this.y, this.width, this.height);
|
|
|
|
|
|
|
|
//draw ankors
|
2022-11-11 16:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
calculate() {
|
|
|
|
//todo calculate outputs based on inputs and function and add exception for light and switch if type.state
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-12 09:24:04 +00:00
|
|
|
onGate(x, y) {
|
|
|
|
if (
|
|
|
|
x > this.x &&
|
|
|
|
x < this.x + this.width &&
|
|
|
|
y > this.y &&
|
|
|
|
y < this.y + this.height
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-11 16:36:38 +00:00
|
|
|
returnOnAnkor(x, y) {
|
2022-11-12 09:24:04 +00:00
|
|
|
//todo add actual onankor that works with renderd circles
|
2022-11-11 16:36:38 +00:00
|
|
|
this.inputs.forEach(ankor => {
|
2022-11-12 09:24:04 +00:00
|
|
|
if (x == ankor.x && y == ankor.y) {
|
2022-11-11 16:36:38 +00:00
|
|
|
return ankor;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.outputs.forEach(ankor => {
|
2022-11-12 09:24:04 +00:00
|
|
|
if (x == ankor.x && y == ankor.y) {
|
2022-11-11 16:36:38 +00:00
|
|
|
return ankor;
|
|
|
|
}
|
|
|
|
});
|
2022-11-12 09:24:04 +00:00
|
|
|
|
2022-11-11 16:36:38 +00:00
|
|
|
return false;
|
2022-11-10 22:26:41 +00:00
|
|
|
}
|
|
|
|
}
|