Decompilation and minor PR feedback
This commit is contained in:
parent
6a1b560101
commit
a79704fecc
@ -77,16 +77,20 @@ export class FieldSpeed extends Blockly.FieldSlider implements Blockly.FieldCust
|
|||||||
setReadout_(readout: Element, value: string) {
|
setReadout_(readout: Element, value: string) {
|
||||||
this.updateSpeed(parseFloat(value));
|
this.updateSpeed(parseFloat(value));
|
||||||
// Update reporter
|
// Update reporter
|
||||||
this.reporter.textContent = `${value}`;
|
this.reporter.textContent = `${value}%`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateSpeed(speed: number) {
|
private updateSpeed(speed: number) {
|
||||||
speed = Math.abs(speed);
|
let sign = this.sign(speed);
|
||||||
speed = speed / 100 * 50;
|
speed = (Math.abs(speed) / 100 * 50) + 50;
|
||||||
speed += 50;
|
if (sign == -1) speed = 50 - speed;
|
||||||
let c = Math.PI * (90 * 2);
|
let c = Math.PI * (90 * 2);
|
||||||
let pct = ((100 - speed) / 100) * c;
|
let pct = ((100 - speed) / 100) * c;
|
||||||
this.circleBar.setAttribute('stroke-dashoffset', `${pct}`);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace motors {
|
|||||||
*/
|
*/
|
||||||
//% blockId=motorSpeedPicker block="%speed" shim=TD_ID
|
//% blockId=motorSpeedPicker block="%speed" shim=TD_ID
|
||||||
//% speed.fieldEditor="speed" colorSecondary="#FFFFFF"
|
//% speed.fieldEditor="speed" colorSecondary="#FFFFFF"
|
||||||
//% weight=0 blockHidden=1
|
//% weight=0 blockHidden=1 speed.fieldOptions.decompileLiterals=1
|
||||||
export function __speedPicker(speed: number): number {
|
export function __speedPicker(speed: number): number {
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user