kopia lustrzana https://github.com/backface/turtlestitch
new "menus" selector for block attributes
rodzic
c848f2d263
commit
23b2f08d51
|
@ -16,7 +16,7 @@
|
|||
* new MOUSE POSITION primitive reporter in the SENSING category
|
||||
* new "position" choice in OF reporter's attribute dropdown, reports a list of XY coordinates
|
||||
* new "categories" choice in MY reporter's dropdown, reports an ordered list of all category names whose indices match the "category" reported elsewhere
|
||||
* new "label", "type", "scope" and "slots" choices in the OF BLOCK block-attribute reporter's dropdown
|
||||
* new "label", "type", "scope", "slots" and "menus" choices in the OF BLOCK block-attribute reporter's dropdown
|
||||
* new "set attribute of block" primitive, experimental
|
||||
* new "define block" primitive, experimental
|
||||
* new "this script" primitive, experimental
|
||||
|
@ -30,6 +30,7 @@
|
|||
* imported single scripts are now placed into the hand, for the user to position them in the scripting area
|
||||
* moved "append", "reshape", "combinations" blocks down one group in the palette
|
||||
* moved "current date" block up to "timer" group in the palette
|
||||
* moved "attribute of block" block from the sensing category to control
|
||||
* include currently dragged sprites in the MY OTHER SPRITES/CLONES lists
|
||||
* library import dialog makeover for custom categories and hidden blocks, thanks, Michael!
|
||||
* when querying a custom reporter's "definition" property only report its reporter without the REPORT block (if applicable)
|
||||
|
@ -52,6 +53,9 @@
|
|||
* **Translation Updates:**
|
||||
* German
|
||||
|
||||
### 2022-06-28
|
||||
* blocks, byob, threads: new "menus" selector for block attributes
|
||||
|
||||
### 2022-06-27
|
||||
* threads: trim block label before identifying existing definition in DEFINE
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
<script src="src/morphic.js?version=2022-04-26"></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=2022-06-22"></script>
|
||||
<script src="src/threads.js?version=2022-06-27"></script>
|
||||
<script src="src/blocks.js?version=2022-06-28"></script>
|
||||
<script src="src/threads.js?version=2022-06-28"></script>
|
||||
<script src="src/objects.js?version=2022-06-23"></script>
|
||||
<script src="src/scenes.js?version=2022-03-03"></script>
|
||||
<script src="src/gui.js?version=2022-05-19"></script>
|
||||
<script src="src/paint.js?version=2021-07-05"></script>
|
||||
<script src="src/lists.js?version=2022-05-19"></script>
|
||||
<script src="src/byob.js?version=2022-05-25"></script>
|
||||
<script src="src/byob.js?version=2022-06-28"></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>
|
||||
|
|
|
@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume, embedMetadataPNG*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.blocks = '2022-June-22';
|
||||
modules.blocks = '2022-June-28';
|
||||
|
||||
var SyntaxElementMorph;
|
||||
var BlockMorph;
|
||||
|
@ -808,7 +808,8 @@ SyntaxElementMorph.prototype.labelParts = {
|
|||
'global?': ['global?'],
|
||||
'type': ['type'],
|
||||
'scope': ['scope'],
|
||||
'slots': ['slots']
|
||||
'slots': ['slots'],
|
||||
'menus' : ['menus']
|
||||
}
|
||||
},
|
||||
'%byob': {
|
||||
|
@ -820,7 +821,8 @@ SyntaxElementMorph.prototype.labelParts = {
|
|||
'category': ['category'],
|
||||
'type': ['type'],
|
||||
'scope': ['scope'],
|
||||
'slots': ['slots']
|
||||
'slots': ['slots'],
|
||||
'menus' : ['menus']
|
||||
}
|
||||
},
|
||||
|
||||
|
|
48
src/byob.js
48
src/byob.js
|
@ -111,7 +111,7 @@ ArgLabelMorph*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.byob = '2022-May-25';
|
||||
modules.byob = '2022-June-28';
|
||||
|
||||
// Declarations
|
||||
|
||||
|
@ -374,6 +374,52 @@ CustomBlockDefinition.prototype.parseChoices = function (string) {
|
|||
return dict;
|
||||
};
|
||||
|
||||
CustomBlockDefinition.prototype.encodeChoices = function (list) {
|
||||
// answer a string representing a parseable dropdown menu for an input slot
|
||||
var encode = (dta) => dta instanceof List ?
|
||||
encodeList(dta) : dta.toString(),
|
||||
encodeList = (dta) => dta.length() === 2 ? encodePair(dta)
|
||||
: dta.itemsArray().reduce(
|
||||
(a, b) => encode(a) + '\n' + encode(b)),
|
||||
encodePair = (dta) => encode(dta.at(1)) + '=' +
|
||||
(dta.at(2) instanceof List ?
|
||||
encodeSub(dta.at(2))
|
||||
: encode(dta.at(2))),
|
||||
encodeSub = (dta) => '{\n' + encode(dta) + '\n}';
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
return list.itemsArray().reduce((a, b) => encode(a) + '\n' + encode(b));
|
||||
};
|
||||
|
||||
CustomBlockDefinition.prototype.decodeChoices = function (choices) {
|
||||
// answer a (nested) List representing the input slot dropdown menu
|
||||
var list = new List(),
|
||||
key;
|
||||
for (key in choices) {
|
||||
if (Object.prototype.hasOwnProperty.call(choices, key)) {
|
||||
if (key[0] === '~') {
|
||||
list.add(key[0]);
|
||||
} else if (choices[key] instanceof Object &&
|
||||
!(choices[key] instanceof Array) &&
|
||||
(typeof choices[key] !== 'function')) {
|
||||
list.add(new List([key, this.decodeChoices(choices[key])]));
|
||||
} else if (choices[key] instanceof Array &&
|
||||
choices[key][0] instanceof Object &&
|
||||
typeof choices[key][0] !== 'function') {
|
||||
|
||||
list.add(new List([key, this.decodeChoices(choices[key][0])]));
|
||||
} else {
|
||||
list.add(choices[key] === key ? key
|
||||
: new List([key, choices[key]])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
CustomBlockDefinition.prototype.menuSearchWords = function () {
|
||||
// return a single string containing words that can be searched for
|
||||
// inside my dropdown menus
|
||||
|
|
|
@ -65,7 +65,7 @@ StagePickerMorph, CustomBlockDefinition*/
|
|||
|
||||
/*jshint esversion: 11, bitwise: false, evil: true*/
|
||||
|
||||
modules.threads = '2022-June-27';
|
||||
modules.threads = '2022-June-28';
|
||||
|
||||
var ThreadManager;
|
||||
var Process;
|
||||
|
@ -5612,7 +5612,7 @@ Process.prototype.reportBlockAttribute = function (attribute, block) {
|
|||
|
||||
Process.prototype.reportBasicBlockAttribute = function (attribute, block) {
|
||||
var choice = this.inputOption(attribute),
|
||||
expr, body, slots;
|
||||
expr, body, slots, def;
|
||||
this.assertType(block, ['command', 'reporter', 'predicate']);
|
||||
expr = block.expression;
|
||||
switch (choice) {
|
||||
|
@ -5663,6 +5663,17 @@ Process.prototype.reportBasicBlockAttribute = function (attribute, block) {
|
|||
each.getSlotSpec() : each.getSpec()
|
||||
)
|
||||
).map(spec => this.slotType(spec));
|
||||
case 'menus':
|
||||
slots = new List();
|
||||
if (expr.isCustomBlock) {
|
||||
def = (expr.isGlobal ?
|
||||
expr.definition
|
||||
: this.blockReceiver().getMethod(expr.semanticSpec));
|
||||
def.declarations.forEach(value => slots.add(
|
||||
def.decodeChoices(def.parseChoices(value[2]))
|
||||
));
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
@ -5944,6 +5955,23 @@ Process.prototype.doSetBlockAttribute = function (attribute, block, val) {
|
|||
}
|
||||
});
|
||||
break;
|
||||
case 'menus':
|
||||
this.assertType(val, ['list', 'text', 'number']);
|
||||
if (!(val instanceof List)) {
|
||||
val = new List([val.toString()]);
|
||||
}
|
||||
def.inputNames().forEach((name, idx) => {
|
||||
var info = def.declarations.get(name),
|
||||
options = val.at(idx + 1);
|
||||
if (options !== '') {
|
||||
if (!(options instanceof List)) {
|
||||
options = new List([options]);
|
||||
}
|
||||
info[2] = def.encodeChoices(options); // +++ || info[2];
|
||||
def.declarations.set(name, info);
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue