custom block definition api, highly experimental, very much under construction

snap8
Jens Mönig 2022-04-27 18:46:15 +02:00
rodzic 7f843742a7
commit d221254ecc
4 zmienionych plików z 94 dodań i 4 usunięć

Wyświetl plik

@ -44,6 +44,9 @@
* **Translation Updates:**
* German
### 2022-04-27
* threads, byob: custom block definition api, highly experimental, very much under construction
### 2022-04-26
* gui: distinguish between embedded blocks code and raw data in PNGs
* morphic: fixed bulk-drop of images

Wyświetl plik

@ -17,13 +17,13 @@
<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-04-22"></script>
<script src="src/threads.js?version=2022-04-20"></script>
<script src="src/threads.js?version=2022-04-27"></script>
<script src="src/objects.js?version=2022-04-25"></script>
<script src="src/scenes.js?version=2022-03-03"></script>
<script src="src/gui.js?version=2022-04-26"></script>
<script src="src/paint.js?version=2021-07-05"></script>
<script src="src/lists.js?version=2022-02-07"></script>
<script src="src/byob.js?version=2022-04-20"></script>
<script src="src/byob.js?version=2022-04-27"></script>
<script src="src/tables.js?version=2022-01-28"></script>
<script src="src/sketch.js?version=2021-11-03"></script>
<script src="src/video.js?version=2019-06-27"></script>

Wyświetl plik

@ -111,7 +111,7 @@ ArgLabelMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2022-April-20';
modules.byob = '2022-April-27';
// Declarations
@ -530,6 +530,37 @@ CustomBlockDefinition.prototype.updateTranslations = function (text) {
});
};
// CustomBlockDefinition API, highly experimental & under construction
CustomBlockDefinition.prototype.setBlockLabel = function (abstractSpec) {
// private - only to be called from a Process that also does housekeeping
// abstract block specs replace the inputs with underscores,
// e.g. "move _ steps", "say _", "_ + _"
var count = abstractSpec.split(' ').filter(word => word === '_').length,
inputNames = this.inputNames(),
parts = [],
spec = abstractSpec;
if (count !== inputNames.length) { // not yet sure about this... (jens)
throw new Error('expecting the number of inputs to match');
}
if (spec.startsWith('_ ')) {
parts.push('');
spec = spec.slice(2);
}
if (spec.endsWith(' _')) {
spec = spec.slice(0, -2);
}
parts = parts.concat(spec.split(' _ '));
spec = '';
parts.forEach((part, i) =>
spec += (part + (
inputNames[i] ? ' %\'' + inputNames[i] + '\' ' : '')
)
);
this.spec = spec.trim();
};
// CustomBlockDefinition picturing
CustomBlockDefinition.prototype.scriptsPicture = function () {

Wyświetl plik

@ -65,7 +65,7 @@ StagePickerMorph*/
/*jshint esversion: 11, bitwise: false, evil: true*/
modules.threads = '2022-April-20';
modules.threads = '2022-April-27';
var ThreadManager;
var Process;
@ -5624,6 +5624,62 @@ Process.prototype.reportBasicBlockAttribute = function (attribute, block) {
return '';
};
Process.prototype.doSetBlockAttribute = function (attribute, block, val) {
// highly experimental & under construction
var choice = this.inputOption(attribute),
rcvr = this.blockReceiver(),
ide = rcvr.parentThatIsA(IDE_Morph),
oldSpec,
count = 1,
expr,
def,
template;
this.assertType(block, ['command', 'reporter', 'predicate']);
expr = block.expression;
def = expr.isGlobal ? expr.definition : rcvr.getMethod(expr.semanticSpec);
oldSpec = def.blockSpec();
switch (choice) {
case 'label':
def.setBlockLabel(val);
break;
case 'definition':
return;
case 'category':
return;
case 'global?':
return;
}
// make sure the spec is unique
while (rcvr.doubleDefinitionsFor(def).length > 0) {
count += 1;
def.spec += (' (' + count + ')');
}
// update all block instances:
// refer to "updateDefinition()" of BlockEditorMorph:
template = rcvr.paletteBlockInstance(def);
if (def.isGlobal) {
rcvr.allBlockInstances(def).reverse().forEach(
block => block.refresh()
);
} else {
rcvr.allDependentInvocationsOf(oldSpec).reverse().forEach(
block => block.refresh(def)
);
}
if (template) {
template.refreshDefaults();
}
ide.flushPaletteCache();
ide.categories.refreshEmpty();
ide.refreshPalette();
ide.recordUnsavedChanges();
};
Process.prototype.reportAttributeOf = function (attribute, name) {
// hyper-dyadic
// note: specifying strings in the left input only accesses