2018-01-04 01:18:39 +01:00
|
|
|
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts"/>
|
|
|
|
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
|
|
|
|
|
|
|
import { deployCoreAsync, initAsync } from "./deploy";
|
|
|
|
import { FieldPorts } from "./field_ports";
|
2018-01-04 02:20:35 +01:00
|
|
|
import { FieldImages } from "./field_images";
|
2018-01-04 01:18:39 +01:00
|
|
|
|
2018-01-06 02:35:25 +01:00
|
|
|
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
|
2018-01-04 01:18:39 +01:00
|
|
|
pxt.debug('loading pxt-ev3 target extensions...')
|
|
|
|
updateBlocklyShape();
|
|
|
|
const res: pxt.editor.ExtensionResult = {
|
|
|
|
fieldEditors: [{
|
|
|
|
selector: "ports",
|
|
|
|
editor: FieldPorts
|
2018-01-04 02:20:35 +01:00
|
|
|
}, {
|
|
|
|
selector: "images",
|
|
|
|
editor: FieldImages
|
2018-01-04 01:18:39 +01:00
|
|
|
}],
|
|
|
|
deployCoreAsync
|
|
|
|
};
|
|
|
|
initAsync().catch(e => {
|
|
|
|
// probably no HID - we'll try this again upon deployment
|
|
|
|
})
|
|
|
|
return Promise.resolve<pxt.editor.ExtensionResult>(res);
|
2017-07-06 18:34:31 +02:00
|
|
|
}
|
2017-07-25 12:48:02 +02:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* Update the shape of Blockly blocks with square corners
|
|
|
|
*/
|
|
|
|
function updateBlocklyShape() {
|
2017-07-06 18:34:31 +02:00
|
|
|
|
2018-01-02 22:32:07 +01:00
|
|
|
/**
|
2018-01-04 01:18:39 +01:00
|
|
|
* Rounded corner radius.
|
|
|
|
* @const
|
2018-01-02 22:32:07 +01:00
|
|
|
*/
|
2018-01-04 01:18:39 +01:00
|
|
|
(Blockly.BlockSvg as any).CORNER_RADIUS = 0 * (Blockly.BlockSvg as any).GRID_UNIT;
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* Inner space between edge of statement input and notch.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).STATEMENT_INPUT_INNER_SPACE = 3 * (Blockly.BlockSvg as any).GRID_UNIT;
|
|
|
|
/**
|
|
|
|
* SVG path for drawing next/previous notch from left to right.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).NOTCH_PATH_LEFT = (
|
|
|
|
'l 8,8 ' +
|
|
|
|
'h 16 ' +
|
|
|
|
'l 8,-8 '
|
|
|
|
);
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing next/previous notch from right to left.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).NOTCH_PATH_RIGHT = (
|
|
|
|
'l -8,8 ' +
|
|
|
|
'h -16 ' +
|
|
|
|
'l -8,-8 '
|
|
|
|
);
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG start point for drawing the top-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).TOP_LEFT_CORNER_START =
|
|
|
|
'm 0,' + 0;
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded top-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).TOP_LEFT_CORNER =
|
|
|
|
'l ' + (Blockly.BlockSvg as any).CORNER_RADIUS + ',0 ';
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded top-right corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).TOP_RIGHT_CORNER =
|
|
|
|
'l ' + 0 + ',' + (Blockly.BlockSvg as any).CORNER_RADIUS;
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded bottom-right corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).BOTTOM_RIGHT_CORNER =
|
|
|
|
'l 0,' + (Blockly.BlockSvg as any).CORNER_RADIUS;
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded bottom-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).BOTTOM_LEFT_CORNER =
|
|
|
|
'l -' + (Blockly.BlockSvg as any).CORNER_RADIUS + ',0';
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the top-left corner of a statement input.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).INNER_TOP_LEFT_CORNER =
|
|
|
|
'l ' + (Blockly.BlockSvg as any).CORNER_RADIUS + ',-' + 0;
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-04 01:18:39 +01:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the bottom-left corner of a statement input.
|
|
|
|
* Includes the rounded inside corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
(Blockly.BlockSvg as any).INNER_BOTTOM_LEFT_CORNER =
|
|
|
|
'l ' + 0 + ',' + (Blockly.BlockSvg as any).CORNER_RADIUS * 2 +
|
|
|
|
'l ' + (Blockly.BlockSvg as any).CORNER_RADIUS + ',' + 0;
|
2018-01-02 22:32:07 +01:00
|
|
|
|
2018-01-06 02:35:25 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2017-07-06 18:58:15 +02:00
|
|
|
}
|
2018-01-04 01:18:39 +01:00
|
|
|
|
|
|
|
// When require()d from node, bind the global pxt namespace
|
|
|
|
// namespace pxt {
|
|
|
|
// export const dummyExport = 1;
|
|
|
|
// }
|
|
|
|
// eval("if (typeof process === 'object' && process + '' === '[object process]') pxt = global.pxt")
|