2016-09-09 22:43:41 +02:00
|
|
|
/// <reference path="../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
|
|
|
|
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
|
|
|
/// <reference path="../node_modules/pxt-core/built/pxtrunner.d.ts"/>
|
2016-08-30 20:55:00 +02:00
|
|
|
|
|
|
|
//HACK: allows instructions.html to access pxtblocks without requiring simulator.html to import blocks as well
|
|
|
|
if (!(<any>window).pxt) (<any>window).pxt = {};
|
|
|
|
import pxtrunner = pxt.runner;
|
|
|
|
import pxtdocs = pxt.docs;
|
|
|
|
|
|
|
|
namespace pxsim.instructions {
|
2016-09-26 22:26:43 +02:00
|
|
|
export function drawInstructions() {
|
|
|
|
pxsim.visuals.mkBoardView = (opts: pxsim.visuals.BoardViewOptions): pxsim.visuals.BoardView => {
|
|
|
|
return new visuals.MicrobitBoardSvg({
|
|
|
|
runtime: runtime,
|
|
|
|
theme: visuals.randomTheme(),
|
|
|
|
disableTilt: false,
|
|
|
|
wireframe: opts.wireframe,
|
2016-08-30 20:55:00 +02:00
|
|
|
});
|
2016-09-26 22:26:43 +02:00
|
|
|
}
|
2016-08-30 20:55:00 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
let getQsVal = parseQueryString();
|
2016-08-30 20:55:00 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
//project name
|
|
|
|
let name = getQsVal("name") || "Untitled";
|
2016-08-30 20:55:00 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
// board def
|
|
|
|
const boardDef = JSON.parse(getQsVal("board")) as pxsim.BoardDefinition;
|
2016-08-30 20:55:00 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
//parts list
|
|
|
|
let parts = (getQsVal("parts") || "").split(" ");
|
|
|
|
parts.sort();
|
2016-08-30 20:55:00 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
// parts definitions
|
|
|
|
let partDefinitions = JSON.parse(getQsVal("partdefs") || "{}") as pxsim.Map<PartDefinition>
|
2016-08-30 20:55:00 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
//fn args
|
|
|
|
let fnArgs = JSON.parse((getQsVal("fnArgs") || "{}"));
|
2016-08-30 20:55:00 +02:00
|
|
|
|
|
|
|
//project code
|
|
|
|
let tsCode = getQsVal("code");
|
2016-08-31 23:07:10 +02:00
|
|
|
let tsPackage = getQsVal("package") || "";
|
2016-08-30 20:55:00 +02:00
|
|
|
let codeSpinnerDiv = document.getElementById("proj-code-spinner");
|
|
|
|
let codeContainerDiv = document.getElementById("proj-code-container");
|
|
|
|
if (tsCode) {
|
|
|
|
//we use the docs renderer to decompile the code to blocks and render it
|
|
|
|
//TODO: render the blocks code directly
|
2016-09-05 15:26:07 +02:00
|
|
|
let md =
|
|
|
|
`\`\`\`blocks
|
2016-08-31 23:07:10 +02:00
|
|
|
${tsCode}
|
|
|
|
\`\`\`
|
|
|
|
\`\`\`package
|
|
|
|
${tsPackage}
|
|
|
|
\`\`\`
|
|
|
|
`
|
|
|
|
|
2016-09-05 15:26:07 +02:00
|
|
|
pxtdocs.requireMarked = function () { return (<any>window).marked; }
|
2016-08-30 20:55:00 +02:00
|
|
|
pxtrunner.renderMarkdownAsync(codeContainerDiv, md)
|
2016-09-05 15:26:07 +02:00
|
|
|
.done(function () {
|
2016-08-30 20:55:00 +02:00
|
|
|
let codeSvg = $("#proj-code-container svg");
|
|
|
|
if (codeSvg.length > 0) {
|
|
|
|
//code rendered successfully as blocks
|
|
|
|
codeSvg.css("width", "inherit");
|
|
|
|
codeSvg.css("height", "inherit");
|
|
|
|
//takes the svg out of the wrapper markdown
|
|
|
|
codeContainerDiv.innerHTML = "";
|
|
|
|
codeContainerDiv.appendChild(codeSvg[0]);
|
|
|
|
} else {
|
|
|
|
//code failed to convert to blocks, display as typescript instead
|
|
|
|
codeContainerDiv.innerText = tsCode;
|
|
|
|
}
|
|
|
|
$(codeContainerDiv).show();
|
|
|
|
$(codeSpinnerDiv).hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-02 00:37:39 +02:00
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
if (name)
|
|
|
|
$("#proj-title").text(name);
|
2016-08-30 20:55:00 +02:00
|
|
|
|
|
|
|
//init runtime
|
|
|
|
if (!pxsim.initCurrentRuntime)
|
|
|
|
pxsim.initCurrentRuntime = initRuntimeWithDalBoard;
|
|
|
|
|
2016-09-26 22:26:43 +02:00
|
|
|
renderParts({
|
|
|
|
name,
|
|
|
|
boardDef,
|
|
|
|
parts,
|
|
|
|
partDefinitions,
|
|
|
|
fnArgs
|
|
|
|
})
|
2016-08-30 20:55:00 +02:00
|
|
|
}
|
|
|
|
}
|