From 038a65b460cfa7772b05867c907c24062060fda3 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Mon, 13 Nov 2017 14:24:30 -0500 Subject: [PATCH] Finishing up lists. --- src/engine/adapter.js | 4 +++ src/engine/blocks.js | 11 +++++++- src/serialization/sb2.js | 10 ++++--- src/serialization/sb2_specmap.js | 45 +++++++++++++++++++++----------- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/engine/adapter.js b/src/engine/adapter.js index ffb8d043e..a8534e249 100644 --- a/src/engine/adapter.js +++ b/src/engine/adapter.js @@ -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': diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 7a9ecbb88..bace2f1b5 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -499,11 +499,20 @@ class Blocks { for (const field in block.fields) { if (!block.fields.hasOwnProperty(field)) continue; const blockField = block.fields[field]; + xmlString += `${value}`; + xmlString += `>${value}`; } // Add blocks connected to the next connection. if (block.next) { diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index e76d6ee2b..0c6c37813 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -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. diff --git a/src/serialization/sb2_specmap.js b/src/serialization/sb2_specmap.js index 59200a06f..c7de538e9 100644 --- a/src/serialization/sb2_specmap.js +++ b/src/serialization/sb2_specmap.js @@ -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' } ] },