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 { class Entity {
constructor() { constructor() {
var entity = this;
this.id = entityId++; 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),
@@ -156,11 +157,24 @@ $(document).ready(function($) {
$('<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);
}
});
} }
}; };