Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "microbit",
|
||||
"name": "BBC micro:bit",
|
||||
"title": "JavaScript for BBC micro:bit",
|
||||
"name": "code micro:bit",
|
||||
"title": "micro:bit",
|
||||
"corepkg": "microbit",
|
||||
"bundleddirs": [
|
||||
"libs/microbit",
|
||||
@ -22,13 +22,13 @@
|
||||
"description": "",
|
||||
"files": [
|
||||
"main.blocks",
|
||||
"main.blocks.ts",
|
||||
"main.ts",
|
||||
"README.md"
|
||||
]
|
||||
},
|
||||
"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.ts": "\n",
|
||||
"main.ts": "\n",
|
||||
"README.md": "Describe your project here!"
|
||||
}
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kindscript-microbit",
|
||||
"version": "0.2.29",
|
||||
"version": "0.2.41",
|
||||
"description": "BBC micro:bit target for KindScript",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"kindscript": "0.2.30"
|
||||
"kindscript": "0.2.42"
|
||||
}
|
||||
}
|
||||
|
114
sim/simsvg.ts
114
sim/simsvg.ts
@ -1,4 +1,5 @@
|
||||
namespace ks.rt.micro_bit {
|
||||
const Svg = ks.rt.Svg;
|
||||
|
||||
export interface IBoardTheme {
|
||||
accent?: string;
|
||||
@ -46,119 +47,6 @@ namespace ks.rt.micro_bit {
|
||||
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
|
||||
{
|
||||
public element : SVGSVGElement;
|
||||
|
@ -596,8 +596,8 @@ namespace ks.rt {
|
||||
writeSerial(s: string) {
|
||||
for (let i = 0; i < s.length; ++i) {
|
||||
let c = s[i];
|
||||
switch (c) {
|
||||
case '\n':
|
||||
this.serialOutBuffer += c;
|
||||
if (c == '\n') {
|
||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||
type: 'serial',
|
||||
data: this.serialOutBuffer,
|
||||
@ -605,8 +605,6 @@ namespace ks.rt {
|
||||
})
|
||||
this.serialOutBuffer = ''
|
||||
break;
|
||||
case '\r': continue;
|
||||
default: this.serialOutBuffer += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user