Entities now can be removed
This commit is contained in:
56
script.js
56
script.js
@@ -137,30 +137,44 @@ class Vector2 {
|
|||||||
$(document).ready(function($) {
|
$(document).ready(function($) {
|
||||||
var entities = [];
|
var entities = [];
|
||||||
|
|
||||||
var entityId = 0;
|
var entityId = 0;
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.id = entityId++;
|
var entity = this;
|
||||||
|
this.id = entityId++;
|
||||||
this.position = new Vector2();
|
this.position = new Vector2();
|
||||||
this.speed = new Vector2();
|
this.speed = new Vector2();
|
||||||
var elem = this.elem = $('<div>').addClass('point').appendTo('body');
|
this.elem = $('<div>').addClass('point').appendTo('body');
|
||||||
this.row = $('<tr>').appendTo('#table_entities');
|
this.row = $('<tr>').appendTo('#table_entities');
|
||||||
this.columns = {
|
this.columns = {
|
||||||
id: $('<td>').text(this.id).appendTo(this.row),
|
id: $('<td>').text(this.id).appendTo(this.row),
|
||||||
position: $('<td>').appendTo(this.row),
|
position: $('<td>').appendTo(this.row),
|
||||||
speed: $('<td>').appendTo(this.row),
|
speed: $('<td>').appendTo(this.row),
|
||||||
color: $('<td>').appendTo(this.row),
|
color: $('<td>').appendTo(this.row),
|
||||||
actions: $('<td>').appendTo(this.row),
|
actions: $('<td>').appendTo(this.row),
|
||||||
}
|
}
|
||||||
$('<input />')
|
$('<input />')
|
||||||
.attr('type', 'color')
|
.attr('type', 'color')
|
||||||
.change(function(){
|
.change(function(){
|
||||||
console.log($(this).val());
|
entity.elem.css('background-color', $(this).val());
|
||||||
elem.css('background-color', $(this).val());
|
})
|
||||||
})
|
.appendTo(this.columns.color)
|
||||||
.appendTo(this.columns.color)
|
.change();
|
||||||
.change();
|
$('<button>')
|
||||||
|
.addClass('btn btn-xs btn-danger')
|
||||||
|
.text(' Löschen')
|
||||||
|
.prepend($('<i>').addClass('glyphicon glyphicon-trash'))
|
||||||
|
.appendTo(this.columns.actions)
|
||||||
|
.click(function(){
|
||||||
|
entity.elem.remove();
|
||||||
|
entity.row.remove();
|
||||||
|
|
||||||
|
var index = entities.indexOf(entity);
|
||||||
|
if (index > -1) {
|
||||||
|
entities.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -276,8 +290,8 @@ $(document).ready(function($) {
|
|||||||
'left': entity.position.getX(),
|
'left': entity.position.getX(),
|
||||||
'top': entity.position.getY()
|
'top': entity.position.getY()
|
||||||
});
|
});
|
||||||
entity.columns.position.text(Math.round(entity.position.getX()) + ', ' + Math.round(entity.position.getY()));
|
entity.columns.position.text(Math.round(entity.position.getX()) + ', ' + Math.round(entity.position.getY()));
|
||||||
entity.columns.speed.text(Math.round(entity.speed.getX()) + ', ' + Math.round(entity.speed.getY()));
|
entity.columns.speed.text(Math.round(entity.speed.getX()) + ', ' + Math.round(entity.speed.getY()));
|
||||||
});
|
});
|
||||||
}, 20);
|
}, 20);
|
||||||
});
|
});
|
Reference in New Issue
Block a user