Entities now can be removed

This commit is contained in:
Daniel Brunner
2016-11-30 12:09:26 +01:00
parent 4e84c98a1b
commit c1951f8bd5

View File

@@ -141,10 +141,11 @@ $(document).ready(function($) {
class Entity {
constructor() {
var entity = this;
this.id = entityId++;
this.position = 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.columns = {
id: $('<td>').text(this.id).appendTo(this.row),
@@ -156,11 +157,24 @@ $(document).ready(function($) {
$('<input />')
.attr('type', 'color')
.change(function(){
console.log($(this).val());
elem.css('background-color', $(this).val());
entity.elem.css('background-color', $(this).val());
})
.appendTo(this.columns.color)
.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);
}
});
}
};