kopia lustrzana https://github.com/backface/turtlestitch
adjusted restoring inputs for relabelling to / from variadic infix reporters
rodzic
93c6d724f5
commit
7346dfb451
|
@ -10,6 +10,9 @@
|
||||||
* **Translation Updates:**
|
* **Translation Updates:**
|
||||||
* German
|
* German
|
||||||
|
|
||||||
|
### 2022-03-01
|
||||||
|
* blocks: adjusted restoring inputs for relabelling to / from variadic infix reporters
|
||||||
|
|
||||||
### 2022-02-28
|
### 2022-02-28
|
||||||
* blocks, objects, threads, store: made addition reporter variadic
|
* blocks, objects, threads, store: made addition reporter variadic
|
||||||
* blocks, objects, threads: made multiplication reporter variadic
|
* blocks, objects, threads: made multiplication reporter variadic
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<script src="src/morphic.js?version=2022-01-28"></script>
|
<script src="src/morphic.js?version=2022-01-28"></script>
|
||||||
<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-02-28"></script>
|
<script src="src/blocks.js?version=2022-03-01"></script>
|
||||||
<script src="src/threads.js?version=2022-02-28"></script>
|
<script src="src/threads.js?version=2022-02-28"></script>
|
||||||
<script src="src/objects.js?version=2022-02-28"></script>
|
<script src="src/objects.js?version=2022-02-28"></script>
|
||||||
<script src="src/scenes.js?version=2021-11-24"></script>
|
<script src="src/scenes.js?version=2021-11-24"></script>
|
||||||
|
|
|
@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2022-February-28';
|
modules.blocks = '2022-March-01';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -3758,13 +3758,15 @@ BlockMorph.prototype.setSelector = function (aSelector, inputOffset = 0) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockMorph.prototype.restoreInputs = function (oldInputs, offset = 0) {
|
BlockMorph.prototype.restoreInputs = function (oldInputs, offset = 0) { // +++++
|
||||||
// private - used only for relabel()
|
// private - used only for relabel()
|
||||||
// try to restore my previous inputs when my spec has been changed
|
// try to restore my previous inputs when my spec has been changed
|
||||||
// return an Array of left-over blocks, if any
|
// return an Array of left-over blocks, if any
|
||||||
// optional offset parameter allows for shifting the range
|
// optional offset parameter allows for shifting the range
|
||||||
// of inputs to be restored
|
// of inputs to be restored
|
||||||
var old, nb, i,
|
var old, nb, i, src, trg,
|
||||||
|
element = this,
|
||||||
|
inputs = this.inputs(),
|
||||||
leftOver = [];
|
leftOver = [];
|
||||||
|
|
||||||
// gather leading surplus blocks
|
// gather leading surplus blocks
|
||||||
|
@ -3780,22 +3782,68 @@ BlockMorph.prototype.restoreInputs = function (oldInputs, offset = 0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// special cases for relabelling to / from single variadic infix reporters
|
||||||
|
src = oldInputs[0];
|
||||||
|
trg = inputs[0];
|
||||||
|
|
||||||
|
// 1.
|
||||||
|
// both blocks have exactly one variadic slot, with the same slot spec but
|
||||||
|
// different infixes, and not nessesarily matching numbers of expanded
|
||||||
|
// slots.
|
||||||
|
if (oldInputs.length === 1 &&
|
||||||
|
(inputs.length === 1) &&
|
||||||
|
src instanceof MultiArgMorph &&
|
||||||
|
trg instanceof MultiArgMorph &&
|
||||||
|
src.slotSpec === trg.slotSpec &&
|
||||||
|
(src.infix !== trg.infix)
|
||||||
|
) {
|
||||||
|
element = trg;
|
||||||
|
oldInputs = src.inputs();
|
||||||
|
while(element.inputs().length < oldInputs.length) {
|
||||||
|
element.addInput();
|
||||||
|
}
|
||||||
|
inputs = element.inputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.
|
||||||
|
// this block has a single variadic infix slot which will hold all of the
|
||||||
|
// old block inputs.
|
||||||
|
else if (oldInputs.length &&
|
||||||
|
(inputs.length === 1) &&
|
||||||
|
trg instanceof MultiArgMorph &&
|
||||||
|
!(src instanceof MultiArgMorph)
|
||||||
|
) {
|
||||||
|
element = trg;
|
||||||
|
inputs = element.inputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3.
|
||||||
|
// the old inputs are a single variadic infix slot whose inputs will be
|
||||||
|
// distributed over this blocks non-variadic slots
|
||||||
|
else if (oldInputs.length === 1 &&
|
||||||
|
inputs.length &&
|
||||||
|
src instanceof MultiArgMorph &&
|
||||||
|
!(trg instanceof MultiArgMorph)
|
||||||
|
) {
|
||||||
|
oldInputs = src.inputs();
|
||||||
|
}
|
||||||
|
|
||||||
// restore matching inputs in their original order
|
// restore matching inputs in their original order
|
||||||
this.inputs().forEach(inp => {
|
inputs.forEach(inp => {
|
||||||
old = oldInputs[offset];
|
old = oldInputs[offset];
|
||||||
if (old instanceof ArgLabelMorph) {
|
if (old instanceof ArgLabelMorph) {
|
||||||
old = old.argMorph();
|
old = old.argMorph();
|
||||||
}
|
}
|
||||||
if (old instanceof RingMorph) {
|
if (old instanceof RingMorph) {
|
||||||
if (old.contents()) {
|
if (old.contents()) {
|
||||||
this.replaceInput(inp, old.fullCopy());
|
element.replaceInput(inp, old.fullCopy());
|
||||||
}
|
}
|
||||||
// otherwise ignore the empty ring
|
// otherwise ignore the empty ring
|
||||||
} else if (old instanceof ReporterBlockMorph) {
|
} else if (old instanceof ReporterBlockMorph) {
|
||||||
if (inp instanceof TemplateSlotMorph || inp.isStatic) {
|
if (inp instanceof TemplateSlotMorph || inp.isStatic) {
|
||||||
leftOver.push(old);
|
leftOver.push(old);
|
||||||
} else {
|
} else {
|
||||||
this.replaceInput(inp, old.fullCopy());
|
element.replaceInput(inp, old.fullCopy());
|
||||||
}
|
}
|
||||||
} else if (old && inp instanceof InputSlotMorph) {
|
} else if (old && inp instanceof InputSlotMorph) {
|
||||||
// original - turns empty numberslots to 0:
|
// original - turns empty numberslots to 0:
|
||||||
|
@ -3814,8 +3862,9 @@ BlockMorph.prototype.restoreInputs = function (oldInputs, offset = 0) {
|
||||||
}
|
}
|
||||||
} else if (old instanceof MultiArgMorph &&
|
} else if (old instanceof MultiArgMorph &&
|
||||||
inp instanceof MultiArgMorph &&
|
inp instanceof MultiArgMorph &&
|
||||||
(old.slotSpec === inp.slotSpec)) {
|
(old.slotSpec === inp.slotSpec) &&
|
||||||
this.replaceInput(inp, old.fullCopy());
|
old.infix === inp.infix) {
|
||||||
|
element.replaceInput(inp, old.fullCopy());
|
||||||
}
|
}
|
||||||
offset += 1;
|
offset += 1;
|
||||||
});
|
});
|
||||||
|
@ -3832,6 +3881,7 @@ BlockMorph.prototype.restoreInputs = function (oldInputs, offset = 0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
element.cachedInputs = null; // +++
|
||||||
this.cachedInputs = null;
|
this.cachedInputs = null;
|
||||||
return leftOver;
|
return leftOver;
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue