Preserve sprite layer order information across saving and loading an sb3.

This commit is contained in:
Karishma Chadha 2018-07-24 11:00:48 -04:00
parent dc612fb4a1
commit 812e7a3772
7 changed files with 133 additions and 7 deletions
src/util

View file

@ -63,6 +63,20 @@ class MathUtil {
return parseFloat(Math.tan((Math.PI * angle) / 180).toFixed(10));
}
}
/**
* Given an array of unique numbers,
* returns a reduced array such that each element of the reduced array
* represents the position of that element in a sorted version of the
* original array.
* E.g. [5, 19. 13, 1] => [1, 3, 2, 0]
* @param {Array<number>} elts The elements to sort and reduce
* @return {Array<number>} The array of reduced orderings
*/
static reducedSortOrdering (elts) {
const sorted = elts.slice(0).sort((a, b) => a - b);
return elts.map(e => sorted.indexOf(e));
}
}
module.exports = MathUtil;