Skip to content
Snippets Groups Projects
Commit d5805985 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Add dynamic labelling

parent 188a92e6
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ const styles = require('./monitor.css');
const categories = {
data: '#FF8C1A',
sensing: '#5CB1D6',
sounds: '#CF63CF',
sound: '#CF63CF',
looks: '#9966FF',
motion: '#4C97FF'
};
......
......@@ -12,15 +12,18 @@ const MONITOR_HEIGHT = 23;
const isUndefined = a => typeof a === 'undefined';
module.exports = function ({id, opcode, value, x, y}, monitorIndex) {
// Look up category and label from opcode label file
module.exports = function ({id, opcode, params, value, x, y}, monitorIndex) {
let opcodeData = OpcodeLabels[opcode];
if (isUndefined(opcodeData)) {
log.error(`No category/label found for opcode: ${opcode}`);
log.error(`No data found for opcode: ${opcode}`);
opcodeData = {category: 'data', label: opcode};
}
const {label, category} = opcodeData;
// Use labelFn with fields if provided for dynamic labelling (e.g. variables)
let {label, category, labelFn} = opcodeData;
if (!isUndefined(labelFn)) {
label = labelFn(params);
}
// Simple layout if x or y are undefined
// @todo scratch2 has a more complex layout behavior we may want to adopt
......
......@@ -34,7 +34,7 @@ module.exports = {
// Data
data_variable: {
category: 'data',
label: 'Variable _' // @todo placeholder for params
labelFn: params => params.VARIABLE
},
// Sound
......@@ -50,18 +50,18 @@ module.exports = {
// Sensing
sensing_loudness: {
category: 'sensing',
label: 'loundness'
label: 'loudness'
},
sensing_of: {
category: 'sensing',
label: '_ of _' // @todo placeholder for params
labelFn: params => `${params.PROPERTY} of ${params.OBJECT}`
},
sensing_current: {
category: 'sensing',
label: 'current _' // @todo placeholder for param
labelFn: params => params.CURRENTMENU.toLowerCase()
},
sensing_timer: {
category: 'timer',
category: 'sensing',
label: 'timer'
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment