Merge pull request from kchadha/list-typed-variable

List typed variable
This commit is contained in:
Paul Kaplan 2017-11-15 12:48:56 -05:00 committed by GitHub
commit 1e27d21b15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 194 additions and 105 deletions

View file

@ -13,7 +13,6 @@ const log = require('../util/log');
const uid = require('../util/uid');
const specMap = require('./sb2_specmap');
const Variable = require('../engine/variable');
const List = require('../engine/list');
const {loadCostume} = require('../import/load-costume.js');
const {loadSound} = require('../import/load-sound.js');
@ -235,9 +234,10 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
const newVariable = new Variable(
getVariableId(variable.name),
variable.name,
variable.value,
Variable.SCALAR_TYPE,
variable.isPersistent
);
newVariable.value = variable.value;
target.variables[newVariable.id] = newVariable;
}
}
@ -251,10 +251,14 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
for (let k = 0; k < object.lists.length; k++) {
const list = object.lists[k];
// @todo: monitor properties.
target.lists[list.listName] = new List(
const newVariable = new Variable(
getVariableId(list.listName),
list.listName,
list.contents
Variable.LIST_TYPE,
false
);
newVariable.value = list.contents;
target.variables[newVariable.id] = newVariable;
}
}
if (object.hasOwnProperty('scratchX')) {
@ -486,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

@ -22,6 +22,8 @@
* Finally, I filled in the expected arguments as below.
*/
const Variable = require('../engine/variable');
/**
* @typedef {object} SB2SpecMap_blockInfo
* @property {string} opcode - the Scratch 3.0 block opcode. Use 'extensionID.opcode' for extension opcodes.
@ -1201,7 +1203,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'VARIABLE'
fieldName: 'VARIABLE',
variableType: Variable.SCALAR_TYPE
}
]
},
@ -1210,7 +1213,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'VARIABLE'
fieldName: 'VARIABLE',
variableType: Variable.SCALAR_TYPE
},
{
type: 'input',
@ -1224,7 +1228,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'VARIABLE'
fieldName: 'VARIABLE',
variableType: Variable.SCALAR_TYPE
},
{
type: 'input',
@ -1238,7 +1243,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'VARIABLE'
fieldName: 'VARIABLE',
variableType: Variable.SCALAR_TYPE
}
]
},
@ -1247,16 +1253,18 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'VARIABLE'
fieldName: 'VARIABLE',
variableType: Variable.SCALAR_TYPE
}
]
},
'contentsOfList:': {
opcode: 'data_list',
opcode: 'data_listcontents',
argMap: [
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1270,7 +1278,8 @@ const specMap = {
},
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1284,7 +1293,8 @@ const specMap = {
},
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1303,7 +1313,8 @@ const specMap = {
},
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1317,7 +1328,8 @@ const specMap = {
},
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
},
{
type: 'input',
@ -1336,7 +1348,8 @@ const specMap = {
},
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1345,7 +1358,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1354,7 +1368,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
},
{
type: 'input',
@ -1368,7 +1383,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},
@ -1377,7 +1393,8 @@ const specMap = {
argMap: [
{
type: 'field',
fieldName: 'LIST'
fieldName: 'LIST',
variableType: Variable.LIST_TYPE
}
]
},

View file

@ -8,7 +8,6 @@ const vmPackage = require('../../package.json');
const Blocks = require('../engine/blocks');
const Sprite = require('../sprites/sprite');
const Variable = require('../engine/variable');
const List = require('../engine/list');
const {loadCostume} = require('../import/load-costume.js');
const {loadSound} = require('../import/load-sound.js');
@ -125,22 +124,13 @@ const parseScratchObject = function (object, runtime, extensions) {
const newVariable = new Variable(
variable.id,
variable.name,
variable.value,
variable.type,
variable.isPersistent
);
newVariable.value = variable.value;
target.variables[newVariable.id] = newVariable;
}
}
if (object.hasOwnProperty('lists')) {
for (let k = 0; k < object.lists.length; k++) {
const list = object.lists[k];
// @todo: monitor properties.
target.lists[list.listName] = new List(
list.listName,
list.contents
);
}
}
if (object.hasOwnProperty('x')) {
target.x = object.x;
}