Finishing up lists.

This commit is contained in:
Karishma Chadha 2017-11-13 14:24:30 -05:00
parent b18938963f
commit 038a65b460
4 changed files with 51 additions and 19 deletions

View file

@ -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':

View file

@ -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) {

View file

@ -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.

View file

@ -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'
}
]
},