mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
Update naming and implementation for custom procedure blocks
This commit is contained in:
parent
ba5b3093f6
commit
34dfbb50ba
7 changed files with 36 additions and 28 deletions
|
@ -13,17 +13,18 @@ class Scratch3ProcedureBlocks {
|
|||
*/
|
||||
getPrimitives () {
|
||||
return {
|
||||
procedures_defnoreturn: this.defNoReturn,
|
||||
procedures_callnoreturn: this.callNoReturn,
|
||||
procedures_param: this.param
|
||||
procedures_definition: this.definition,
|
||||
procedures_call: this.call,
|
||||
argument_reporter_string_number: this.param,
|
||||
argument_reporter_boolean: this.param
|
||||
};
|
||||
}
|
||||
|
||||
defNoReturn () {
|
||||
definition () {
|
||||
// No-op: execute the blocks.
|
||||
}
|
||||
|
||||
callNoReturn (args, util) {
|
||||
call (args, util) {
|
||||
if (!util.stackFrame.executed) {
|
||||
const procedureCode = args.mutation.proccode;
|
||||
const paramNames = util.getProcedureParamNames(procedureCode);
|
||||
|
@ -47,7 +48,7 @@ class Scratch3ProcedureBlocks {
|
|||
}
|
||||
|
||||
param (args, util) {
|
||||
const value = util.getParam(args.mutation.paramname);
|
||||
const value = util.getParam(args.VALUE);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,8 +152,7 @@ class Blocks {
|
|||
for (const id in this._blocks) {
|
||||
if (!this._blocks.hasOwnProperty(id)) continue;
|
||||
const block = this._blocks[id];
|
||||
if (block.opcode === 'procedures_defnoreturn' ||
|
||||
block.opcode === 'procedures_defreturn') {
|
||||
if (block.opcode === 'procedures_definition') {
|
||||
const internal = this._getCustomBlockInternal(block);
|
||||
if (internal && internal.mutation.proccode === name) {
|
||||
return id; // The outer define block id
|
||||
|
@ -172,7 +171,7 @@ class Blocks {
|
|||
for (const id in this._blocks) {
|
||||
if (!this._blocks.hasOwnProperty(id)) continue;
|
||||
const block = this._blocks[id];
|
||||
if (block.opcode === 'procedures_callnoreturn_internal' &&
|
||||
if (block.opcode === 'procedures_prototype' &&
|
||||
block.mutation.proccode === name) {
|
||||
return JSON.parse(block.mutation.argumentnames);
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ class Thread {
|
|||
let blockID = this.peekStack();
|
||||
while (blockID !== null) {
|
||||
const block = this.target.blocks.getBlock(blockID);
|
||||
if (typeof block !== 'undefined' && block.opcode === 'procedures_callnoreturn') {
|
||||
if (typeof block !== 'undefined' && block.opcode === 'procedures_call') {
|
||||
break;
|
||||
}
|
||||
this.popStack();
|
||||
|
@ -271,7 +271,7 @@ class Thread {
|
|||
const sp = this.stack.length - 1;
|
||||
for (let i = sp - 1; i >= 0; i--) {
|
||||
const block = this.target.blocks.getBlock(this.stack[i]);
|
||||
if (block.opcode === 'procedures_callnoreturn' &&
|
||||
if (block.opcode === 'procedures_call' &&
|
||||
block.mutation.proccode === procedureCode) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -518,7 +518,7 @@ const parseBlock = function (sb2block, getVariableId, extensions) {
|
|||
};
|
||||
activeBlock.children = [{
|
||||
id: inputUid,
|
||||
opcode: 'procedures_callnoreturn_internal',
|
||||
opcode: 'procedures_prototype',
|
||||
inputs: {},
|
||||
fields: {},
|
||||
next: null,
|
||||
|
@ -544,13 +544,15 @@ const parseBlock = function (sb2block, getVariableId, extensions) {
|
|||
argumentids: JSON.stringify(parseProcedureArgIds(sb2block[1]))
|
||||
};
|
||||
} else if (oldOpcode === 'getParam') {
|
||||
// Mutation for procedure parameter.
|
||||
activeBlock.mutation = {
|
||||
tagName: 'mutation',
|
||||
children: [],
|
||||
paramname: sb2block[1], // Name of parameter.
|
||||
shape: sb2block[2] // Shape - in 2.0, 'r' or 'b'.
|
||||
};
|
||||
// Assign correct opcode based on the block shape.
|
||||
switch (sb2block[2]) {
|
||||
case 'r':
|
||||
activeBlock.opcode = 'argument_reporter_string_number';
|
||||
break;
|
||||
case 'b':
|
||||
activeBlock.opcode = 'argument_reporter_boolean';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return activeBlock;
|
||||
};
|
||||
|
|
|
@ -1382,15 +1382,21 @@ const specMap = {
|
|||
]
|
||||
},
|
||||
'procDef': {
|
||||
opcode: 'procedures_defnoreturn',
|
||||
opcode: 'procedures_definition',
|
||||
argMap: []
|
||||
},
|
||||
'getParam': {
|
||||
opcode: 'procedures_param',
|
||||
argMap: []
|
||||
// Doesn't map to single opcode. Import step assigns final correct opcode.
|
||||
opcode: 'argument_reporter_string_number',
|
||||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'VALUE'
|
||||
}
|
||||
]
|
||||
},
|
||||
'call': {
|
||||
opcode: 'procedures_callnoreturn',
|
||||
opcode: 'procedures_call',
|
||||
argMap: []
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ const generateBlock = function (id) {
|
|||
block: 'fakeBlock',
|
||||
name: 'fakeName',
|
||||
next: null,
|
||||
opcode: 'procedures_defnoreturn',
|
||||
opcode: 'procedures_definition',
|
||||
mutation: {proccode: 'fakeCode'},
|
||||
parent: null,
|
||||
shadow: false,
|
||||
|
@ -55,7 +55,7 @@ const generateBlockInput = function (id, next, inp) {
|
|||
block: 'fakeBlock',
|
||||
name: 'fakeName',
|
||||
next: next,
|
||||
opcode: 'procedures_defnoreturn',
|
||||
opcode: 'procedures_definition',
|
||||
mutation: {proccode: 'fakeCode'},
|
||||
parent: null,
|
||||
shadow: false,
|
||||
|
@ -156,7 +156,7 @@ test('stepToProcedure', t => {
|
|||
|
||||
th.target.blocks.createBlock({
|
||||
id: 'internalId',
|
||||
opcode: 'procedures_callnoreturn_internal',
|
||||
opcode: 'procedures_prototype',
|
||||
mutation: {
|
||||
proccode: 'othercode'
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ test('stopThisScript', t => {
|
|||
block: 'fakeBlock',
|
||||
name: 'STEPS',
|
||||
next: null,
|
||||
opcode: 'procedures_callnoreturn',
|
||||
opcode: 'procedures_call',
|
||||
mutation: {proccode: 'fakeCode'},
|
||||
parent: null,
|
||||
shadow: false,
|
||||
|
@ -246,7 +246,7 @@ test('isRecursiveCall', t => {
|
|||
block: 'fakeBlock',
|
||||
name: 'STEPS',
|
||||
next: null,
|
||||
opcode: 'procedures_callnoreturn',
|
||||
opcode: 'procedures_call',
|
||||
mutation: {proccode: 'fakeCode'},
|
||||
parent: null,
|
||||
shadow: false,
|
||||
|
|
Loading…
Reference in a new issue