tweaked programmatic blocks-changing

snap8
Jens Mönig 2022-05-17 18:08:22 +02:00
rodzic b205bb822b
commit efa458fe41
4 zmienionych plików z 23 dodań i 20 usunięć

Wyświetl plik

@ -50,6 +50,7 @@
### 2022-05-017
* blocks: added experimental private isChangeableTo(type) method
* blocks, threads: tweaked programmatic blocks-changing
### 2022-05-06
* threads: include currently dragged sprites in the MY OTHER SPRITES/CLONES lists

Wyświetl plik

@ -17,7 +17,7 @@
<script src="src/symbols.js?version=2021-03-03"></script>
<script src="src/widgets.js?version=2021-17-09"></script>
<script src="src/blocks.js?version=2022-05-17"></script>
<script src="src/threads.js?version=2022-05-03"></script>
<script src="src/threads.js?version=2022-05-17"></script>
<script src="src/objects.js?version=2022-05-02"></script>
<script src="src/scenes.js?version=2022-03-03"></script>
<script src="src/gui.js?version=2022-04-26"></script>

Wyświetl plik

@ -3577,28 +3577,19 @@ BlockMorph.prototype.isChangeableTo = function (type) {
// a block is considered "changeable" if
// -------------------------------------
// * it's a command & the target type isn't also a command & doesn't have a
// next block & its parent also isn't a syntax element (block or C-shaped
// slot), except it can be a ring.
// next block & is unattached (e.g. the only expression inside a context).
//
// * it's a reporter or a predicate & the target type is a command & its
// parent is not a block, except it can be a ring.
// * it's a reporter or a predicate & the target type is a command & is
// unattached (e.g. the only expression inside a function context).
//
// * it's a reporter or a predicate & the target type is also a reporter or
// a predicate the type can always be changed
var typ = this.type();
if (typ === type) {return true; }
if (typ === 'command') {
if (this.nextBlock()) {return false; }
if (this.parent instanceof RingMorph) {return true; }
return !(this.parent instanceof SyntaxElementMorph);
if (typ === 'command' || type === 'command') {
return this.isUnattached();
}
// typ is 'reporter' or 'predicate'
if (type === 'command') {
if (this.parent instanceof RingMorph) {return true; }
return !(this.parent instanceof BlockMorph);
}
// type is 'reporter' or 'predicate'
return true;
};
@ -3608,6 +3599,13 @@ BlockMorph.prototype.type = function () {
: (this.isPredicate ? 'predicate' : 'reporter');
};
BlockMorph.prototype.isUnattached = function () {
// private
return ((this.nextBlock && !this.nextBlock()) || !this.nextBlock) &&
!(this.parent instanceof SyntaxElementMorph) &&
!(this.parent instanceof ScriptsMorph)
};
BlockMorph.prototype.isInheritedVariable = function (shadowedOnly) {
// private - only for variable getter template inside the palette
if (this.isTemplate &&

Wyświetl plik

@ -65,7 +65,7 @@ StagePickerMorph, CustomBlockDefinition*/
/*jshint esversion: 11, bitwise: false, evil: true*/
modules.threads = '2022-May-06';
modules.threads = '2022-May-17';
var ThreadManager;
var Process;
@ -5687,9 +5687,6 @@ Process.prototype.doSetBlockAttribute = function (attribute, block, val) {
'other';
break;
case 'type':
if (isInUse()) {
throw new Error('cannot change this\nfor a block that is in use');
}
this.assertType(val, ['number', 'text']);
if (this.reportTypeOf(val) === 'text') {
type = val;
@ -5697,7 +5694,14 @@ Process.prototype.doSetBlockAttribute = function (attribute, block, val) {
type = types[val - 1] || '';
}
if (!types.includes(type)) {return;}
def.type = type;
if (rcvr.allBlockInstances(def).every(block =>
block.isChangeableTo(type))
) {
def.type = type;
} else {
throw new Error('cannot change this\nfor a block that is in use');
}
break;
case 'scope':
if (isInUse()) {