Skip to content

Commit

Permalink
aply code mappings and block patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Amerlander committed Nov 22, 2023
1 parent 9ece957 commit ec0360e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
7 changes: 1 addition & 6 deletions docs/static/icons/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "makecode.microbit.org",
"name": "makecode.calliope.cc",
"icons": [
{
"src": "\/android-chrome-36x36.png",
Expand All @@ -21,11 +21,6 @@
"sizes": "96x96",
"type": "image\/png"
},
{
"src": "\/android-chrome-144x144.png",
"sizes": "144x144",
"type": "image\/png"
},
{
"src": "\/android-chrome-192x192.png",
"sizes": "192x192",
Expand Down
34 changes: 31 additions & 3 deletions editor/patch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@

export function patchBlocks(pkgTargetVersion: string, dom: Element) {

// is this a old script?
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "5.0.0") >= 0) return;

// Motor Names mapping
pxt.U.toArray(dom.querySelectorAll('field[name="motor"]'))
.forEach(node => {
const motorValue = node.textContent.trim();
switch (motorValue) {
case 'Motor.A':
node.textContent = 'Motor.M0';
break;
case 'Motor.B':
node.textContent = 'Motor.M1';
break;
case 'Motor.AB':
node.textContent = 'Motor.M0_M1';
break;
// Add additional cases if needed for other motor values
}
});

// Sound level mapping
pxt.U.toArray(dom.querySelectorAll('block[type=device_get_sound_level]'))
.forEach(node => {
node.setAttribute('type', 'soundLevel');
});



// is this a old script?
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "4.0.20") >= 0) return;
// button and pin pressed/released blocks
Expand Down Expand Up @@ -148,9 +178,6 @@ arrowImageNodes.forEach(node => {
arrowNode.textContent = "IconNames.Arrow" + arrowNode.textContent.split('.')[1];
});

// is this a very old script?
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "1.0.0") >= 0) return;

// LEDs
/**
* <block type="device_show_leds">
Expand Down Expand Up @@ -196,6 +223,7 @@ arrowImageNodes.forEach(node => {


if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "5.0.12") <= 0) {

// Eighth note misspelling
/*
<block type="basic_show_icon">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"input": "Events and data from sensors",
"input.assumeCalibrationCompass": "Obsolete, compass calibration is automatic.",
"input.clearCalibrationCompass": "Obsolete, compass calibration is automatic.",
"input.loudness": "gets the level of loudness from 0 (silent) to 255 (loud)",
"motors": "Blocks to control the onboard motors",
"motors.dualMotorPower": "Controls two motors attached to the board. Switches to dual-motor mode!",
"motors.motorCommand": "Send break, coast or sleep commands to the motor. Has no effect in dual-motor mode.",
Expand Down
1 change: 0 additions & 1 deletion libs/core-mini-dal/_locales/core-mini-dal-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"basic|block": "basic",
"input.assumeCalibrationCompass|block": "assume calibration compass",
"input.clearCalibrationCompass|block": "clear calibration compass",
"input.loudness|block": "Loudness",
"input|block": "input",
"motors.dualMotorPower|block": "motor %motor|at %percent \\%",
"motors.motorCommand|block": "motor %command",
Expand Down
15 changes: 0 additions & 15 deletions libs/core-mini-dal/microphone.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/core-mini-dal/pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"files": [
"shims.d.ts",
"enums.d.ts",
"microphone.ts",
"motors.ts",
"parts/dcmotor.svg",
"input.cpp",
Expand Down
3 changes: 2 additions & 1 deletion libs/core/microphone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace input {
* Reads the loudness through the microphone from 0 (silent) to 255 (loud)
*/
//% help=input/sound-level
//% blockId=device_get_sound_level block="sound level"
//% blockId=soundLevel block="sound level"
//% parts="microphone"
//% weight=34 blockGap=8
//% group="Sound"
Expand Down Expand Up @@ -48,4 +48,5 @@ int soundLevel() {
return level;
#endif
}

}
2 changes: 1 addition & 1 deletion libs/core/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ declare namespace input {
* Reads the loudness through the microphone from 0 (silent) to 255 (loud)
*/
//% help=input/sound-level
//% blockId=device_get_sound_level block="sound level"
//% blockId=soundLevel block="sound level"
//% parts="microphone"
//% weight=34 blockGap=8
//% group="Sound" shim=input::soundLevel
Expand Down
11 changes: 11 additions & 0 deletions pxtarget.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@
"input\\s*\\.\\s*onButtonEvent\\s*\\(\\s*(.*?),\\s*ButtonEvent\\s*.\\s*(.*?),": "input.onButtonEvent($1, input.buttonEventValue(ButtonEvent.$2),"
}
}
],
"0.0.0 - 5.0.0": [
{
"type": "api",
"map": {
"input\\s*\\.\\s*loudness\\s*\\(": "input.soundLevel(",
"Motor\\s*\\.\\s*AB": "Motor.M0_M1",
"Motor\\s*\\.\\s*A": "Motor.M0",
"Motor\\s*\\.\\s*B": "Motor.M1"
}
}
]
},
"hidSelectors": [{
Expand Down

0 comments on commit ec0360e

Please sign in to comment.