Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 136 additions & 135 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,135 +1,136 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const gulp = require("gulp");

const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const typescript = require("typescript");
const del = require("del");
const es = require("event-stream");
const vsce = require("vsce");
const nls = require("vscode-nls-dev");

const tsProject = ts.createProject("./tsconfig.json", { typescript });

const inlineMap = true;
const inlineSource = false;
const outDest = "out";

// A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales
const languages = [{ folderName: "en", id: "en" }];

gulp.task("clean", () => {
return del(
[
"out/*",
"package.nls.*.json",
"../../dist/*0.0.0-UNTRACKEDVERSION.vsix"
],
{ force: true }
);
});

const pythonToMove = [
"./src/adafruit_circuitplayground/*.*",
"./src/*.py",
"./src/requirements.txt",
];

gulp.task("python-compile", () => {
// the base option sets the relative root for the set of files,
// preserving the folder structure
return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out"));
});

gulp.task("internal-compile", () => {
return compile(false);
});

gulp.task("internal-nls-compile", () => {
return compile(true);
});

gulp.task("add-locales", () => {
return gulp
.src(["package.nls.json"])
.pipe(nls.createAdditionalLanguageFiles(languages, "locales"))
.pipe(gulp.dest("."));
});

gulp.task("vsce:publish", () => {
return vsce.publish();
});

gulp.task("vsce:package", () => {
return vsce.createVSIX({
packagePath: "../../dist/deviceSimulatorExpress-0.0.0-UNTRACKEDVERSION.vsix"
});
});

gulp.task(
"compile",
gulp.series("clean", "internal-compile", "python-compile", callback => {
callback();
})
);

gulp.task(
"build",
gulp.series(
"clean",
"internal-nls-compile",
"python-compile",
"add-locales",
callback => {
callback();
}
)
);

gulp.task(
"publish",
gulp.series("compile", "vsce:publish", callback => {
callback();
})
);

gulp.task(
"package",
gulp.series("compile", "vsce:package", callback => {
callback();
})
);

//---- internal

function compile(buildNls) {
var r = tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
.pipe(
buildNls
? nls.createAdditionalLanguageFiles(languages, "locales", "out")
: es.through()
);

if (inlineMap && inlineSource) {
r = r.pipe(sourcemaps.write());
} else {
r = r.pipe(
sourcemaps.write("../out", {
// no inlined source
includeContent: inlineSource,
// Return relative source map root directories per file.
sourceRoot: "../src"
})
);
}

return r.pipe(gulp.dest(outDest));
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const gulp = require("gulp");

const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const typescript = require("typescript");
const del = require("del");
const es = require("event-stream");
const vsce = require("vsce");
const nls = require("vscode-nls-dev");

const tsProject = ts.createProject("./tsconfig.json", { typescript });

const inlineMap = true;
const inlineSource = false;
const outDest = "out";

// A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales
const languages = [{ folderName: "en", id: "en" }];

gulp.task("clean", () => {
return del(
[
"out/*",
"package.nls.*.json",
"../../dist/*0.0.0-UNTRACKEDVERSION.vsix"
],
{ force: true }
);
});

const pythonToMove = [
"./src/adafruit_circuitplayground/*.*",
"./src/microbit/*.*",
"./src/*.py",
"./src/requirements.txt",
];

gulp.task("python-compile", () => {
// the base option sets the relative root for the set of files,
// preserving the folder structure
return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out"));
});

gulp.task("internal-compile", () => {
return compile(false);
});

gulp.task("internal-nls-compile", () => {
return compile(true);
});

gulp.task("add-locales", () => {
return gulp
.src(["package.nls.json"])
.pipe(nls.createAdditionalLanguageFiles(languages, "locales"))
.pipe(gulp.dest("."));
});

gulp.task("vsce:publish", () => {
return vsce.publish();
});

gulp.task("vsce:package", () => {
return vsce.createVSIX({
packagePath: "../../dist/deviceSimulatorExpress-0.0.0-UNTRACKEDVERSION.vsix"
});
});

gulp.task(
"compile",
gulp.series("clean", "internal-compile", "python-compile", callback => {
callback();
})
);

gulp.task(
"build",
gulp.series(
"clean",
"internal-nls-compile",
"python-compile",
"add-locales",
callback => {
callback();
}
)
);

gulp.task(
"publish",
gulp.series("compile", "vsce:publish", callback => {
callback();
})
);

gulp.task(
"package",
gulp.series("compile", "vsce:package", callback => {
callback();
})
);

//---- internal

function compile(buildNls) {
var r = tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
.pipe(
buildNls
? nls.createAdditionalLanguageFiles(languages, "locales", "out")
: es.through()
);

if (inlineMap && inlineSource) {
r = r.pipe(sourcemaps.write());
} else {
r = r.pipe(
sourcemaps.write("../out", {
// no inlined source
includeContent: inlineSource,
// Return relative source map root directories per file.
sourceRoot: "../src"
})
);
}

return r.pipe(gulp.dest(outDest));
}
1 change: 1 addition & 0 deletions src/microbit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .code_processing_shim import *
50 changes: 50 additions & 0 deletions src/microbit/code_processing_shim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from . import microbit_model
from . import image
from . import constants as CONSTANTS

# EXAMPLE
# can be called simply as "show_message("string")"
def show_message(message):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome, it was exactly what I was thinking as well :)

microbit_model.mb.show_message(message)


display = microbit_model.mb.display

microbit = microbit_model.mb
Image = image.Image

def repr(image):

ret_str = "Image(\'"
for index_y in range(0,image.height()):
ret_str += row_to_str(image, index_y)

ret_str = ret_str + "\')"

return ret_str


def str(image):
if type(image) is Image:
ret_str = "Image(\'\n"
for index_y in range(0,image.height()):
ret_str += "\t" + row_to_str(image,index_y) + "\n"

ret_str = ret_str + "\')"

return ret_str
else:
# if not image, call regular str class
return image.__str__()



# method to help with string formation
def row_to_str(image, y):
new_str = ""
for x in range(0, image.width()):
new_str = new_str + str(image.get_pixel(x, y))

new_str = new_str + ":"

return new_str
37 changes: 37 additions & 0 deletions src/microbit/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
INDEX_ERR = "index out of bounds"
BRIGHTNESS_ERR = "brightness out of bounds"
SAME_SIZE_ERR = "images must be the same size"
UNSUPPORTED_ADD_TYPE = "unsupported types for __add__:"
LED_WIDTH = 5
LED_HEIGHT = 5

NOT_IMPLEMENTED_ERROR = "This method is not implemented by the simulator"

BOAT = (
[0, 5, 0, 5, 0],
[0, 5, 0, 5, 0],
[0, 5, 0, 5, 0],
[9, 9, 9, 9, 9],
[0, 9, 9, 9, 0],
)

HEART = [
[0, 9, 0, 9, 0],
[9, 9, 9, 9, 9],
[9, 9, 9, 9, 9],
[0, 9, 9, 9, 0],
[0, 0, 9, 0, 0],
]

BLANK = [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]


COPY_ERR_MESSAGE = "please copy() first"

LED_MAX = 5
Loading