Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
2798b579a6 | |||
9d23f82238 | |||
ce53d5c386 | |||
5d3471b3b2 | |||
08b9b10ac8 | |||
404d7cc4a2 | |||
7c43739e4b | |||
92d8adfdbd | |||
0f273131f6 | |||
9ae0c48477 | |||
5f538f418e | |||
859b68b6e3 | |||
6576f7bd66 | |||
5a670f3291 | |||
7129487618 | |||
e1797b457a | |||
c82efa452d | |||
493014af01 | |||
fb4a96d81b | |||
bbf115f33c | |||
5d9c2cf590 | |||
b99231f6e2 | |||
2676907129 | |||
6f4c533ebb | |||
85dcaea979 | |||
8560b31657 | |||
b896588f45 | |||
0b4d4facfe | |||
52ad897ee3 | |||
72582f2a60 | |||
2b2048da7d | |||
e85fa990bd | |||
81a61538c3 | |||
cc8751bd09 |
@ -2,9 +2,9 @@ language: node_js
|
|||||||
node_js:
|
node_js:
|
||||||
- "5.7.0"
|
- "5.7.0"
|
||||||
script:
|
script:
|
||||||
- "node node_modules/kindscript/built/kind.js travis"
|
- "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
- "(cd libs/lang-test0; node ../../node_modules/kindscript/built/kind.js run)"
|
- "(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js run)"
|
||||||
- "node node_modules/kindscript/built/kind.js uploaddoc"
|
- "node node_modules/pxt-core/built/pxt.js uploaddoc"
|
||||||
sudo: false
|
sudo: false
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
|
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
// Task runner is jake
|
// Task runner is jake
|
||||||
"command": "kind",
|
"command": "pxt",
|
||||||
// Need to be executed in shell / cmd
|
// Need to be executed in shell / cmd
|
||||||
"isShellCommand": true,
|
"isShellCommand": true,
|
||||||
"showOutput": "always",
|
"showOutput": "always",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/// <reference path="../node_modules/kindscript/built/kind.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/built/pxt.d.ts"/>
|
||||||
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
@ -7,7 +7,7 @@ import * as child_process from 'child_process';
|
|||||||
let writeFileAsync: any = Promise.promisify(fs.writeFile)
|
let writeFileAsync: any = Promise.promisify(fs.writeFile)
|
||||||
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
|
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
|
||||||
|
|
||||||
export function deployCoreAsync(res: ts.ks.CompileResult) {
|
export function deployCoreAsync(res: ts.pxt.CompileResult) {
|
||||||
return getBitDrivesAsync()
|
return getBitDrivesAsync()
|
||||||
.then(drives => {
|
.then(drives => {
|
||||||
if (drives.length == 0) {
|
if (drives.length == 0) {
|
||||||
@ -40,4 +40,4 @@ function getBitDrivesAsync(): Promise<string[]> {
|
|||||||
} else {
|
} else {
|
||||||
return Promise.resolve([])
|
return Promise.resolve([])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ namespace i2c_fram {
|
|||||||
const devaddr = 0x50;
|
const devaddr = 0x50;
|
||||||
const memend = 0x7fff;
|
const memend = 0x7fff;
|
||||||
|
|
||||||
//% shim=ksrt::panic
|
//% shim=pxtrt::panic
|
||||||
function panic(code: number) { }
|
function panic(code: number) { }
|
||||||
|
|
||||||
function die() { panic(142) }
|
function die() { panic(142) }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Do not use anything besides basic.pause, control.inBackground, console.log
|
// Do not use anything besides basic.pause, control.inBackground, console.log
|
||||||
//
|
//
|
||||||
|
|
||||||
//% shim=ksrt::panic
|
//% shim=pxtrt::panic
|
||||||
function panic(code2: number): void { }
|
function panic(code2: number): void { }
|
||||||
|
|
||||||
function msg(s: string): void {
|
function msg(s: string): void {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "kindscript.h"
|
#include "pxt.h"
|
||||||
#include "MESEvents.h"
|
#include "MESEvents.h"
|
||||||
|
|
||||||
using namespace kindscript;
|
using namespace pxt;
|
||||||
|
|
||||||
enum class MesCameraEvent {
|
enum class MesCameraEvent {
|
||||||
//% block="take photo"
|
//% block="take photo"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "kindscript.h"
|
#include "pxt.h"
|
||||||
|
|
||||||
using namespace kindscript;
|
using namespace pxt;
|
||||||
|
|
||||||
//% color=270 weight=34
|
//% color=270 weight=34
|
||||||
namespace radio {
|
namespace radio {
|
||||||
@ -15,7 +15,7 @@ namespace radio {
|
|||||||
int r = uBit.radio.enable();
|
int r = uBit.radio.enable();
|
||||||
if (r != MICROBIT_OK) return r;
|
if (r != MICROBIT_OK) return r;
|
||||||
if (!radioEnabled) {
|
if (!radioEnabled) {
|
||||||
uBit.radio.setGroup(kindscript::programHash());
|
uBit.radio.setGroup(pxt::programHash());
|
||||||
radioEnabled = true;
|
radioEnabled = true;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
@ -154,7 +154,7 @@ namespace Array_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Import some stuff directly
|
// Import some stuff directly
|
||||||
namespace kindscript {
|
namespace pxt {
|
||||||
//%
|
//%
|
||||||
void registerWithDal(int id, int event, Action a);
|
void registerWithDal(int id, int event, Action a);
|
||||||
//%
|
//%
|
||||||
@ -181,7 +181,7 @@ namespace kindscript {
|
|||||||
void *ptrOfLiteral(int offset);
|
void *ptrOfLiteral(int offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ksrt {
|
namespace pxtrt {
|
||||||
//%
|
//%
|
||||||
uint32_t ldloc(RefLocal *r) {
|
uint32_t ldloc(RefLocal *r) {
|
||||||
return r->v;
|
return r->v;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "kindscript.h"
|
#include "pxt.h"
|
||||||
#include "ManagedBuffer.h"
|
#include "ManagedBuffer.h"
|
||||||
|
|
||||||
using namespace kindscript;
|
using namespace pxt;
|
||||||
MicroBitPin *getPin(int id);
|
MicroBitPin *getPin(int id);
|
||||||
typedef ImageData* Image;
|
typedef ImageData* Image;
|
||||||
typedef BufferData* Buffer;
|
typedef BufferData* Buffer;
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
"dal.d.ts",
|
"dal.d.ts",
|
||||||
"enums.d.ts",
|
"enums.d.ts",
|
||||||
"shims.d.ts",
|
"shims.d.ts",
|
||||||
"ks-core.d.ts",
|
"pxt-core.d.ts",
|
||||||
"ksbit.h",
|
"ksbit.h",
|
||||||
"core.cpp",
|
"core.cpp",
|
||||||
"ks-helpers.ts",
|
"pxt-helpers.ts",
|
||||||
"helpers.ts",
|
"helpers.ts",
|
||||||
"images.cpp",
|
"images.cpp",
|
||||||
"basic.cpp",
|
"basic.cpp",
|
14
package.json
14
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "kindscript-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.2.29",
|
"version": "0.2.43",
|
||||||
"description": "BBC micro:bit target for KindScript",
|
"description": "BBC micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
"education",
|
"education",
|
||||||
@ -9,14 +9,14 @@
|
|||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/Microsoft/kindscript-microbit.git"
|
"url": "git+https://github.com/Microsoft/pxt-microbit.git"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/Microsoft/kindscript-microbit#readme",
|
"homepage": "https://github.com/Microsoft/pxt-microbit#readme",
|
||||||
"files": [
|
"files": [
|
||||||
"README.md",
|
"README.md",
|
||||||
"kindtarget.json",
|
"pxtarget.json",
|
||||||
"built/*.js",
|
"built/*.js",
|
||||||
"built/*.json",
|
"built/*.json",
|
||||||
"built/*.d.ts",
|
"built/*.d.ts",
|
||||||
@ -29,6 +29,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"kindscript": "0.2.30"
|
"pxt-core": "0.2.44"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "microbit",
|
"id": "microbit",
|
||||||
"name": "BBC micro:bit",
|
"name": "code micro:bit",
|
||||||
"title": "JavaScript for BBC micro:bit",
|
"title": "micro:bit",
|
||||||
"corepkg": "microbit",
|
"corepkg": "microbit",
|
||||||
"bundleddirs": [
|
"bundleddirs": [
|
||||||
"libs/microbit",
|
"libs/microbit",
|
||||||
@ -22,13 +22,13 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"files": [
|
"files": [
|
||||||
"main.blocks",
|
"main.blocks",
|
||||||
"main.blocks.ts",
|
"main.ts",
|
||||||
"README.md"
|
"README.md"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"device_print_message\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">Hello!</field></shadow></value></block></xml>",
|
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"device_print_message\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">Hello!</field></shadow></value></block></xml>",
|
||||||
"main.blocks.ts": "\n",
|
"main.ts": "\n",
|
||||||
"README.md": "Describe your project here!"
|
"README.md": "Describe your project here!"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -59,7 +59,7 @@
|
|||||||
"autoRun": true
|
"autoRun": true
|
||||||
},
|
},
|
||||||
"compileService": {
|
"compileService": {
|
||||||
"gittag": "v0.1.5",
|
"gittag": "v0.1.6",
|
||||||
"serviceId": "ws"
|
"serviceId": "ws"
|
||||||
},
|
},
|
||||||
"serial": {
|
"serial": {
|
||||||
@ -93,4 +93,4 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
/// <reference path="../node_modules/kindscript/typings/bluebird/bluebird.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
|
||||||
/// <reference path="../node_modules/kindscript/built/kindsim.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||||
/// <reference path="../libs/microbit/dal.d.ts"/>
|
/// <reference path="../libs/microbit/dal.d.ts"/>
|
||||||
|
|
||||||
namespace ks.rt {
|
namespace pxsim {
|
||||||
ks.rt.initCurrentRuntime = () => {
|
pxsim.initCurrentRuntime = () => {
|
||||||
U.assert(!runtime.board)
|
U.assert(!runtime.board)
|
||||||
runtime.board = new Board()
|
runtime.board = new Board()
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ namespace ks.rt {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.basic {
|
namespace pxsim.basic {
|
||||||
export var pause = thread.pause;
|
export var pause = thread.pause;
|
||||||
export var forever = thread.forever;
|
export var forever = thread.forever;
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ namespace ks.rt.basic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.control {
|
namespace pxsim.control {
|
||||||
export var inBackground = thread.runInBackground;
|
export var inBackground = thread.runInBackground;
|
||||||
|
|
||||||
export function reset() {
|
export function reset() {
|
||||||
@ -213,7 +213,7 @@ namespace ks.rt.control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function onEvent(id: number, evid: number, handler: RefAction) {
|
export function onEvent(id: number, evid: number, handler: RefAction) {
|
||||||
kindscript.registerWithDal(id, evid, handler)
|
pxt.registerWithDal(id, evid, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function raiseEvent(id: number, evid: number, mode: number) {
|
export function raiseEvent(id: number, evid: number, mode: number) {
|
||||||
@ -222,13 +222,13 @@ namespace ks.rt.control {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.kindscript {
|
namespace pxsim.pxt {
|
||||||
export function registerWithDal(id: number, evid: number, handler: RefAction) {
|
export function registerWithDal(id: number, evid: number, handler: RefAction) {
|
||||||
board().bus.listen(id, evid, handler);
|
board().bus.listen(id, evid, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.input {
|
namespace pxsim.input {
|
||||||
export function onButtonPressed(button: number, handler: RefAction): void {
|
export function onButtonPressed(button: number, handler: RefAction): void {
|
||||||
let b = board();
|
let b = board();
|
||||||
if (button == DAL.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) {
|
if (button == DAL.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) {
|
||||||
@ -333,7 +333,7 @@ namespace ks.rt.input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.led {
|
namespace pxsim.led {
|
||||||
export function plot(x: number, y: number) {
|
export function plot(x: number, y: number) {
|
||||||
board().image.set(x, y, 255);
|
board().image.set(x, y, 255);
|
||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
@ -367,7 +367,7 @@ namespace ks.rt.led {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.serial {
|
namespace pxsim.serial {
|
||||||
export function writeString(s: string) {
|
export function writeString(s: string) {
|
||||||
board().writeSerial(s);
|
board().writeSerial(s);
|
||||||
}
|
}
|
||||||
@ -378,7 +378,7 @@ namespace ks.rt.serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace ks.rt.radio {
|
namespace pxsim.radio {
|
||||||
export function broadcastMessage(msg: number): void {
|
export function broadcastMessage(msg: number): void {
|
||||||
board().radio.broadcast(msg);
|
board().radio.broadcast(msg);
|
||||||
}
|
}
|
||||||
@ -416,7 +416,7 @@ namespace ks.rt.radio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.pins {
|
namespace pxsim.pins {
|
||||||
export function digitalReadPin(pinId: number): number {
|
export function digitalReadPin(pinId: number): number {
|
||||||
let pin = getPin(pinId);
|
let pin = getPin(pinId);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
@ -504,12 +504,12 @@ namespace ks.rt.pins {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.images {
|
namespace pxsim.images {
|
||||||
export function createImage(img: Image) { return img }
|
export function createImage(img: Image) { return img }
|
||||||
export function createBigImage(img: Image) { return img }
|
export function createBigImage(img: Image) { return img }
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ks.rt.ImageMethods {
|
namespace pxsim.ImageMethods {
|
||||||
export function showImage(i: Image, offset: number) {
|
export function showImage(i: Image, offset: number) {
|
||||||
// TODO offset?
|
// TODO offset?
|
||||||
i.copyTo(0, 5, board().image, 0)
|
i.copyTo(0, 5, board().image, 0)
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="/cdn/bluebird.min.js"></script>
|
<script src="/cdn/bluebird.min.js"></script>
|
||||||
<script src="/cdn/kindsim.js"></script>
|
<script src="/cdn/pxtsim.js"></script>
|
||||||
<script src="/sim/sim.js"></script>
|
<script src="/sim/sim.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
124
sim/simsvg.ts
124
sim/simsvg.ts
@ -1,4 +1,5 @@
|
|||||||
namespace ks.rt.micro_bit {
|
namespace pxsim.micro_bit {
|
||||||
|
const Svg = pxsim.Svg;
|
||||||
|
|
||||||
export interface IBoardTheme {
|
export interface IBoardTheme {
|
||||||
accent?: string;
|
accent?: string;
|
||||||
@ -41,124 +42,11 @@ namespace ks.rt.micro_bit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IBoardProps {
|
export interface IBoardProps {
|
||||||
runtime: ks.rt.Runtime;
|
runtime: pxsim.Runtime;
|
||||||
theme?: IBoardTheme;
|
theme?: IBoardTheme;
|
||||||
disableTilt?:boolean;
|
disableTilt?:boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Svg {
|
|
||||||
static pt : SVGPoint;
|
|
||||||
static cursorPoint(pt: SVGPoint, svg: SVGSVGElement, evt : MouseEvent) : SVGPoint {
|
|
||||||
pt.x = evt.clientX;
|
|
||||||
pt.y = evt.clientY;
|
|
||||||
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
||||||
}
|
|
||||||
|
|
||||||
static rotateElement(el : SVGElement, originX : number ,originY : number,degrees:number){
|
|
||||||
el.setAttribute(
|
|
||||||
'transform',
|
|
||||||
`translate(${originX},${originY}) rotate(${degrees+90}) translate(${-originX},${-originY})`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static elt(name:string) : SVGElement {
|
|
||||||
return document.createElementNS("http://www.w3.org/2000/svg", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
static hydrate(el : SVGElement, props: any) {
|
|
||||||
for(let k in props) {
|
|
||||||
if (k == "title") {
|
|
||||||
Svg.title(el, props[k])
|
|
||||||
} else el.setAttributeNS(null, k, props[k])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static child(parent : Element, name: string, props: any) : SVGElement {
|
|
||||||
var el = <SVGElement>Svg.elt(name);
|
|
||||||
Svg.hydrate(el, props);
|
|
||||||
parent.appendChild(el);
|
|
||||||
return el;
|
|
||||||
}
|
|
||||||
|
|
||||||
static path(parent: Element, cls: string, data:string, title?: string) : SVGElement {
|
|
||||||
let p : any = {class:cls, d:data};
|
|
||||||
if (title) p["title"] = title;
|
|
||||||
return Svg.child(parent, "path", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
static fill(el: SVGElement, c : string) {
|
|
||||||
(<SVGStylable><any>el).style.fill = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static fills(els: SVGElement[], c : string) {
|
|
||||||
els.forEach(el => (<SVGStylable><any>el).style.fill = c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static buttonEvents(el : Element,
|
|
||||||
move: (ev: MouseEvent) => void,
|
|
||||||
start?: (ev:MouseEvent) => void,
|
|
||||||
stop?: (ev:MouseEvent) => void) {
|
|
||||||
let captured = false;
|
|
||||||
el.addEventListener('mousedown', (ev: MouseEvent) => {
|
|
||||||
captured = true;
|
|
||||||
if (start) start(ev)
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
el.addEventListener('mousemove', (ev:MouseEvent) => {
|
|
||||||
if (captured) {
|
|
||||||
move(ev);
|
|
||||||
ev.preventDefault();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
el.addEventListener('mouseup', (ev:MouseEvent) => {
|
|
||||||
captured = false;
|
|
||||||
if (stop) stop(ev);
|
|
||||||
});
|
|
||||||
el.addEventListener('mouseleave', (ev:MouseEvent) => {
|
|
||||||
captured = false;
|
|
||||||
if (stop) stop(ev);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static linearGradient(defs: SVGDefsElement, id : string) : SVGLinearGradientElement {
|
|
||||||
let gradient = <SVGLinearGradientElement>Svg.child(defs, "linearGradient", { id: id, x1:"0%", y1:"0%", x2:"0%", y2:"100%" });
|
|
||||||
let stop1 = Svg.child(gradient, "stop", {offset:"0%"})
|
|
||||||
let stop2 = Svg.child(gradient, "stop", {offset:"100%"})
|
|
||||||
let stop3 = Svg.child(gradient, "stop", {offset:"100%"})
|
|
||||||
let stop4 = Svg.child(gradient, "stop", {offset:"100%"})
|
|
||||||
return gradient;
|
|
||||||
}
|
|
||||||
|
|
||||||
static setGradientColors(lg : SVGLinearGradientElement, start:string, end:string) {
|
|
||||||
if (!lg) return;
|
|
||||||
|
|
||||||
(<SVGStopElement>lg.childNodes[0]).style.stopColor = start;
|
|
||||||
(<SVGStopElement>lg.childNodes[1]).style.stopColor = start;
|
|
||||||
(<SVGStopElement>lg.childNodes[2]).style.stopColor = end;
|
|
||||||
(<SVGStopElement>lg.childNodes[3]).style.stopColor = end;
|
|
||||||
}
|
|
||||||
|
|
||||||
static setGradientValue(lg : SVGLinearGradientElement, percent: string) {
|
|
||||||
(<SVGStopElement>lg.childNodes[1]).setAttribute("offset", percent);
|
|
||||||
(<SVGStopElement>lg.childNodes[2]).setAttribute("offset", percent);
|
|
||||||
}
|
|
||||||
|
|
||||||
static animate(el: SVGElement, cls: string) {
|
|
||||||
el.classList.add(cls);
|
|
||||||
let p = el.parentElement;
|
|
||||||
p.removeChild(el);
|
|
||||||
p.appendChild(el)
|
|
||||||
}
|
|
||||||
|
|
||||||
static title(el : SVGElement, txt:string) {
|
|
||||||
let t = Svg.child(el, "title", {});
|
|
||||||
t.textContent = txt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MicrobitBoardSvg
|
export class MicrobitBoardSvg
|
||||||
{
|
{
|
||||||
public element : SVGSVGElement;
|
public element : SVGSVGElement;
|
||||||
@ -188,10 +76,10 @@ namespace ks.rt.micro_bit {
|
|||||||
private thermometerText: SVGTextElement;
|
private thermometerText: SVGTextElement;
|
||||||
private shakeButton: SVGCircleElement;
|
private shakeButton: SVGCircleElement;
|
||||||
private shakeText: SVGTextElement;
|
private shakeText: SVGTextElement;
|
||||||
public board: rt.Board;
|
public board: pxsim.Board;
|
||||||
|
|
||||||
constructor(public props: IBoardProps) {
|
constructor(public props: IBoardProps) {
|
||||||
this.board = this.props.runtime.board as rt.Board;
|
this.board = this.props.runtime.board as pxsim.Board;
|
||||||
this.board.updateView = () => this.updateState();
|
this.board.updateView = () => this.updateState();
|
||||||
this.buildDom();
|
this.buildDom();
|
||||||
this.updateTheme();
|
this.updateTheme();
|
||||||
@ -227,7 +115,7 @@ namespace ks.rt.micro_bit {
|
|||||||
Svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp);
|
Svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp);
|
||||||
});
|
});
|
||||||
|
|
||||||
var bw = state.displayMode == rt.DisplayMode.bw
|
var bw = state.displayMode == pxsim.DisplayMode.bw
|
||||||
var img = state.image;
|
var img = state.image;
|
||||||
this.leds.forEach((led,i) => {
|
this.leds.forEach((led,i) => {
|
||||||
var sel = (<SVGStylable><any>led)
|
var sel = (<SVGStylable><any>led)
|
||||||
|
12
sim/state.ts
12
sim/state.ts
@ -1,4 +1,4 @@
|
|||||||
namespace ks.rt {
|
namespace pxsim {
|
||||||
export interface RuntimeOptions {
|
export interface RuntimeOptions {
|
||||||
theme: string;
|
theme: string;
|
||||||
}
|
}
|
||||||
@ -555,11 +555,11 @@ namespace ks.rt {
|
|||||||
case 'yellow': theme = micro_bit.themes[1]; break;
|
case 'yellow': theme = micro_bit.themes[1]; break;
|
||||||
case 'green': theme = micro_bit.themes[2]; break;
|
case 'green': theme = micro_bit.themes[2]; break;
|
||||||
case 'red': theme = micro_bit.themes[3]; break;
|
case 'red': theme = micro_bit.themes[3]; break;
|
||||||
default: theme = ks.rt.micro_bit.randomTheme();
|
default: theme = pxsim.micro_bit.randomTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('setting up microbit simulator')
|
console.log('setting up microbit simulator')
|
||||||
let view = new ks.rt.micro_bit.MicrobitBoardSvg({
|
let view = new pxsim.micro_bit.MicrobitBoardSvg({
|
||||||
theme: theme,
|
theme: theme,
|
||||||
runtime: runtime
|
runtime: runtime
|
||||||
})
|
})
|
||||||
@ -596,8 +596,8 @@ namespace ks.rt {
|
|||||||
writeSerial(s: string) {
|
writeSerial(s: string) {
|
||||||
for (let i = 0; i < s.length; ++i) {
|
for (let i = 0; i < s.length; ++i) {
|
||||||
let c = s[i];
|
let c = s[i];
|
||||||
switch (c) {
|
this.serialOutBuffer += c;
|
||||||
case '\n':
|
if (c == '\n') {
|
||||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||||
type: 'serial',
|
type: 'serial',
|
||||||
data: this.serialOutBuffer,
|
data: this.serialOutBuffer,
|
||||||
@ -605,8 +605,6 @@ namespace ks.rt {
|
|||||||
})
|
})
|
||||||
this.serialOutBuffer = ''
|
this.serialOutBuffer = ''
|
||||||
break;
|
break;
|
||||||
case '\r': continue;
|
|
||||||
default: this.serialOutBuffer += c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user