Explain when it's OK to omit <field> element

Also, alphabetize the `ArgumentType` and `BlockType` enums.
This commit is contained in:
Christopher Willis-Ford 2017-10-02 15:29:32 -07:00
parent 772da24d9e
commit 99b868c0f0
3 changed files with 13 additions and 6 deletions

View file

@ -459,10 +459,17 @@ class Runtime extends EventEmitter {
const argInfo = blockInfo.arguments[placeholder] || {};
const argTypeInfo = ArgumentTypeMap[argInfo.type] || {};
const defaultValue = (typeof argInfo.defaultValue === 'undefined' ? '' : argInfo.defaultValue.toString());
// <value> is the ScratchBlocks name for a block input.
// The <shadow> is a placeholder for a reporter and is visible when there's no reporter in this input.
inputList.push(`<value name="${placeholder}"><shadow type="${argTypeInfo.shadowType}">`);
// <field> is a text field that the user can type into. Some shadows, like the color picker, don't allow
// text input and therefore don't need a field element.
if (argTypeInfo.fieldType) {
inputList.push(`<field name="${argTypeInfo.fieldType}">${defaultValue}</field>`);
}
inputList.push('</shadow></value>');
return `%${argNum}`;

View file

@ -1,8 +1,8 @@
const ArgumentType = {
NUMBER: 'number',
STRING: 'string',
BOOLEAN: 'Boolean',
COLOR: 'color'
COLOR: 'color',
NUMBER: 'number',
STRING: 'string'
};
module.exports = ArgumentType;

View file

@ -1,9 +1,9 @@
const BlockType = {
COMMAND: 'command',
REPORTER: 'reporter',
BOOLEAN: 'Boolean',
COMMAND: 'command',
CONDITIONAL: 'conditional',
HAT: 'hat',
CONDITIONAL: 'conditional'
REPORTER: 'reporter'
};
module.exports = BlockType;