2022-11-13 00:15:17 +00:00
|
|
|
/// <reference path="../../udbscript.d.ts" />
|
|
|
|
|
2022-01-06 17:46:37 +00:00
|
|
|
`#version 4`;
|
|
|
|
|
2021-11-28 13:00:24 +00:00
|
|
|
`#name Randomize Selection Order`;
|
|
|
|
|
|
|
|
`#description Randomize the selection order of the selected map elements.`;
|
|
|
|
|
|
|
|
// Put all selected map elements into an array
|
|
|
|
let elements = [
|
2022-01-06 17:46:37 +00:00
|
|
|
...UDB.Map.getSelectedThings(),
|
|
|
|
...UDB.Map.getSelectedVertices(),
|
|
|
|
...UDB.Map.getSelectedLinedefs(),
|
|
|
|
...UDB.Map.getSelectedSectors()
|
2021-11-28 13:00:24 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Clear current selection
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.Map.clearAllSelected();
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
// Keep going as long as there are elements in the array
|
|
|
|
while(elements.length > 0)
|
|
|
|
{
|
|
|
|
// Randomly choose one element
|
|
|
|
let index = Math.floor(Math.random() * elements.length);
|
|
|
|
|
|
|
|
// Select it!
|
|
|
|
elements[index].selected = true;
|
|
|
|
|
|
|
|
// Remove it from the array
|
|
|
|
elements.splice(index, 1);
|
|
|
|
}
|