add heal option to context menu

This commit is contained in:
Stewart Allen 2021-09-06 21:47:27 -04:00
commit 2c78e5e9cc
6 changed files with 97 additions and 12 deletions

View file

@ -388,6 +388,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
filter: (fn) => { WIDGETS = WIDGETS.filter(fn) },
for: forAllWidgets,
load: Widget.loadFromCatalog,
heal: healWidgets,
meshes: meshArray,
opacity: setOpacity,
annotate: (id) => {
@ -853,6 +854,26 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
return out;
}
function healWidgets() {
let widgets = API.widgets.all();
if (widgets.length) {
API.show.alert("Analyzing objects");
} else {
return;
}
let healed = 0;
for (let w of widgets) {
if (w.heal()) {
healed++;
}
}
if (healed) {
API.show.alert(`${healed} Object${healed ? 's':''} healed`);
} else {
API.show.alert('Nothing found to heal');
}
}
function forAllWidgets(f) {
WIDGETS.slice().forEach(function(widget) {
f(widget);