mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Hoist target list assignment to simplify code.
This commit is contained in:
parent
0ec0ea6ef7
commit
4b64df222a
1 changed files with 4 additions and 4 deletions
|
@ -1041,11 +1041,11 @@ class VirtualMachine extends EventEmitter {
|
|||
* @returns {boolean} Whether a target was reordered.
|
||||
*/
|
||||
reorderTarget (targetIndex, newIndex) {
|
||||
targetIndex = MathUtil.clamp(targetIndex, 0, this.runtime.targets.length - 1);
|
||||
newIndex = MathUtil.clamp(newIndex, 0, this.runtime.targets.length - 1);
|
||||
if (targetIndex === newIndex) return false;
|
||||
const target = this.runtime.targets[targetIndex];
|
||||
let targets = this.runtime.targets;
|
||||
targetIndex = MathUtil.clamp(targetIndex, 0, targets.length - 1);
|
||||
newIndex = MathUtil.clamp(newIndex, 0, targets.length - 1);
|
||||
if (targetIndex === newIndex) return false;
|
||||
const target = targets[targetIndex];
|
||||
targets = targets.slice(0, targetIndex).concat(targets.slice(targetIndex + 1));
|
||||
targets.splice(newIndex, 0, target);
|
||||
this.runtime.targets = targets;
|
||||
|
|
Loading…
Reference in a new issue