7 years ago by Joncom
Here's a Weltmeister issue that's been bothering me lately...
Steps to reproduce:
1. Edit a single property of a single entity
2. Save the level
3. Do a
4. Notice how almost all the entities appear to have changed!
(This seems to affect Chrome more-so than some other browsers.)
This makes it nearly impossible to know what actually changed between commits!
Here's a small patch to fix it:
Steps to reproduce:
1. Edit a single property of a single entity
2. Save the level
3. Do a
git diff
to see what changed4. Notice how almost all the entities appear to have changed!
(This seems to affect Chrome more-so than some other browsers.)
This makes it nearly impossible to know what actually changed between commits!
Here's a small patch to fix it:
diff --git a/game/lib/weltmeister/edit-entities.js b/game/lib/weltmeister/edit-entities.js index 80322f92..4e3a5a4c 100644 --- a/game/lib/weltmeister/edit-entities.js +++ b/game/lib/weltmeister/edit-entities.js @@ -58,7 +58,18 @@ wm.EditEntities = ig.Class.extend({ sort: function() { - this.entities.sort( ig.Game.SORT.Z_INDEX ); + this.stableSort(this.entities, ig.Game.SORT.Z_INDEX); + }, + + + // https://stackoverflow.com/a/47714216/1609607 + stableSort: function(arr, compare) { + var original = this.entities.slice(); + arr.sort(function(a, b){ + var result = compare(a, b); + return result === 0 ? original.indexOf(a) - original.indexOf(b) : result; + }); + return arr; },