Spaces:
Running
Running
File size: 19,706 Bytes
6bcb42f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
import {defineMessages} from 'react-intl';
const messages = defineMessages({
motion_direction: {
defaultMessage: 'direction',
description: 'Label for the direction monitor when shown on the stage',
id: 'gui.opcodeLabels.direction'
},
motion_xposition: {
defaultMessage: 'x position',
description: 'Label for the x position monitor when shown on the stage',
id: 'gui.opcodeLabels.xposition'
},
motion_yposition: {
defaultMessage: 'y position',
description: 'Label for the y position monitor when shown on the stage',
id: 'gui.opcodeLabels.yposition'
},
// Looks
looks_size: {
defaultMessage: 'size',
description: 'Label for the size monitor when shown on the stage',
id: 'gui.opcodeLabels.size'
},
looks_costumename: {
defaultMessage: 'costume name',
description: 'Label for the costume name monitor when shown on the stage',
id: 'gui.opcodeLabels.costumename'
},
looks_costumenumber: {
defaultMessage: 'costume number',
description: 'Label for the costume number monitor when shown on the stage',
id: 'gui.opcodeLabels.costumenumber'
},
looks_backdropname: {
defaultMessage: 'backdrop name',
description: 'Label for the backdrop name monitor when shown on the stage',
id: 'gui.opcodeLabels.backdropname'
},
looks_backdropnumber: {
defaultMessage: 'backdrop number',
description: 'Label for the backdrop number monitor when shown on the stage',
id: 'gui.opcodeLabels.backdropnumber'
},
looks_stretchGetX: {
defaultMessage: 'stretch x',
description: 'Label for the stretch x monitor when shown on the stage',
id: 'gui.opcodeLabels.stretchGetX'
},
looks_stretchGetY: {
defaultMessage: 'stretch y',
description: 'Label for the stretch y monitor when shown on the stage',
id: 'gui.opcodeLabels.stretchGetY'
},
looks_sayWidth: {
defaultMessage: 'bubble width',
description: 'Label for the bubble width monitor when shown on the stage',
id: 'gui.opcodeLabels.sayWidth'
},
looks_sayHeight: {
defaultMessage: 'bubble height',
description: 'Label for the bubble height monitor when shown on the stage',
id: 'gui.opcodeLabels.sayHeight'
},
looks_getEffectValue: {
defaultMessage: 'effect',
description: 'Label for the effect monitor with no effect chosen when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue'
},
looks_getEffectValue_color: {
defaultMessage: 'color effect',
description: 'Label for the color effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.color'
},
looks_getEffectValue_fisheye: {
defaultMessage: 'fisheye effect',
description: 'Label for the fisheye effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.fisheye'
},
looks_getEffectValue_whirl: {
defaultMessage: 'whirl effect',
description: 'Label for the whirl effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.whirl'
},
looks_getEffectValue_pixelate: {
defaultMessage: 'pixelate effect',
description: 'Label for the pixelate effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.pixelate'
},
looks_getEffectValue_mosaic: {
defaultMessage: 'mosaic effect',
description: 'Label for the mosaic effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.mosaic'
},
looks_getEffectValue_brightness: {
defaultMessage: 'brightness effect',
description: 'Label for the brightness effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.brightness'
},
looks_getEffectValue_ghost: {
defaultMessage: 'ghost effect',
description: 'Label for the ghost effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.ghost'
},
looks_getEffectValue_saturation: {
defaultMessage: 'saturation effect',
description: 'Label for the saturation effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.saturation'
},
looks_getEffectValue_red: {
defaultMessage: 'red effect',
description: 'Label for the red effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.red'
},
looks_getEffectValue_green: {
defaultMessage: 'green effect',
description: 'Label for the green effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.green'
},
looks_getEffectValue_blue: {
defaultMessage: 'blue effect',
description: 'Label for the blue effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.blue'
},
looks_getEffectValue_opaque: {
defaultMessage: 'opaque effect',
description: 'Label for the opaque effect monitor when shown on the stage',
id: 'gui.opcodeLabels.getEffectValue.opaque'
},
looks_tintColor: {
defaultMessage: 'tint color',
description: 'Label for the tint color monitor when shown on the stage',
id: 'gui.opcodeLabels.tintColor'
},
looks_getSpriteVisible: {
defaultMessage: 'visible?',
description: 'Label for the visible monitor when shown on the stage',
id: 'gui.opcodeLabels.getSpriteVisible'
},
looks_layersGetLayer: {
defaultMessage: 'layer',
description: 'Label for the layer monitor when shown on the stage',
id: 'gui.opcodeLabels.layersGetLayer'
},
// Sound
sound_volume: {
defaultMessage: 'volume',
description: 'Label for the volume monitor when shown on the stage',
id: 'gui.opcodeLabels.volume'
},
sound_getEffectValue: {
defaultMessage: 'effect',
description: 'Label for the sound effect monitor with no effect chosen when shown on the stage',
id: 'gui.opcodeLabels.soundgetEffectValue'
},
sound_getEffectValue_pitch: {
defaultMessage: 'pitch',
description: 'Label for the pitch effect monitor when shown on the stage',
id: 'gui.opcodeLabels.soundgetEffectValue.pitch'
},
sound_getEffectValue_pan: {
defaultMessage: 'pan left/right',
description: 'Label for the pan left/right effect monitor when shown on the stage',
id: 'gui.opcodeLabels.soundgetEffectValue.pan'
},
sound_tempo: {
defaultMessage: 'tempo',
description: 'Label for the tempo monitor when shown on the stage',
id: 'gui.opcodeLabels.tempo'
},
// Sensing
sensing_answer: {
defaultMessage: 'answer',
description: 'Label for the answer monitor when shown on the stage',
id: 'gui.opcodeLabels.answer'
},
sensing_loudness: {
defaultMessage: 'loudness',
description: 'Label for the loudness monitor when shown on the stage',
id: 'gui.opcodeLabels.loudness'
},
sensing_username: {
defaultMessage: 'username',
description: 'Label for the username monitor when shown on the stage',
id: 'gui.opcodeLabels.username'
},
sensing_current_year: {
defaultMessage: 'year',
description: 'Label for the current year monitor when shown on the stage',
id: 'gui.opcodeLabels.year'
},
sensing_current_month: {
defaultMessage: 'month',
description: 'Label for the current month monitor when shown on the stage.',
id: 'gui.opcodeLabels.month'
},
sensing_current_date: {
defaultMessage: 'date',
description: 'Label for the current date monitor when shown on the stage. Shows the current day of the month',
id: 'gui.opcodeLabels.date'
},
sensing_current_dayofweek: {
defaultMessage: 'day of week',
description: 'Label for the current day of week monitor when shown on the stage',
id: 'gui.opcodeLabels.dayofweek'
},
sensing_current_hour: {
defaultMessage: 'hour',
description: 'Label for the current hour monitor when shown on the stage',
id: 'gui.opcodeLabels.hour'
},
sensing_current_minute: {
defaultMessage: 'minute',
description: 'Label for the current minute monitor when shown on the stage',
id: 'gui.opcodeLabels.minute'
},
sensing_current_second: {
defaultMessage: 'second',
description: 'Label for the current second monitor when shown on the stage',
id: 'gui.opcodeLabels.second'
},
sensing_timer: {
defaultMessage: 'timer',
description: 'Label for the timer monitor when shown on the stage',
id: 'gui.opcodeLabels.timer'
},
sensing_mousedown: {
defaultMessage: 'mouse down?',
description: 'Label for the mouse down monitor when shown on the stage',
id: 'gui.opcodeLabels.mousedown'
},
sensing_mouseclicked: {
defaultMessage: 'mouse clicked?',
description: 'Label for the mouse clicked monitor when shown on the stage',
id: 'gui.opcodeLabels.mouseclicked'
},
sensing_mousex: {
defaultMessage: 'mouse x',
description: 'Label for the mouse x monitor when shown on the stage',
id: 'gui.opcodeLabels.mousex'
},
sensing_mousey: {
defaultMessage: 'mouse y',
description: 'Label for the mouse y monitor when shown on the stage',
id: 'gui.opcodeLabels.mousey'
},
sensing_getclipboard: {
defaultMessage: 'clipboard item',
description: 'Label for the clipboard item monitor when shown on the stage',
id: 'gui.opcodeLabels.getclipboard'
},
sensing_getdragmode: {
defaultMessage: 'draggable?',
description: 'Label for the draggable monitor when shown on the stage',
id: 'gui.opcodeLabels.getdragmode'
},
sensing_loud: {
defaultMessage: 'loud?',
description: 'Label for the loud monitor when shown on the stage',
id: 'gui.opcodeLabels.loud'
},
sensing_dayssince2000: {
defaultMessage: 'days since 2000',
description: 'Label for the days since 2000 monitor when shown on the stage',
id: 'gui.opcodeLabels.dayssince2000'
},
sensing_loggedin: {
defaultMessage: 'logged in?',
description: 'Label for the logged in monitor when shown on the stage',
id: 'gui.opcodeLabels.loggedin'
},
// Control
control_get_counter: {
defaultMessage: 'counter',
description: 'Label for the counter monitor when shown on the stage',
id: 'gui.opcodeLabels.counter'
}
});
class OpcodeLabels {
constructor () {
/**
* Translation function for labels. By default just return the defaultMessage
* @private
* @param {object} message A message object compatible with react-intl formatMessage
* @return {string} Return the default string initially
*/
this._translator = message => message.defaultMessage;
/**
* Initial opcode map, with categories defined
* @private
*/
this._opcodeMap = {
// Motion
motion_direction: {category: 'motion'},
motion_xposition: {category: 'motion'},
motion_yposition: {category: 'motion'},
// Looks
looks_size: {category: 'looks'},
looks_costumenumbername: {category: 'looks'},
looks_backdropnumbername: {category: 'looks'},
looks_backdropname: {category: 'looks'},
looks_stretchGetX: {category: 'looks'},
looks_stretchGetY: {category: 'looks'},
looks_sayWidth: {category: 'looks'},
looks_sayHeight: {category: 'looks'},
looks_getEffectValue: {category: 'looks'},
looks_tintColor: {category: 'looks'},
looks_getSpriteVisible: {category: 'looks'},
looks_layersGetLayer: {category: 'looks'},
// Data
data_variable: {category: 'data'},
data_listcontents: {category: 'list'},
// Sound
sound_volume: {category: 'sound'},
sound_getEffectValue: {category: 'sound'},
sound_tempo: {category: 'sound'},
// Sensing
sensing_answer: {category: 'sensing'},
sensing_loudness: {category: 'sensing'},
sensing_username: {category: 'sensing'},
sensing_current: {category: 'sensing'},
sensing_timer: {category: 'sensing'},
sensing_mousedown: {category: 'sensing'},
sensing_mouseclicked: {category: 'sensing'},
sensing_mousex: {category: 'sensing'},
sensing_mousey: {category: 'sensing'},
sensing_getclipboard: {category: 'sensing'},
sensing_getdragmode: {category: 'sensing'},
sensing_loud: {category: 'sensing'},
sensing_dayssince2000: {category: 'sensing'},
sensing_loggedin: {category: 'sensing'},
// Control
control_get_counter: {category: 'control'}
};
// Initialize opcodeMap with default strings
this._refreshOpcodeMap();
}
/**
* Set the translation function for monitor labels. The function should accept
* a message object as defined by react-intl defineMessages
* @param {function} translator the function to use for localization
*/
setTranslatorFunction (translator) {
this._translator = translator;
this._refreshOpcodeMap();
}
/**
* Internal function to update opcode Map when translation function is defined
* @private
*/
_refreshOpcodeMap () {
// Motion
this._opcodeMap.motion_direction.labelFn = () => this._translator(messages.motion_direction);
this._opcodeMap.motion_xposition.labelFn = () => this._translator(messages.motion_xposition);
this._opcodeMap.motion_yposition.labelFn = () => this._translator(messages.motion_yposition);
// Looks
this._opcodeMap.looks_size.labelFn = () => this._translator(messages.looks_size);
this._opcodeMap.looks_stretchGetX.labelFn = () => this._translator(messages.looks_stretchGetX);
this._opcodeMap.looks_stretchGetY.labelFn = () => this._translator(messages.looks_stretchGetY);
this._opcodeMap.looks_sayWidth.labelFn = () => this._translator(messages.looks_sayWidth);
this._opcodeMap.looks_sayHeight.labelFn = () => this._translator(messages.looks_sayHeight);
this._opcodeMap.looks_getEffectValue.labelFn = params => {
const effect = params.EFFECT.toLowerCase();
if (messages[`looks_getEffectValue_${effect}`]) {
return this._translator(messages[`looks_getEffectValue_${effect}`]);
}
return this._translator(messages.looks_getEffectValue);
};
this._opcodeMap.looks_tintColor.labelFn = () => this._translator(messages.looks_tintColor);
this._opcodeMap.looks_getSpriteVisible.labelFn = () => this._translator(messages.looks_getSpriteVisible);
this._opcodeMap.looks_layersGetLayer.labelFn = () => this._translator(messages.looks_layersGetLayer);
this._opcodeMap.looks_costumenumbername.labelFn = params => {
if (params.NUMBER_NAME === 'number') {
return this._translator(messages.looks_costumenumber);
}
return this._translator(messages.looks_costumename);
};
this._opcodeMap.looks_backdropnumbername.labelFn = params => {
if (params.NUMBER_NAME === 'number') {
return this._translator(messages.looks_backdropnumber);
}
return this._translator(messages.looks_backdropname);
};
this._opcodeMap.looks_backdropname.labelFn = () => this._translator(messages.looks_backdropname);
// Data
this._opcodeMap.data_variable.labelFn = params => params.VARIABLE;
this._opcodeMap.data_listcontents.labelFn = params => params.LIST;
// Sound
this._opcodeMap.sound_volume.labelFn = () => this._translator(messages.sound_volume);
this._opcodeMap.sound_tempo.labelFn = () => this._translator(messages.sound_tempo);
this._opcodeMap.sound_getEffectValue.labelFn = params => {
const effect = params.EFFECT.toLowerCase();
if (messages[`sound_getEffectValue_${effect}`]) {
return this._translator(messages[`sound_getEffectValue_${effect}`]);
}
return this._translator(messages.sound_getEffectValue);
};
// Sensing
this._opcodeMap.sensing_answer.labelFn = () => this._translator(messages.sensing_answer);
this._opcodeMap.sensing_loudness.labelFn = () => this._translator(messages.sensing_loudness);
this._opcodeMap.sensing_username.labelFn = () => this._translator(messages.sensing_username);
this._opcodeMap.sensing_current.labelFn = params => {
switch (params.CURRENTMENU.toLowerCase()) {
case 'year':
return this._translator(messages.sensing_current_year);
case 'month':
return this._translator(messages.sensing_current_month);
case 'date':
return this._translator(messages.sensing_current_date);
case 'dayofweek':
return this._translator(messages.sensing_current_dayofweek);
case 'hour':
return this._translator(messages.sensing_current_hour);
case 'minute':
return this._translator(messages.sensing_current_minute);
case 'second':
return this._translator(messages.sensing_current_second);
}
};
this._opcodeMap.sensing_timer.labelFn = () => this._translator(messages.sensing_timer);
this._opcodeMap.sensing_mousedown.labelFn = () => this._translator(messages.sensing_mousedown);
this._opcodeMap.sensing_mouseclicked.labelFn = () => this._translator(messages.sensing_mouseclicked);
this._opcodeMap.sensing_mousex.labelFn = () => this._translator(messages.sensing_mousex);
this._opcodeMap.sensing_mousey.labelFn = () => this._translator(messages.sensing_mousey);
this._opcodeMap.sensing_getclipboard.labelFn = () => this._translator(messages.sensing_getclipboard);
this._opcodeMap.sensing_getdragmode.labelFn = () => this._translator(messages.sensing_getdragmode);
this._opcodeMap.sensing_loud.labelFn = () => this._translator(messages.sensing_loud);
this._opcodeMap.sensing_dayssince2000.labelFn = () => this._translator(messages.sensing_dayssince2000);
this._opcodeMap.sensing_loggedin.labelFn = () => this._translator(messages.sensing_loggedin);
// Control
this._opcodeMap.control_get_counter.labelFn = () => this._translator(messages.control_get_counter);
}
/**
* Return the label for an opcode
* @param {string} opcode the opcode you want a label for
* @return {object} object with label and category
*/
getLabel (opcode) {
if (opcode in this._opcodeMap) return this._opcodeMap[opcode];
return {
category: 'extension',
label: opcode
};
}
}
export default new OpcodeLabels();
|