mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Finishing up lists.
This commit is contained in:
parent
b18938963f
commit
038a65b460
4 changed files with 51 additions and 19 deletions
|
@ -75,6 +75,10 @@ const domToBlock = function (blockDOM, blocks, isTopBlock, parent) {
|
|||
id: fieldId,
|
||||
value: fieldData
|
||||
};
|
||||
const fieldVarType = xmlChild.attribs.variabletype;
|
||||
if (typeof fieldVarType === 'string') {
|
||||
block.fields[fieldName].variableType = fieldVarType;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'value':
|
||||
|
|
|
@ -499,11 +499,20 @@ class Blocks {
|
|||
for (const field in block.fields) {
|
||||
if (!block.fields.hasOwnProperty(field)) continue;
|
||||
const blockField = block.fields[field];
|
||||
xmlString += `<field name="${blockField.name}"`;
|
||||
const fieldId = blockField.id;
|
||||
if (fieldId) {
|
||||
xmlString += ` id="${fieldId}"`;
|
||||
}
|
||||
const varType = blockField.variableType;
|
||||
if (typeof varType === 'string') {
|
||||
xmlString += ` variabletype="${varType}"`;
|
||||
}
|
||||
let value = blockField.value;
|
||||
if (typeof value === 'string') {
|
||||
value = xmlEscape(blockField.value);
|
||||
}
|
||||
xmlString += `<field name="${blockField.name}">${value}</field>`;
|
||||
xmlString += `>${value}</field>`;
|
||||
}
|
||||
// Add blocks connected to the next connection.
|
||||
if (block.next) {
|
||||
|
|
|
@ -234,7 +234,7 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
|
|||
const newVariable = new Variable(
|
||||
getVariableId(variable.name),
|
||||
variable.name,
|
||||
"",
|
||||
'',
|
||||
variable.isPersistent
|
||||
);
|
||||
newVariable.value = variable.value;
|
||||
|
@ -254,7 +254,7 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
|
|||
const newVariable = new Variable(
|
||||
getVariableId(list.listName),
|
||||
list.listName,
|
||||
"list",
|
||||
'list',
|
||||
list.isPersistent
|
||||
);
|
||||
newVariable.value = list.contents;
|
||||
|
@ -490,10 +490,14 @@ const parseBlock = function (sb2block, getVariableId, extensions) {
|
|||
value: providedArg
|
||||
};
|
||||
|
||||
if (expectedArg.fieldName === 'VARIABLE') {
|
||||
if (expectedArg.fieldName === 'VARIABLE' || expectedArg.fieldName === 'LIST') {
|
||||
// Add `id` property to variable fields
|
||||
activeBlock.fields[expectedArg.fieldName].id = getVariableId(providedArg);
|
||||
}
|
||||
const varType = expectedArg.variableType;
|
||||
if (typeof varType === 'string') {
|
||||
activeBlock.fields[expectedArg.fieldName].variableType = varType;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Special cases to generate mutations.
|
||||
|
|
|
@ -1201,7 +1201,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'VARIABLE'
|
||||
fieldName: 'VARIABLE',
|
||||
variableType: ''
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1210,7 +1211,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'VARIABLE'
|
||||
fieldName: 'VARIABLE',
|
||||
variableType: ''
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
@ -1224,7 +1226,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'VARIABLE'
|
||||
fieldName: 'VARIABLE',
|
||||
variableType: ''
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
@ -1238,7 +1241,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'VARIABLE'
|
||||
fieldName: 'VARIABLE',
|
||||
variableType: ''
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1247,7 +1251,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'VARIABLE'
|
||||
fieldName: 'VARIABLE',
|
||||
variableType: ''
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1256,7 +1261,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1270,7 +1276,8 @@ const specMap = {
|
|||
},
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1284,7 +1291,8 @@ const specMap = {
|
|||
},
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1303,7 +1311,8 @@ const specMap = {
|
|||
},
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1317,7 +1326,8 @@ const specMap = {
|
|||
},
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
@ -1336,7 +1346,8 @@ const specMap = {
|
|||
},
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1345,7 +1356,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1354,7 +1366,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
@ -1368,7 +1381,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1377,7 +1391,8 @@ const specMap = {
|
|||
argMap: [
|
||||
{
|
||||
type: 'field',
|
||||
fieldName: 'LIST'
|
||||
fieldName: 'LIST',
|
||||
variableType: 'list'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue