From 2a42285abef677360e28e8e128b304b51f1aba18 Mon Sep 17 00:00:00 2001 From: DD Liu Date: Thu, 19 Mar 2020 12:40:55 -0400 Subject: [PATCH] Revert "Consistently format text bubbles" This reverts commit bc61e547b59dedfb0998771690fd3e1b75dc3208. --- src/blocks/scratch3_looks.js | 31 ++++++++----------------------- test/unit/blocks_looks.js | 15 ++++++--------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 762cfa6ec..a6da97f35 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -233,26 +233,6 @@ class Scratch3LooksBlocks { this._positionBubble(target); } - /** - * Properly format text for a text bubble. - * @param {string} text The text to be formatted - * @return {string} The formatted text - * @private - */ - _formatBubbleText (text) { - if (text === '') return text; - - // Limit decimal precision to 2 digits. - if (typeof text === 'number') { - text = parseFloat(text.toFixed(2)); - } - - // Limit the length of the string. - text = String(text).substr(0, Scratch3LooksBlocks.SAY_BUBBLE_LIMIT); - - return text; - } - /** * The entry point for say/think blocks. Clears existing bubble if the text is empty. * Set the bubble custom state and then call _renderBubble. @@ -264,7 +244,7 @@ class Scratch3LooksBlocks { _updateBubble (target, type, text) { const bubbleState = this._getBubbleState(target); bubbleState.type = type; - bubbleState.text = this._formatBubbleText(text); + bubbleState.text = text; bubbleState.usageId = uid(); this._renderBubble(target); } @@ -320,7 +300,12 @@ class Scratch3LooksBlocks { say (args, util) { // @TODO in 2.0 calling say/think resets the right/left bias of the bubble - this.runtime.emit('SAY', util.target, 'say', args.MESSAGE); + let message = args.MESSAGE; + if (typeof message === 'number') { + message = parseFloat(message.toFixed(2)); + } + message = String(message).substr(0, Scratch3LooksBlocks.SAY_BUBBLE_LIMIT); + this.runtime.emit('SAY', util.target, 'say', message); } sayforsecs (args, util) { @@ -340,7 +325,7 @@ class Scratch3LooksBlocks { } think (args, util) { - this.runtime.emit('SAY', util.target, 'think', args.MESSAGE); + this._updateBubble(util.target, 'think', String(args.MESSAGE).substr(0, Scratch3LooksBlocks.SAY_BUBBLE_LIMIT)); } thinkforsecs (args, util) { diff --git a/test/unit/blocks_looks.js b/test/unit/blocks_looks.js index 487112ff2..599e7e49a 100644 --- a/test/unit/blocks_looks.js +++ b/test/unit/blocks_looks.js @@ -15,9 +15,7 @@ const util = { {name: 'second name'}, {name: 'third name'} ] - }, - _customState: {}, - getCustomState: () => util.target._customState + } } }; @@ -204,15 +202,14 @@ test('numbers should be rounded to two decimals in say', t => { const args = {MESSAGE: 3.14159}; const expectedSayString = '3.14'; - rt.addListener('SAY', () => { - const bubbleState = util.target.getCustomState(Looks.STATE_KEY); - t.strictEqual(bubbleState.text, expectedSayString); + rt.removeAllListeners('SAY'); // Prevent say blocks from executing + + rt.addListener('SAY', (target, type, sayString) => { + t.strictEqual(sayString, expectedSayString); + t.end(); }); looks.say(args, util); - looks.think(args, util); - - t.end(); }); test('clamp graphic effects', t => {