From ec0360ed4742718b9f6ac12776ee6dc7a944ab3e Mon Sep 17 00:00:00 2001 From: Amerlander Date: Wed, 22 Nov 2023 15:11:20 +0100 Subject: [PATCH] aply code mappings and block patches --- docs/static/icons/manifest.json | 7 +--- editor/patch.ts | 34 +++++++++++++++++-- .../_locales/core-mini-dal-jsdoc-strings.json | 1 - .../_locales/core-mini-dal-strings.json | 1 - libs/core-mini-dal/microphone.ts | 15 -------- libs/core-mini-dal/pxt.json | 1 - libs/core/microphone.cpp | 3 +- libs/core/shims.d.ts | 2 +- pxtarget.json | 11 ++++++ 9 files changed, 46 insertions(+), 29 deletions(-) delete mode 100644 libs/core-mini-dal/microphone.ts diff --git a/docs/static/icons/manifest.json b/docs/static/icons/manifest.json index 339e99bac..0c744cf48 100644 --- a/docs/static/icons/manifest.json +++ b/docs/static/icons/manifest.json @@ -1,5 +1,5 @@ { - "name": "makecode.microbit.org", + "name": "makecode.calliope.cc", "icons": [ { "src": "\/android-chrome-36x36.png", @@ -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", diff --git a/editor/patch.ts b/editor/patch.ts index 623063e16..f00a645c9 100644 --- a/editor/patch.ts +++ b/editor/patch.ts @@ -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 @@ -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 /** * @@ -196,6 +223,7 @@ arrowImageNodes.forEach(node => { if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "5.0.12") <= 0) { + // Eighth note misspelling /* diff --git a/libs/core-mini-dal/_locales/core-mini-dal-jsdoc-strings.json b/libs/core-mini-dal/_locales/core-mini-dal-jsdoc-strings.json index 2cbc509d0..15723c3c2 100644 --- a/libs/core-mini-dal/_locales/core-mini-dal-jsdoc-strings.json +++ b/libs/core-mini-dal/_locales/core-mini-dal-jsdoc-strings.json @@ -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.", diff --git a/libs/core-mini-dal/_locales/core-mini-dal-strings.json b/libs/core-mini-dal/_locales/core-mini-dal-strings.json index 017045f18..faefd8c20 100644 --- a/libs/core-mini-dal/_locales/core-mini-dal-strings.json +++ b/libs/core-mini-dal/_locales/core-mini-dal-strings.json @@ -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", diff --git a/libs/core-mini-dal/microphone.ts b/libs/core-mini-dal/microphone.ts deleted file mode 100644 index c19042f79..000000000 --- a/libs/core-mini-dal/microphone.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Events and data from sensors - */ -//% color=#C90072 weight=99 -namespace input { - /** - * gets the level of loudness from 0 (silent) to 255 (loud) - */ - //% blockId="loudness" - //% block="Loudness" - //% deprecated=true - export function loudness(): number { - return input.soundLevel() - } -} diff --git a/libs/core-mini-dal/pxt.json b/libs/core-mini-dal/pxt.json index e3a939b54..094718992 100644 --- a/libs/core-mini-dal/pxt.json +++ b/libs/core-mini-dal/pxt.json @@ -11,7 +11,6 @@ "files": [ "shims.d.ts", "enums.d.ts", - "microphone.ts", "motors.ts", "parts/dcmotor.svg", "input.cpp", diff --git a/libs/core/microphone.cpp b/libs/core/microphone.cpp index 0a9d479ca..21979d0da 100644 --- a/libs/core/microphone.cpp +++ b/libs/core/microphone.cpp @@ -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" @@ -48,4 +48,5 @@ int soundLevel() { return level; #endif } + } \ No newline at end of file diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 92c424005..445578911 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -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 diff --git a/pxtarget.json b/pxtarget.json index 508507c84..ee5b9c1d6 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -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": [{