Skip to content

Commit

Permalink
entity map layer sorting improved, sort reason debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch committed Mar 23, 2013
1 parent 78eaa2f commit 6aba71a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/scripts/models/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
layerName: '',
// debug
label: null,
sortReason: null,
// character specific
input: null,
climbHeight: 128.0,
Expand Down
27 changes: 23 additions & 4 deletions app/scripts/models/MapElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,30 @@

// -- CHECK IF ENTITY IS IN FRONT --
var mapBounds = this.getSortBounds();
var entityBounds = entity.getSortBounds();

// Entity is above Element
if (entity.z >= mapBounds.top) {
return true;
// Entity is not behind Element
if (entityBounds.front > mapBounds.back) {
if (ec.debug > 0) {
entity.sortReason = 'above '+this.name;
}
return true;
}
return false;
}

var entityBounds = entity.getSortBounds();

// Entity is in front of Element
if (entityBounds.back > mapBounds.front) {
return true;
// Entity is not under Element
if (entityBounds.top > this.z) {
if (ec.debug > 0) {
entity.sortReason = 'before '+this.name;
}
return true;
}
return false;
}

// -- CHECK IF ENTITY IS BEHIND --
Expand Down Expand Up @@ -159,6 +172,9 @@
if (distance > 0) { // Entity is outside Element shape
// Entity is in front of edge
if (direction > 0) {
if (ec.debug > 0) {
entity.sortReason = 'edge '+this.name;
}
return true;
}
} else { // Entity is inside Element shape
Expand All @@ -169,6 +185,9 @@
case 'oval':
// Entity is in front of Element
if ((entityBounds.front + entityBounds.back)/2 > (mapBounds.front + mapBounds.back)/2) {
if (ec.debug > 0) {
entity.sortReason = 'center '+this.name;
}
return true;
}
break;
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/views/Canvas2dEntityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@
var fieldHeight = 48;
entity.label = entity.label || ec.Entity.getLabel(context, fieldHeight);
entity.label.setPos(x-16, y-((o&&o.regY+fieldHeight)||0));
var info = ''+ entity.layerNum +': '+ entity.layerName +' z: '+ entity.z.toFixed(1);
var info = ''+ entity.layerNum +': '+ entity.layerName +', '+ entity.sortReason;
if (entity.mapCollision.length) {
info += '\r' + ec.objectToProps(entity.mapCollision, 'name').join(',');
}
info += '\rz: '+ entity.z.toFixed(1);
if (entity.input) {
var goal = entity.input.goal;
if (goal) {
Expand Down

0 comments on commit 6aba71a

Please sign in to comment.