-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into dev/riknoll/tutoria…
…l-bundle
- Loading branch information
Showing
16 changed files
with
236 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Simulator Extensions | ||
|
||
A simulator extension is a static web application that complements a traditional MakeCode extension. When you add an extension containing a simulator extension to your MakeCode project, the simulator extension is loaded into a separate iframe within the MakeCode editor. This enables extensions to display custom UI when the project is running. | ||
|
||
> [!IMPORTANT] | ||
> Simulator extensions are only supported for [Approved Extensions](./approval.md), and they must go through an additional approval process. The MakeCode team reserves the right to approve or decline simulator extensions at their discretion. We strongly recommend consulting with the MakeCode team before investing time and resources into creating a simulator extension. | ||
## Example simulator extensions | ||
|
||
* [pxt-simx-sample](https://github.com/microsoft/pxt-simx-sample) | ||
* [pxt-arcadeshield](https://github.com/microsoft/pxt-arcadeshield) | ||
* [microbit-robot](https://github.com/microsoft/microbit-robot) | ||
* [pxt-jacdac](https://github.com/microsoft/) | ||
|
||
## Creating a simulator extension | ||
|
||
Refer to the [pxt-simx-sample](https://github.com/microsoft/pxt-simx-sample) project for detailed instructions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as Blockly from "blockly"; | ||
|
||
interface ExtendedGridOptions extends Blockly.Options.GridOptions { | ||
image?: { | ||
path: string; | ||
width: string; | ||
height: string; | ||
opacity: number; | ||
} | ||
} | ||
|
||
export function monkeyPatchGrid() { | ||
const options = pxt.appTarget.appTheme.blocklyOptions?.grid as ExtendedGridOptions; | ||
|
||
if (!options?.image?.path) return; | ||
|
||
const gridPatternIds: string[] = []; | ||
|
||
Blockly.Grid.createDom = function (rnd: string, gridOptions: Blockly.Options.GridOptions, defs: SVGElement) { | ||
const id = "blocklyGridPattern" + rnd; | ||
|
||
const gridPattern = Blockly.utils.dom.createSvgElement( | ||
Blockly.utils.Svg.PATTERN, | ||
{ | ||
id, | ||
patternUnits: "userSpaceOnUse", | ||
width: options.image.width, | ||
height: options.image.height | ||
}, | ||
defs, | ||
); | ||
|
||
gridPatternIds.push(id) | ||
|
||
const image = Blockly.utils.dom.createSvgElement( | ||
Blockly.utils.Svg.IMAGE, | ||
{ | ||
width: options.image.width, | ||
height: options.image.height, | ||
opacity: options.image.opacity | ||
}, | ||
gridPattern | ||
); | ||
|
||
image.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", options.image.path) | ||
|
||
return gridPattern; | ||
} | ||
|
||
const oldGridUpdate = Blockly.Grid.prototype.update; | ||
|
||
Blockly.Grid.prototype.update = function (this: Blockly.Grid, scale: number) { | ||
oldGridUpdate.call(this, scale); | ||
|
||
const patternsToRemove: string[] = []; | ||
for (const patternId of gridPatternIds) { | ||
const imagePattern = document.getElementById(patternId) as unknown as SVGPatternElement; | ||
|
||
if (!imagePattern) { | ||
patternsToRemove.push(patternId); | ||
continue; | ||
} | ||
|
||
imagePattern.setAttribute("width", options.image.width); | ||
imagePattern.setAttribute("height", options.image.height); | ||
imagePattern.setAttribute('patternTransform', 'scale(' + scale + ')'); | ||
} | ||
|
||
for (const patternId of patternsToRemove) { | ||
gridPatternIds.splice(gridPatternIds.indexOf(patternId), 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { monkeyPatchBlockSvg } from "./blockSvg"; | ||
import { monkeyPatchGrid } from "./grid"; | ||
|
||
export function applyMonkeyPatches() { | ||
monkeyPatchBlockSvg(); | ||
monkeyPatchGrid(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.