kopia lustrzana https://github.com/backface/turtlestitch
never push untested last minute changes that might break everything
rodzic
26b2f16e21
commit
9932f6ba2f
|
@ -69,6 +69,9 @@
|
|||
* Chinese, thanks, Simon!
|
||||
* Brazilian Portuguese, thank you, Cassiano D'Andrea!
|
||||
|
||||
### 2021-12-09
|
||||
* blocks, threads: never push untested last minute changes that might break everything
|
||||
|
||||
### 2021-12-08
|
||||
* blocks: refactored syntax trees
|
||||
* rc1
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<script src="src/morphic.js?version=2021-07-09"></script>
|
||||
<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=2021-12-08"></script>
|
||||
<script src="src/threads.js?version=2021-12-06"></script>
|
||||
<script src="src/blocks.js?version=2021-12-09"></script>
|
||||
<script src="src/threads.js?version=2021-12-09"></script>
|
||||
<script src="src/objects.js?version=2021-12-07"></script>
|
||||
<script src="src/scenes.js?version=2021-11-24"></script>
|
||||
<script src="src/gui.js?version=2021-12-08"></script>
|
||||
|
|
|
@ -160,7 +160,7 @@ CustomCommandBlockMorph, ToggleButtonMorph, DialMorph, SnapExtensions*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.blocks = '2021-December-08';
|
||||
modules.blocks = '2021-December-09';
|
||||
|
||||
var SyntaxElementMorph;
|
||||
var BlockMorph;
|
||||
|
@ -1279,30 +1279,63 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
|
|||
};
|
||||
|
||||
SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) {
|
||||
var deflt = this.revertToEmptyInput(arg),
|
||||
inp = this.inputs().indexOf(deflt),
|
||||
def;
|
||||
if (noValues || inp < 0) {
|
||||
return deflt;
|
||||
}
|
||||
if (this instanceof BlockMorph) {
|
||||
if (this.isCustomBlock) {
|
||||
def = this.isGlobal ? this.definition
|
||||
: this.scriptTarget().getMethod(this.blockSpec);
|
||||
if (!noValues &&
|
||||
(deflt instanceof InputSlotMorph ||
|
||||
deflt instanceof BooleanSlotMorph)
|
||||
) {
|
||||
deflt.setContents(
|
||||
def.defaultValueOfInputIdx(inp)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deflt instanceof MultiArgMorph && !inp) {
|
||||
// first - and only - input is variadic
|
||||
deflt.setContents(this.defaults);
|
||||
deflt.defaults = this.defaults;
|
||||
} else if (!isNil(this.defaults[inp])) {
|
||||
deflt.setContents(this.defaults[inp]);
|
||||
if (deflt instanceof MultiArgMorph) {
|
||||
deflt.defaults = this.defaults[inp];
|
||||
}
|
||||
}
|
||||
return deflt;
|
||||
};
|
||||
|
||||
SyntaxElementMorph.prototype.revertToEmptyInput = function (arg) {
|
||||
var idx = this.parts().indexOf(arg),
|
||||
inp = this.inputs().indexOf(arg),
|
||||
deflt = new InputSlotMorph(),
|
||||
def;
|
||||
rcvr, def;
|
||||
|
||||
if (idx !== -1) {
|
||||
if (this instanceof BlockMorph) {
|
||||
deflt = this.labelPart(this.parseSpec(this.blockSpec)[idx]);
|
||||
if (this.isCustomBlock) {
|
||||
def = this.isGlobal ? this.definition
|
||||
: this.scriptTarget().getMethod(this.blockSpec);
|
||||
if (deflt instanceof InputSlotMorph) {
|
||||
if (this.isGlobal) {
|
||||
def = this.definition;
|
||||
} else {
|
||||
rcvr = this.scriptTarget(true);
|
||||
if (rcvr) {
|
||||
def = rcvr.getMethod(this.blockSpec);
|
||||
}
|
||||
}
|
||||
if (def && deflt instanceof InputSlotMorph) {
|
||||
deflt.setChoices.apply(
|
||||
deflt,
|
||||
def.inputOptionsOfIdx(inp)
|
||||
);
|
||||
}
|
||||
if (deflt instanceof InputSlotMorph ||
|
||||
(deflt instanceof BooleanSlotMorph)
|
||||
) {
|
||||
deflt.setContents(
|
||||
def.defaultValueOfInputIdx(inp)
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (this instanceof MultiArgMorph) {
|
||||
deflt = this.labelPart(this.slotSpec);
|
||||
|
@ -1310,21 +1343,6 @@ SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) {
|
|||
deflt = this.emptySlot();
|
||||
}
|
||||
}
|
||||
// set default value
|
||||
if (!noValues) {
|
||||
if (inp !== -1) {
|
||||
if (deflt instanceof MultiArgMorph && !inp) {
|
||||
// first - and only - input is variadic
|
||||
deflt.setContents(this.defaults);
|
||||
deflt.defaults = this.defaults;
|
||||
} else if (!isNil(this.defaults[inp])) {
|
||||
deflt.setContents(this.defaults[inp]);
|
||||
if (deflt instanceof MultiArgMorph) {
|
||||
deflt.defaults = this.defaults[inp];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deflt.icon || deflt instanceof BooleanSlotMorph) {
|
||||
deflt.fixLayout();
|
||||
}
|
||||
|
@ -2625,7 +2643,7 @@ BlockMorph.prototype.init = function () {
|
|||
this.cachedInputs = null;
|
||||
};
|
||||
|
||||
BlockMorph.prototype.scriptTarget = function () {
|
||||
BlockMorph.prototype.scriptTarget = function (noError) {
|
||||
// answer the sprite or stage that this block acts on,
|
||||
// if the user clicks on it.
|
||||
// NOTE: since scripts can be shared by more than a single sprite
|
||||
|
@ -2650,6 +2668,7 @@ BlockMorph.prototype.scriptTarget = function () {
|
|||
return dlg.target.currentSprite;
|
||||
}
|
||||
}
|
||||
if (noError) {return null; }
|
||||
throw new Error('script target cannot be found for orphaned block');
|
||||
};
|
||||
|
||||
|
@ -3749,10 +3768,13 @@ BlockMorph.prototype.syntaxTree = function (parameterNames) {
|
|||
return;
|
||||
}
|
||||
parts.add(inp.components());
|
||||
expr.revertToDefaultInput(inp, true);
|
||||
expr.revertToEmptyInput(inp);
|
||||
} else if (inp.isEmptySlot()) {
|
||||
parts.add();
|
||||
} else if (inp instanceof MultiArgMorph) {
|
||||
if (!inp.inputs().length) {
|
||||
parts.add();
|
||||
}
|
||||
inp.inputs().forEach((slot, i) => {
|
||||
var entry;
|
||||
if (slot instanceof BlockMorph) {
|
||||
|
@ -3768,15 +3790,18 @@ BlockMorph.prototype.syntaxTree = function (parameterNames) {
|
|||
parts.add(entry instanceof BlockMorph ?
|
||||
entry.components() : entry);
|
||||
}
|
||||
inp.revertToDefaultInput(slot, true);
|
||||
inp.revertToEmptyInput(slot);
|
||||
});
|
||||
} else if (inp instanceof ArgLabelMorph) {
|
||||
parts.add(inp.argMorph().components());
|
||||
expr.revertToDefaultInput(inp, true).collapseAll();
|
||||
expr.revertToEmptyInput(inp).collapseAll();
|
||||
} else {
|
||||
val = inp.evaluate();
|
||||
if (inp instanceof ColorSlotMorph) {
|
||||
val = val.toString();
|
||||
}
|
||||
parts.add(val instanceof BlockMorph ? val.components() : val);
|
||||
expr.revertToDefaultInput(inp, true);
|
||||
expr.revertToEmptyInput(inp, true);
|
||||
}
|
||||
});
|
||||
parts.at(1).updateEmptySlots();
|
||||
|
@ -3804,14 +3829,14 @@ BlockMorph.prototype.copyWithInputs = function (inputs) {
|
|||
// restore input slots
|
||||
slots.forEach(slt => {
|
||||
if (slt instanceof BlockMorph) {
|
||||
dflt = cpy.revertToDefaultInput(slt);
|
||||
dflt = cpy.revertToEmptyInput(slt);
|
||||
if (dflt instanceof MultiArgMorph) {
|
||||
dflt.collapseAll();
|
||||
}
|
||||
} else if (slt instanceof MultiArgMorph) {
|
||||
slt.inputs().forEach(entry => {
|
||||
if (entry instanceof BlockMorph) {
|
||||
slt.revertToDefaultInput(entry);
|
||||
slt.revertToEmptyInput(entry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -3858,6 +3883,8 @@ BlockMorph.prototype.copyWithInputs = function (inputs) {
|
|||
} else {
|
||||
if (inp instanceof List && inp.length() === 0) {
|
||||
nop(); // ignore, i.e. leave slot as is
|
||||
} else if (slot instanceof ColorSlotMorph) {
|
||||
slot.setColor(Color.fromString(inp));
|
||||
} else if (slot instanceof InputSlotMorph ||
|
||||
slot instanceof TemplateSlotMorph ||
|
||||
slot instanceof BooleanSlotMorph) {
|
||||
|
|
|
@ -64,7 +64,7 @@ SnapExtensions, AlignmentMorph, TextMorph, Cloud, HatBlockMorph*/
|
|||
|
||||
/*jshint esversion: 6*/
|
||||
|
||||
modules.threads = '2021-December-07';
|
||||
modules.threads = '2021-December-09';
|
||||
|
||||
var ThreadManager;
|
||||
var Process;
|
||||
|
@ -5463,7 +5463,7 @@ Process.prototype.reportBasicBlockAttribute = function (attribute, block) {
|
|||
case 'definition':
|
||||
if (expr.isCustomBlock) {
|
||||
if (expr.isGlobal) {
|
||||
return expr.definition.body;
|
||||
return expr.definition.body || new Context();
|
||||
}
|
||||
return this.blockReceiver().getMethod(expr.semanticSpec).body ||
|
||||
new Context();
|
||||
|
|
Ładowanie…
Reference in New Issue