Implemented table with entities

This commit is contained in:
Daniel Brunner
2016-11-30 11:52:10 +01:00
parent 11c1c7d389
commit bb96f88823
2 changed files with 254 additions and 238 deletions

View File

@@ -125,7 +125,7 @@
<fieldset> <fieldset>
<legend>Segmente:</legend> <legend>Segmente:</legend>
<button class="btn btn-primary"><i class="glyphicon glyphicon-plus"></i> Hinzuf&uuml;gen</button> <button id="button_add" class="btn btn-primary"><i class="glyphicon glyphicon-plus"></i> Hinzuf&uuml;gen</button>
<table class="table table-striped table-condensed"> <table class="table table-striped table-condensed">
<thead> <thead>
@@ -136,7 +136,7 @@
<th>Aktionen</th> <th>Aktionen</th>
</tr> </tr>
</thead> </thead>
<tbody></tbody> <tbody id="table_entities"></tbody>
</table> </table>
</fieldset> </fieldset>

View File

@@ -137,16 +137,30 @@ class Vector2 {
$(document).ready(function($) { $(document).ready(function($) {
var entities = []; var entities = [];
var entityId = 0;
class Entity { class Entity {
constructor() { constructor() {
this.id = entityId++;
this.position = new Vector2(); this.position = new Vector2();
this.speed = new Vector2(); this.speed = new Vector2();
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),
position: $('<td>').appendTo(this.row),
speed: $('<td>').appendTo(this.row),
actions: $('<td>').appendTo(this.row),
}
} }
}; };
for (var i = 0; i < 8; i++) { $('#button_add').click(function(){
entities.push(new Entity()); entities.push(new Entity());
});
for (var i = 0; i < 8; i++) {
$('#button_add').click();
} }
var mousePosition = new Vector2; var mousePosition = new Vector2;
@@ -253,6 +267,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.speed.text(Math.round(entity.speed.getX()) + ', ' + Math.round(entity.speed.getY()));
}); });
}, 20); }, 20);
}); });