From 50f6b04ed4dfb6836fbe67098af59661627e4a60 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Fri, 5 Jan 2018 17:35:25 -0800 Subject: [PATCH] Re-implement Math.sign so it works on IE 11 (not supported). Square shaped corners for Flyout --- editor/extension.ts | 16 +++++++++++++++- sim/state/motornode.ts | 9 ++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/editor/extension.ts b/editor/extension.ts index 969eeb85..90055b3a 100644 --- a/editor/extension.ts +++ b/editor/extension.ts @@ -5,7 +5,7 @@ import { deployCoreAsync, initAsync } from "./deploy"; import { FieldPorts } from "./field_ports"; import { FieldImages } from "./field_images"; -pxt.editor.initExtensionsAsync = function(opts: pxt.editor.ExtensionOptions): Promise { +pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise { pxt.debug('loading pxt-ev3 target extensions...') updateBlocklyShape(); const res: pxt.editor.ExtensionResult = { @@ -111,6 +111,20 @@ function updateBlocklyShape() { 'l ' + 0 + ',' + (Blockly.BlockSvg as any).CORNER_RADIUS * 2 + 'l ' + (Blockly.BlockSvg as any).CORNER_RADIUS + ',' + 0; + /** + * Corner radius of the flyout background. + * @type {number} + * @const + */ + (Blockly as any).Flyout.prototype.CORNER_RADIUS = 0; + + /** + * Margin around the edges of the blocks in the flyout. + * @type {number} + * @const + */ + (Blockly as any).Flyout.prototype.MARGIN = 8; + } // When require()d from node, bind the global pxt namespace diff --git a/sim/state/motornode.ts b/sim/state/motornode.ts index c89ae1e0..0a28b1c7 100644 --- a/sim/state/motornode.ts +++ b/sim/state/motornode.ts @@ -176,8 +176,15 @@ namespace pxsim { // let it coast to speed 0 if (this.speed && !(this.started || this.speedCmd)) { // decay speed 5% per tick - this.speed = Math.round(Math.max(0, Math.abs(this.speed) - 10) * Math.sign(this.speed)); + this.speed = Math.round(Math.max(0, Math.abs(this.speed) - 10) * sign(this.speed)); } } } +} + +namespace pxsim { + // A re-implementation of Math.sign (since IE11 doesn't support it) + export function sign(num: number) { + return num ? num < 0 ? -1 : 1 : 0; + } } \ No newline at end of file