added object-naming extension primitive

snap7
jmoenig 2021-06-16 23:22:59 +02:00
rodzic 1f22de2511
commit dd83287b85
2 zmienionych plików z 26 dodań i 1 usunięć

Wyświetl plik

@ -11,6 +11,7 @@
* threads: added exception handling primitives for try/catch
* extensions: added try-catch extension primitives
* updated try-catch library
* extensions: added object-naming extension primitive
### 2021-06-15
* extensions: tweaked world-map primitives

Wyświetl plik

@ -28,7 +28,8 @@
// Global settings /////////////////////////////////////////////////////
/*global modules, List, StageMorph, Costume, SpeechSynthesisUtterance, Sound,
IDE_Morph, CamSnapshotDialogMorph, SoundRecorderDialogMorph*/
IDE_Morph, CamSnapshotDialogMorph, SoundRecorderDialogMorph, SpriteMorph,
isSnapObject*/
modules.extensions = '2021-June-16';
@ -421,3 +422,26 @@ SnapExtensions.set(
return result;
}
);
// Object properties (obj_)
SnapExtensions.set(
'obj_name(obj, name)',
function (obj, name, proc) {
var ide = this.parentThatIsA(IDE_Morph);
proc.assertType(obj, [SpriteMorph, StageMorph, Costume, Sound]);
if (isSnapObject(obj)) {
obj.setName(ide.newSpriteName(name, obj));
ide.recordUnsavedChanges();
} else if (obj instanceof Costume) {
obj.name = this.newCostumeName(name, obj);
obj.version = Date.now();
ide.hasChangedMedia = true;
ide.recordUnsavedChanges();
} else if (obj instanceof Sound) {
obj.name = ide.newSoundName(name);
ide.hasChangedMedia = true;
ide.recordUnsavedChanges();
}
}
);