2018-06-22 16:09:43 +02:00
|
|
|
console.log("bulb");
|
|
|
|
function light(id){
|
|
|
|
this.id = id;
|
|
|
|
var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
|
|
$(g).attr({
|
|
|
|
width: "100%",
|
|
|
|
height: "100%"
|
|
|
|
});
|
|
|
|
var el = $(document.createElementNS('http://www.w3.org/2000/svg', 'circle')).attr({
|
|
|
|
cx: "50",
|
|
|
|
cy:"50",
|
|
|
|
r: "40",
|
|
|
|
id: this.id,
|
|
|
|
fill:"white",
|
|
|
|
stroke: "black"
|
|
|
|
});
|
|
|
|
$(el).attr("stroke-width","2");
|
|
|
|
$(el).attr("class","light");
|
|
|
|
$(g).append(el);
|
|
|
|
//$(el).attr("onmousedown","selected='"+this.id+"';");
|
|
|
|
$(el).attr("onmouseup","selected='yay';");
|
|
|
|
var elem = document.getElementById("svg1");
|
|
|
|
elem.appendChild(g);
|
|
|
|
this.rep = el;
|
|
|
|
|
|
|
|
this.i = new pin(0);
|
|
|
|
this.val = false;
|
|
|
|
//addevt(this);
|
|
|
|
$((this.rep)).attr("stroke-width",4);
|
|
|
|
|
|
|
|
this.activation = function(){
|
|
|
|
return this.i.val;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.x = function(){
|
|
|
|
let name = "#" + this.id;
|
|
|
|
return parseFloat($(name).attr("cx"));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.y = function(){
|
|
|
|
let name = "#" + this.id;
|
|
|
|
//console.log("y"+parseFloat($(name).attr("y")));
|
|
|
|
return parseFloat($(name).attr("cy"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//design
|
|
|
|
this.init = function(){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.update = function(){
|
|
|
|
if (this.i.val != "yay"){
|
|
|
|
if ((this.activation())){
|
|
|
|
$((this.rep)).attr("fill","yellow");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$((this.rep)).attr("fill","white");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//console.log($((this.rep)).attr("fill"));
|
|
|
|
let x = this.x();
|
|
|
|
let y = this.y();
|
|
|
|
this.i.set(x-60,y-10);
|
|
|
|
}
|
|
|
|
pieces[pieces.length] = this;
|
|
|
|
|
|
|
|
addclk_light(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addclk_light(ob){
|
|
|
|
var rep = ob.rep;
|
2018-06-25 11:00:37 +02:00
|
|
|
$(ob.rep).on("mousedown touchstart",function(e){
|
|
|
|
e.preventDefault();
|
2018-06-22 16:09:43 +02:00
|
|
|
var svg = document.getElementById("svg1");
|
|
|
|
$(svg).append(ob.rep);
|
|
|
|
$(svg).append($(ob.i.rep));
|
|
|
|
selected=ob.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|