mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-26 14:12:32 -04:00
Preserve sprite layer order information across saving and loading an sb3.
This commit is contained in:
parent
dc612fb4a1
commit
812e7a3772
7 changed files with 133 additions and 7 deletions
src/util
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue