kopia lustrzana https://github.com/backface/turtlestitch
tweaked programmatic blocks-changing
rodzic
b205bb822b
commit
efa458fe41
|
@ -50,6 +50,7 @@
|
||||||
|
|
||||||
### 2022-05-017
|
### 2022-05-017
|
||||||
* blocks: added experimental private isChangeableTo(type) method
|
* blocks: added experimental private isChangeableTo(type) method
|
||||||
|
* blocks, threads: tweaked programmatic blocks-changing
|
||||||
|
|
||||||
### 2022-05-06
|
### 2022-05-06
|
||||||
* threads: include currently dragged sprites in the MY OTHER SPRITES/CLONES lists
|
* threads: include currently dragged sprites in the MY OTHER SPRITES/CLONES lists
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<script src="src/symbols.js?version=2021-03-03"></script>
|
<script src="src/symbols.js?version=2021-03-03"></script>
|
||||||
<script src="src/widgets.js?version=2021-17-09"></script>
|
<script src="src/widgets.js?version=2021-17-09"></script>
|
||||||
<script src="src/blocks.js?version=2022-05-17"></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/objects.js?version=2022-05-02"></script>
|
||||||
<script src="src/scenes.js?version=2022-03-03"></script>
|
<script src="src/scenes.js?version=2022-03-03"></script>
|
||||||
<script src="src/gui.js?version=2022-04-26"></script>
|
<script src="src/gui.js?version=2022-04-26"></script>
|
||||||
|
|
|
@ -3577,28 +3577,19 @@ BlockMorph.prototype.isChangeableTo = function (type) {
|
||||||
// a block is considered "changeable" if
|
// a block is considered "changeable" if
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
// * it's a command & the target type isn't also a command & doesn't have a
|
// * 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
|
// next block & is unattached (e.g. the only expression inside a context).
|
||||||
// slot), except it can be a ring.
|
|
||||||
//
|
//
|
||||||
// * it's a reporter or a predicate & the target type is a command & its
|
// * it's a reporter or a predicate & the target type is a command & is
|
||||||
// parent is not a block, except it can be a ring.
|
// 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
|
// * it's a reporter or a predicate & the target type is also a reporter or
|
||||||
// a predicate the type can always be changed
|
// a predicate the type can always be changed
|
||||||
|
|
||||||
var typ = this.type();
|
var typ = this.type();
|
||||||
if (typ === type) {return true; }
|
if (typ === type) {return true; }
|
||||||
if (typ === 'command') {
|
if (typ === 'command' || type === 'command') {
|
||||||
if (this.nextBlock()) {return false; }
|
return this.isUnattached();
|
||||||
if (this.parent instanceof RingMorph) {return true; }
|
|
||||||
return !(this.parent instanceof SyntaxElementMorph);
|
|
||||||
}
|
}
|
||||||
// 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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3608,6 +3599,13 @@ BlockMorph.prototype.type = function () {
|
||||||
: (this.isPredicate ? 'predicate' : 'reporter');
|
: (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) {
|
BlockMorph.prototype.isInheritedVariable = function (shadowedOnly) {
|
||||||
// private - only for variable getter template inside the palette
|
// private - only for variable getter template inside the palette
|
||||||
if (this.isTemplate &&
|
if (this.isTemplate &&
|
||||||
|
|
|
@ -65,7 +65,7 @@ StagePickerMorph, CustomBlockDefinition*/
|
||||||
|
|
||||||
/*jshint esversion: 11, bitwise: false, evil: true*/
|
/*jshint esversion: 11, bitwise: false, evil: true*/
|
||||||
|
|
||||||
modules.threads = '2022-May-06';
|
modules.threads = '2022-May-17';
|
||||||
|
|
||||||
var ThreadManager;
|
var ThreadManager;
|
||||||
var Process;
|
var Process;
|
||||||
|
@ -5687,9 +5687,6 @@ Process.prototype.doSetBlockAttribute = function (attribute, block, val) {
|
||||||
'other';
|
'other';
|
||||||
break;
|
break;
|
||||||
case 'type':
|
case 'type':
|
||||||
if (isInUse()) {
|
|
||||||
throw new Error('cannot change this\nfor a block that is in use');
|
|
||||||
}
|
|
||||||
this.assertType(val, ['number', 'text']);
|
this.assertType(val, ['number', 'text']);
|
||||||
if (this.reportTypeOf(val) === 'text') {
|
if (this.reportTypeOf(val) === 'text') {
|
||||||
type = val;
|
type = val;
|
||||||
|
@ -5697,7 +5694,14 @@ Process.prototype.doSetBlockAttribute = function (attribute, block, val) {
|
||||||
type = types[val - 1] || '';
|
type = types[val - 1] || '';
|
||||||
}
|
}
|
||||||
if (!types.includes(type)) {return;}
|
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;
|
break;
|
||||||
case 'scope':
|
case 'scope':
|
||||||
if (isInUse()) {
|
if (isInUse()) {
|
||||||
|
|
Ładowanie…
Reference in New Issue