removing feild editors moved to pxt
This commit is contained in:
		@@ -33,7 +33,7 @@ export function initAsync() {
 | 
				
			|||||||
        canHID = false
 | 
					        canHID = false
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        const forceHexDownload = /forceHexDownload/i.test(window.location.href);
 | 
					        const forceHexDownload = /forceHexDownload/i.test(window.location.href);
 | 
				
			||||||
        if (pxt.Cloud.isLocalHost() && pxt.Cloud.localToken && !forceHexDownload)
 | 
					        if (pxt.BrowserUtils.isLocalHost() && pxt.Cloud.localToken && !forceHexDownload)
 | 
				
			||||||
            canHID = true
 | 
					            canHID = true
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,9 +3,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import { FieldPorts } from "./field_ports";
 | 
					import { FieldPorts } from "./field_ports";
 | 
				
			||||||
import { FieldMotors } from "./field_motors";
 | 
					import { FieldMotors } from "./field_motors";
 | 
				
			||||||
import { FieldSpeed } from "./field_speed";
 | 
					 | 
				
			||||||
import { FieldBrickButtons } from "./field_brickbuttons";
 | 
					import { FieldBrickButtons } from "./field_brickbuttons";
 | 
				
			||||||
import { FieldTurnRatio } from "./field_turnratio";
 | 
					 | 
				
			||||||
import { FieldColorEnum } from "./field_color";
 | 
					import { FieldColorEnum } from "./field_color";
 | 
				
			||||||
import { FieldMusic } from "./field_music";
 | 
					import { FieldMusic } from "./field_music";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,15 +17,9 @@ pxt.editor.initFieldExtensionsAsync = function (opts: pxt.editor.FieldExtensionO
 | 
				
			|||||||
        }, {
 | 
					        }, {
 | 
				
			||||||
            selector: "motors",
 | 
					            selector: "motors",
 | 
				
			||||||
            editor: FieldMotors
 | 
					            editor: FieldMotors
 | 
				
			||||||
        }, {
 | 
					 | 
				
			||||||
            selector: "speed",
 | 
					 | 
				
			||||||
            editor: FieldSpeed
 | 
					 | 
				
			||||||
        }, {
 | 
					        }, {
 | 
				
			||||||
            selector: "brickbuttons",
 | 
					            selector: "brickbuttons",
 | 
				
			||||||
            editor: FieldBrickButtons
 | 
					            editor: FieldBrickButtons
 | 
				
			||||||
        }, {
 | 
					 | 
				
			||||||
            selector: "turnratio",
 | 
					 | 
				
			||||||
            editor: FieldTurnRatio
 | 
					 | 
				
			||||||
        }, {
 | 
					        }, {
 | 
				
			||||||
            selector: "colorenum",
 | 
					            selector: "colorenum",
 | 
				
			||||||
            editor: FieldColorEnum
 | 
					            editor: FieldColorEnum
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -149,9 +149,9 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
 | 
				
			|||||||
    getFirstValueI11n(value: string) {
 | 
					    getFirstValueI11n(value: string) {
 | 
				
			||||||
        const firstValue = this.getFirstValue(value);
 | 
					        const firstValue = this.getFirstValue(value);
 | 
				
			||||||
        const motorOptions = {
 | 
					        const motorOptions = {
 | 
				
			||||||
            'medium motor': lf('medium motor'),
 | 
					            'medium motor': lf("medium motor"),
 | 
				
			||||||
            'large motor': lf('large motor'),
 | 
					            'large motor': lf("large motor"),
 | 
				
			||||||
            'large motors': lf('large motors')
 | 
					            'large motors': lf("large motors")
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return motorOptions[firstValue];
 | 
					        return motorOptions[firstValue];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
 | 
					 | 
				
			||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export interface FieldSpeedOptions extends Blockly.FieldCustomOptions {
 | 
					 | 
				
			||||||
    min?: string;
 | 
					 | 
				
			||||||
    max?: string;
 | 
					 | 
				
			||||||
    label?: string;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export class FieldSpeed extends Blockly.FieldSlider implements Blockly.FieldCustom {
 | 
					 | 
				
			||||||
    public isFieldCustom_ = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private params: any;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private speedSVG: SVGElement;
 | 
					 | 
				
			||||||
    private circleBar: SVGCircleElement;
 | 
					 | 
				
			||||||
    private reporter: SVGTextElement;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Class for a color wheel field.
 | 
					 | 
				
			||||||
     * @param {number|string} value The initial content of the field.
 | 
					 | 
				
			||||||
     * @param {Function=} opt_validator An optional function that is called
 | 
					 | 
				
			||||||
     *     to validate any constraints on what the user entered.  Takes the new
 | 
					 | 
				
			||||||
     *     text as an argument and returns either the accepted text, a replacement
 | 
					 | 
				
			||||||
     *     text, or null to abort the change.
 | 
					 | 
				
			||||||
     * @extends {Blockly.FieldNumber}
 | 
					 | 
				
			||||||
     * @constructor
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    constructor(value_: any, params: FieldSpeedOptions, opt_validator?: Function) {
 | 
					 | 
				
			||||||
        super(String(value_), '-100', '100', null, '10', 'Speed', opt_validator);
 | 
					 | 
				
			||||||
        this.params = params;
 | 
					 | 
				
			||||||
        if (this.params['min']) this.min_ = parseFloat(this.params.min);
 | 
					 | 
				
			||||||
        if (this.params['max']) this.max_ = parseFloat(this.params.max);
 | 
					 | 
				
			||||||
        if (this.params['label']) this.labelText_ = this.params.label;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        (this as any).sliderColor_ = '#a8aaa8';
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    createLabelDom_(labelText: string) {
 | 
					 | 
				
			||||||
        var labelContainer = document.createElement('div');
 | 
					 | 
				
			||||||
        this.speedSVG = document.createElementNS("http://www.w3.org/2000/svg", "svg") as SVGGElement;
 | 
					 | 
				
			||||||
        pxsim.svg.hydrate(this.speedSVG, {
 | 
					 | 
				
			||||||
            viewBox: "0 0 200 100",
 | 
					 | 
				
			||||||
            width: "170"
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        labelContainer.appendChild(this.speedSVG);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const outerCircle = pxsim.svg.child(this.speedSVG, "circle", {
 | 
					 | 
				
			||||||
            'stroke-dasharray': '565.48', 'stroke-dashoffset': '0',
 | 
					 | 
				
			||||||
            'cx': 100, 'cy': 100, 'r': '90', 'style': `fill:transparent; transition: stroke-dashoffset 0.1s linear;`,
 | 
					 | 
				
			||||||
            'stroke': '#a8aaa8', 'stroke-width': '1rem'
 | 
					 | 
				
			||||||
        }) as SVGCircleElement;
 | 
					 | 
				
			||||||
        this.circleBar = pxsim.svg.child(this.speedSVG, "circle", {
 | 
					 | 
				
			||||||
            'stroke-dasharray': '565.48', 'stroke-dashoffset': '0',
 | 
					 | 
				
			||||||
            'cx': 100, 'cy': 100, 'r': '90', 'style': `fill:transparent; transition: stroke-dashoffset 0.1s linear;`,
 | 
					 | 
				
			||||||
            'stroke': '#f12a21', 'stroke-width': '1rem'
 | 
					 | 
				
			||||||
        }) as SVGCircleElement;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.reporter = pxsim.svg.child(this.speedSVG, "text", {
 | 
					 | 
				
			||||||
            'x': 100, 'y': 80,
 | 
					 | 
				
			||||||
            'text-anchor': 'middle', 'dominant-baseline': 'middle',
 | 
					 | 
				
			||||||
            'style': 'font-size: 50px',
 | 
					 | 
				
			||||||
            'class': 'sim-text inverted number'
 | 
					 | 
				
			||||||
        }) as SVGTextElement;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // labelContainer.setAttribute('class', 'blocklyFieldSliderLabel');
 | 
					 | 
				
			||||||
        var readout = document.createElement('span');
 | 
					 | 
				
			||||||
        readout.setAttribute('class', 'blocklyFieldSliderReadout');
 | 
					 | 
				
			||||||
        // var label = document.createElement('span');
 | 
					 | 
				
			||||||
        // label.setAttribute('class', 'blocklyFieldSliderLabelText');
 | 
					 | 
				
			||||||
        // label.innerHTML = labelText;
 | 
					 | 
				
			||||||
        // labelContainer.appendChild(label);
 | 
					 | 
				
			||||||
        // labelContainer.appendChild(readout);
 | 
					 | 
				
			||||||
        return [labelContainer, readout];
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    setReadout_(readout: Element, value: string) {
 | 
					 | 
				
			||||||
        this.updateSpeed(parseFloat(value));
 | 
					 | 
				
			||||||
        // Update reporter
 | 
					 | 
				
			||||||
        this.reporter.textContent = `${value}%`;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private updateSpeed(speed: number) {
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,108 +0,0 @@
 | 
				
			|||||||
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
 | 
					 | 
				
			||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export interface FieldTurnRatioOptions extends Blockly.FieldCustomOptions {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export class FieldTurnRatio extends Blockly.FieldSlider implements Blockly.FieldCustom {
 | 
					 | 
				
			||||||
    public isFieldCustom_ = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private params: any;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private path_: SVGPathElement;
 | 
					 | 
				
			||||||
    private reporter_: SVGTextElement;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Class for a color wheel field.
 | 
					 | 
				
			||||||
     * @param {number|string} value The initial content of the field.
 | 
					 | 
				
			||||||
     * @param {Function=} opt_validator An optional function that is called
 | 
					 | 
				
			||||||
     *     to validate any constraints on what the user entered.  Takes the new
 | 
					 | 
				
			||||||
     *     text as an argument and returns either the accepted text, a replacement
 | 
					 | 
				
			||||||
     *     text, or null to abort the change.
 | 
					 | 
				
			||||||
     * @extends {Blockly.FieldNumber}
 | 
					 | 
				
			||||||
     * @constructor
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    constructor(value_: any, params: FieldTurnRatioOptions, opt_validator?: Function) {
 | 
					 | 
				
			||||||
        super(String(value_), '-100', '100', null, '10', 'TurnRatio', opt_validator);
 | 
					 | 
				
			||||||
        this.params = params;
 | 
					 | 
				
			||||||
        (this as any).sliderColor_ = '#a8aaa8';
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    static HALF = 80;
 | 
					 | 
				
			||||||
    static HANDLE_RADIUS = 30;
 | 
					 | 
				
			||||||
    static RADIUS = FieldTurnRatio.HALF - FieldTurnRatio.HANDLE_RADIUS - 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    createLabelDom_(labelText: string) {
 | 
					 | 
				
			||||||
        let labelContainer = document.createElement('div');
 | 
					 | 
				
			||||||
        let svg = Blockly.utils.createSvgElement('svg', {
 | 
					 | 
				
			||||||
            'xmlns': 'http://www.w3.org/2000/svg',
 | 
					 | 
				
			||||||
            'xmlns:html': 'http://www.w3.org/1999/xhtml',
 | 
					 | 
				
			||||||
            'xmlns:xlink': 'http://www.w3.org/1999/xlink',
 | 
					 | 
				
			||||||
            'version': '1.1',
 | 
					 | 
				
			||||||
            'height': (FieldTurnRatio.HALF + FieldTurnRatio.HANDLE_RADIUS + 10) + 'px',
 | 
					 | 
				
			||||||
            'width': (FieldTurnRatio.HALF * 2) + 'px'
 | 
					 | 
				
			||||||
        }, labelContainer);
 | 
					 | 
				
			||||||
        let defs = Blockly.utils.createSvgElement('defs', {}, svg);
 | 
					 | 
				
			||||||
        let marker = Blockly.utils.createSvgElement('marker', {
 | 
					 | 
				
			||||||
            'id': 'head',
 | 
					 | 
				
			||||||
            'orient': "auto",
 | 
					 | 
				
			||||||
            'markerWidth': '2',
 | 
					 | 
				
			||||||
            'markerHeight': '4',
 | 
					 | 
				
			||||||
            'refX': '0.1', 'refY': '1.5'
 | 
					 | 
				
			||||||
        }, defs);
 | 
					 | 
				
			||||||
        let markerPath = Blockly.utils.createSvgElement('path', {
 | 
					 | 
				
			||||||
            'd': 'M0,0 V3 L1.5,1.5 Z',
 | 
					 | 
				
			||||||
            'fill': '#f12a21'
 | 
					 | 
				
			||||||
        }, marker);
 | 
					 | 
				
			||||||
        this.reporter_ = pxsim.svg.child(svg, "text", {
 | 
					 | 
				
			||||||
            'x': FieldTurnRatio.HALF, 'y': 96,
 | 
					 | 
				
			||||||
            'text-anchor': 'middle', 'dominant-baseline': 'middle',
 | 
					 | 
				
			||||||
            'style': 'font-size: 50px',
 | 
					 | 
				
			||||||
            'class': 'sim-text inverted number'
 | 
					 | 
				
			||||||
        }) as SVGTextElement;
 | 
					 | 
				
			||||||
        this.path_ = Blockly.utils.createSvgElement('path', {
 | 
					 | 
				
			||||||
            'x1': FieldTurnRatio.HALF,
 | 
					 | 
				
			||||||
            'y1': FieldTurnRatio.HALF,
 | 
					 | 
				
			||||||
            'marker-end': 'url(#head)',
 | 
					 | 
				
			||||||
            'style': 'fill: none; stroke: #f12a21; stroke-width: 10'
 | 
					 | 
				
			||||||
        }, svg);
 | 
					 | 
				
			||||||
        this.updateGraph_();
 | 
					 | 
				
			||||||
        let readout = document.createElement('span');
 | 
					 | 
				
			||||||
        readout.setAttribute('class', 'blocklyFieldSliderReadout');
 | 
					 | 
				
			||||||
        return [labelContainer, readout];
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    updateGraph_() {
 | 
					 | 
				
			||||||
        if (!this.path_) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        let v = goog.math.clamp(parseFloat(this.getText()), -100, 100);
 | 
					 | 
				
			||||||
        if (isNaN(v)) {
 | 
					 | 
				
			||||||
            v = 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const x = goog.math.clamp(parseFloat(this.getText()), -100, 100) / 100;
 | 
					 | 
				
			||||||
        const theta = x * Math.PI / 2;
 | 
					 | 
				
			||||||
        const cx = FieldTurnRatio.HALF;
 | 
					 | 
				
			||||||
        const cy = FieldTurnRatio.HALF - 14;
 | 
					 | 
				
			||||||
        const gamma = Math.PI - 2 * theta;
 | 
					 | 
				
			||||||
        const r = FieldTurnRatio.RADIUS;
 | 
					 | 
				
			||||||
        const alpha = 0.2 + Math.abs(x) * 0.5;
 | 
					 | 
				
			||||||
        const x1 = 0;
 | 
					 | 
				
			||||||
        const y1 = r * alpha;
 | 
					 | 
				
			||||||
        const y2 = r * Math.sin(Math.PI / 2 - theta);
 | 
					 | 
				
			||||||
        const x2 = r * Math.cos(Math.PI / 2 - theta);
 | 
					 | 
				
			||||||
        const y3 = y2 - r * alpha * Math.cos(2 * theta);
 | 
					 | 
				
			||||||
        const x3 = x2 - r * alpha * Math.sin(2 * theta);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const d = `M ${cx} ${cy} C ${cx} ${cy - y1} ${cx + x3} ${cy - y3} ${cx + x2} ${cy - y2}`;
 | 
					 | 
				
			||||||
        this.path_.setAttribute('d', d);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.reporter_.textContent = `${v}`;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    setReadout_(readout: Element, value: string) {
 | 
					 | 
				
			||||||
        this.updateGraph_();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -5,6 +5,7 @@
 | 
				
			|||||||
namespace pxsim {
 | 
					namespace pxsim {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export class EV3Board extends CoreBoard {
 | 
					    export class EV3Board extends CoreBoard {
 | 
				
			||||||
 | 
					        viewHost: visuals.BoardHost;
 | 
				
			||||||
        view: SVGSVGElement;
 | 
					        view: SVGSVGElement;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        outputState: EV3OutputState;
 | 
					        outputState: EV3OutputState;
 | 
				
			||||||
@@ -83,15 +84,16 @@ namespace pxsim {
 | 
				
			|||||||
                highContrast: msg.highContrast,
 | 
					                highContrast: msg.highContrast,
 | 
				
			||||||
                light: msg.light
 | 
					                light: msg.light
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({
 | 
					            this.viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView(<pxsim.visuals.BoardViewOptions>{
 | 
				
			||||||
                visual: boardDef.visual,
 | 
					                visual: boardDef.visual,
 | 
				
			||||||
 | 
					                boardDef,
 | 
				
			||||||
                highContrast: msg.highContrast,
 | 
					                highContrast: msg.highContrast,
 | 
				
			||||||
                light: msg.light
 | 
					                light: msg.light
 | 
				
			||||||
            }), opts);
 | 
					            }), opts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            document.body.innerHTML = ""; // clear children
 | 
					            document.body.innerHTML = ""; // clear children
 | 
				
			||||||
            document.body.className = msg.light ? "light" : "";
 | 
					            document.body.className = msg.light ? "light" : "";
 | 
				
			||||||
            document.body.appendChild(this.view = viewHost.getView() as SVGSVGElement);
 | 
					            document.body.appendChild(this.view = this.viewHost.getView() as SVGSVGElement);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.inputNodes = [];
 | 
					            this.inputNodes = [];
 | 
				
			||||||
            this.outputNodes = [];
 | 
					            this.outputNodes = [];
 | 
				
			||||||
@@ -102,8 +104,8 @@ namespace pxsim {
 | 
				
			|||||||
            return Promise.resolve();
 | 
					            return Promise.resolve();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        screenshot(): string {
 | 
					        screenshotAsync(width?: number): Promise<ImageData> {
 | 
				
			||||||
            return svg.toDataUri(new XMLSerializer().serializeToString(this.view));
 | 
					            return this.viewHost.screenshotAsync(width);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        getBrickNode() {
 | 
					        getBrickNode() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user