Decompilation and minor PR feedback

This commit is contained in:
Sam El-Husseini 2018-01-06 17:16:08 -08:00
parent 6a1b560101
commit a79704fecc
2 changed files with 9 additions and 5 deletions

View File

@ -77,16 +77,20 @@ export class FieldSpeed extends Blockly.FieldSlider implements Blockly.FieldCust
setReadout_(readout: Element, value: string) {
this.updateSpeed(parseFloat(value));
// Update reporter
this.reporter.textContent = `${value}`;
this.reporter.textContent = `${value}%`;
}
private updateSpeed(speed: number) {
speed = Math.abs(speed);
speed = speed / 100 * 50;
speed += 50;
let sign = this.sign(speed);
speed = (Math.abs(speed) / 100 * 50) + 50;
if (sign == -1) speed = 50 - speed;
let c = Math.PI * (90 * 2);
let pct = ((100 - speed) / 100) * c;
this.circleBar.setAttribute('stroke-dashoffset', `${pct}`);
}
// A re-implementation of Math.sign (since IE11 doesn't support it)
private sign(num: number) {
return num ? num < 0 ? -1 : 1 : 0;
}
}

View File

@ -7,7 +7,7 @@ namespace motors {
*/
//% blockId=motorSpeedPicker block="%speed" shim=TD_ID
//% speed.fieldEditor="speed" colorSecondary="#FFFFFF"
//% weight=0 blockHidden=1
//% weight=0 blockHidden=1 speed.fieldOptions.decompileLiterals=1
export function __speedPicker(speed: number): number {
return speed;
}