pxt-core 8.4.1 → 8.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/backendutils.js +1 -0
- package/built/cli.js +83 -75
- package/built/pxt.js +1274 -179
- package/built/pxtblockly.js +323 -40
- package/built/pxtblocks.d.ts +30 -7
- package/built/pxtblocks.js +324 -41
- package/built/pxteditor.d.ts +2 -0
- package/built/pxtlib.d.ts +91 -5
- package/built/pxtlib.js +1183 -101
- package/built/pxtsim.js +8 -3
- package/built/server.js +4 -0
- package/built/target.js +1 -1
- package/built/web/main.js +1 -1
- package/built/web/multiplayer/css/main.2dd69ed8.css +4 -0
- package/built/web/multiplayer/js/main.f3b8f930.js +2 -0
- package/built/web/pxtapp.js +1 -1
- package/built/web/pxtasseteditor.js +1 -1
- package/built/web/pxtblockly.js +1 -1
- package/built/web/pxtblocks.js +1 -1
- package/built/web/pxtembed.js +2 -2
- package/built/web/pxtlib.js +1 -1
- package/built/web/pxtsim.js +1 -1
- package/built/web/pxtworker.js +2 -2
- package/built/web/react-common-authcode.css +4 -6993
- package/built/web/react-common-multiplayer.css +13 -0
- package/built/web/react-common-skillmap.css +1 -1
- package/built/web/rtlreact-common-authcode.css +13 -0
- package/built/web/rtlreact-common-multiplayer.css +13 -0
- package/built/web/rtlreact-common-skillmap.css +1 -1
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/semantic.css +1 -1
- package/built/web/skillmap/js/main.a6cf40e1.chunk.js +1 -0
- package/common-docs/identity/sign-in.md +17 -3
- package/common-docs/static/music-editor/apple.png +0 -0
- package/common-docs/static/music-editor/burger.png +0 -0
- package/common-docs/static/music-editor/cake.png +0 -0
- package/common-docs/static/music-editor/car.png +0 -0
- package/common-docs/static/music-editor/cat.png +0 -0
- package/common-docs/static/music-editor/cherry.png +0 -0
- package/common-docs/static/music-editor/clam.png +0 -0
- package/common-docs/static/music-editor/computer.png +0 -0
- package/common-docs/static/music-editor/crab.png +0 -0
- package/common-docs/static/music-editor/dog.png +0 -0
- package/common-docs/static/music-editor/duck.png +0 -0
- package/common-docs/static/music-editor/egg.png +0 -0
- package/common-docs/static/music-editor/explosion.png +0 -0
- package/common-docs/static/music-editor/fish.png +0 -0
- package/common-docs/static/music-editor/ice-cream.png +0 -0
- package/common-docs/static/music-editor/lemon.png +0 -0
- package/common-docs/static/music-editor/metronomeWorker.js +35 -0
- package/common-docs/static/music-editor/snake.png +0 -0
- package/common-docs/static/music-editor/star.png +0 -0
- package/common-docs/static/music-editor/strawberry.png +0 -0
- package/common-docs/static/music-editor/taco.png +0 -0
- package/common-docs/static/music-editor/treble-clef.svg +1 -0
- package/localtypings/projectheader.d.ts +1 -0
- package/package.json +4 -2
- package/react-common/components/controls/Input.tsx +7 -3
- package/react-common/components/share/Share.tsx +6 -2
- package/react-common/components/share/ShareInfo.tsx +12 -3
- package/react-common/styles/controls/Button.less +9 -0
- package/react-common/styles/react-common-authcode-core.less +1 -1
- package/react-common/styles/react-common-authcode.less +1 -1
- package/react-common/styles/react-common-multiplayer-core.less +10 -0
- package/react-common/styles/react-common-multiplayer.less +12 -0
- package/theme/highcontrast.less +14 -0
- package/theme/music-editor/EditControls.less +22 -0
- package/theme/music-editor/MusicEditor.less +25 -0
- package/theme/music-editor/Note.less +16 -0
- package/theme/music-editor/NoteGroup.less +7 -0
- package/theme/music-editor/PlaybackControls.less +55 -0
- package/theme/music-editor/ScrollableWorkspace.less +3 -0
- package/theme/music-editor/Staff.less +31 -0
- package/theme/music-editor/Track.less +0 -0
- package/theme/music-editor/TrackSelector.less +48 -0
- package/theme/music-editor/Workspace.less +3 -0
- package/theme/pxt.less +1 -0
- package/theme/tutorial-sidebar.less +19 -3
- package/theme/tutorial.less +2 -2
- package/webapp/public/multiplayer.html +1 -1
- package/webapp/public/skillmap.html +1 -1
- package/built/web/skillmap/js/main.6fa0eaff.chunk.js +0 -1
package/built/pxtblocks.js
CHANGED
|
@@ -2401,6 +2401,7 @@ var pxt;
|
|
|
2401
2401
|
registerFieldEditor('melody', pxtblockly.FieldCustomMelody);
|
|
2402
2402
|
registerFieldEditor('soundeffect', pxtblockly.FieldSoundEffect);
|
|
2403
2403
|
registerFieldEditor('autocomplete', pxtblockly.FieldAutoComplete);
|
|
2404
|
+
registerFieldEditor('musiceditor', pxtblockly.FieldMusicEditor);
|
|
2404
2405
|
}
|
|
2405
2406
|
blocks.initFieldEditors = initFieldEditors;
|
|
2406
2407
|
function registerFieldEditor(selector, field, validator) {
|
|
@@ -8022,50 +8023,159 @@ var pxtblockly;
|
|
|
8022
8023
|
const project = pxt.react.getTilemapProject();
|
|
8023
8024
|
pxt.sprite.addMissingTilemapTilesAndReferences(project, this.asset);
|
|
8024
8025
|
break;
|
|
8026
|
+
case "song" /* pxt.AssetType.Song */:
|
|
8027
|
+
editorKind = "music-editor";
|
|
8028
|
+
params.temporaryAssets = pxtblockly.getTemporaryAssets(this.sourceBlock_.workspace, "song" /* pxt.AssetType.Song */);
|
|
8029
|
+
pxtblockly.setMelodyEditorOpen(this.sourceBlock_, true);
|
|
8030
|
+
break;
|
|
8031
|
+
}
|
|
8032
|
+
if (this.isFullscreen()) {
|
|
8033
|
+
this.showEditorFullscreen(editorKind, params);
|
|
8034
|
+
}
|
|
8035
|
+
else {
|
|
8036
|
+
this.showEditorInWidgetDiv(editorKind, params);
|
|
8025
8037
|
}
|
|
8038
|
+
}
|
|
8039
|
+
showEditorFullscreen(editorKind, params) {
|
|
8026
8040
|
const fv = pxt.react.getFieldEditorView(editorKind, this.asset, params);
|
|
8027
8041
|
if (this.undoRedoState) {
|
|
8028
8042
|
fv.restorePersistentData(this.undoRedoState);
|
|
8029
8043
|
}
|
|
8030
8044
|
pxt.react.getTilemapProject().pushUndo();
|
|
8031
8045
|
fv.onHide(() => {
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8046
|
+
this.onFieldEditorHide(fv);
|
|
8047
|
+
});
|
|
8048
|
+
fv.show();
|
|
8049
|
+
}
|
|
8050
|
+
showEditorInWidgetDiv(editorKind, params) {
|
|
8051
|
+
let bbox;
|
|
8052
|
+
// This is due to the changes in https://github.com/microsoft/pxt-blockly/pull/289
|
|
8053
|
+
// which caused the widgetdiv to jump around if any fields underneath changed size
|
|
8054
|
+
let widgetOwner = {
|
|
8055
|
+
getScaledBBox: () => bbox
|
|
8056
|
+
};
|
|
8057
|
+
Blockly.WidgetDiv.show(widgetOwner, this.sourceBlock_.RTL, () => {
|
|
8058
|
+
if (document.activeElement && document.activeElement.tagName === "INPUT")
|
|
8059
|
+
document.activeElement.blur();
|
|
8060
|
+
fv.hide();
|
|
8061
|
+
widgetDiv.classList.remove("sound-effect-editor-widget");
|
|
8062
|
+
widgetDiv.style.transform = "";
|
|
8063
|
+
widgetDiv.style.position = "";
|
|
8064
|
+
widgetDiv.style.left = "";
|
|
8065
|
+
widgetDiv.style.top = "";
|
|
8066
|
+
widgetDiv.style.width = "";
|
|
8067
|
+
widgetDiv.style.height = "";
|
|
8068
|
+
widgetDiv.style.opacity = "";
|
|
8069
|
+
widgetDiv.style.transition = "";
|
|
8070
|
+
widgetDiv.style.alignItems = "";
|
|
8071
|
+
this.onFieldEditorHide(fv);
|
|
8072
|
+
});
|
|
8073
|
+
const widgetDiv = Blockly.WidgetDiv.DIV;
|
|
8074
|
+
const fv = pxt.react.getFieldEditorView(editorKind, this.asset, params, widgetDiv);
|
|
8075
|
+
const block = this.sourceBlock_;
|
|
8076
|
+
const bounds = block.getBoundingRectangle();
|
|
8077
|
+
const coord = pxtblockly.workspaceToScreenCoordinates(block.workspace, new Blockly.utils.Coordinate(bounds.right, bounds.top));
|
|
8078
|
+
const animationDistance = 20;
|
|
8079
|
+
const left = coord.x - 400;
|
|
8080
|
+
const top = coord.y + 60 - animationDistance;
|
|
8081
|
+
widgetDiv.style.opacity = "0";
|
|
8082
|
+
widgetDiv.classList.add("sound-effect-editor-widget");
|
|
8083
|
+
widgetDiv.style.position = "absolute";
|
|
8084
|
+
widgetDiv.style.left = left + "px";
|
|
8085
|
+
widgetDiv.style.top = top + "px";
|
|
8086
|
+
widgetDiv.style.width = "50rem";
|
|
8087
|
+
widgetDiv.style.height = "34.25rem";
|
|
8088
|
+
widgetDiv.style.display = "flex";
|
|
8089
|
+
widgetDiv.style.alignItems = "center";
|
|
8090
|
+
widgetDiv.style.transition = "transform 0.25s ease 0s, opacity 0.25s ease 0s";
|
|
8091
|
+
widgetDiv.style.borderRadius = "";
|
|
8092
|
+
fv.onHide(() => {
|
|
8093
|
+
Blockly.WidgetDiv.hideIfOwner(widgetOwner);
|
|
8094
|
+
});
|
|
8095
|
+
fv.show();
|
|
8096
|
+
const divBounds = widgetDiv.getBoundingClientRect();
|
|
8097
|
+
const injectDivBounds = block.workspace.getInjectionDiv().getBoundingClientRect();
|
|
8098
|
+
if (divBounds.height > injectDivBounds.height) {
|
|
8099
|
+
widgetDiv.style.height = "";
|
|
8100
|
+
widgetDiv.style.top = `calc(1rem - ${animationDistance}px)`;
|
|
8101
|
+
widgetDiv.style.bottom = `calc(1rem + ${animationDistance}px)`;
|
|
8102
|
+
}
|
|
8103
|
+
else {
|
|
8104
|
+
if (divBounds.bottom > injectDivBounds.bottom || divBounds.top < injectDivBounds.top) {
|
|
8105
|
+
// This editor is pretty tall, so just center vertically on the inject div
|
|
8106
|
+
widgetDiv.style.top = (injectDivBounds.top + (injectDivBounds.height / 2) - (divBounds.height / 2)) - animationDistance + "px";
|
|
8107
|
+
}
|
|
8108
|
+
}
|
|
8109
|
+
const toolboxWidth = block.workspace.getToolbox().getWidth();
|
|
8110
|
+
const workspaceLeft = injectDivBounds.left + toolboxWidth;
|
|
8111
|
+
if (divBounds.width > injectDivBounds.width - toolboxWidth) {
|
|
8112
|
+
widgetDiv.style.width = "";
|
|
8113
|
+
widgetDiv.style.left = "1rem";
|
|
8114
|
+
widgetDiv.style.right = "1rem";
|
|
8115
|
+
}
|
|
8116
|
+
else {
|
|
8117
|
+
// Check to see if we are bleeding off the right side of the canvas
|
|
8118
|
+
if (divBounds.left + divBounds.width >= injectDivBounds.right) {
|
|
8119
|
+
// If so, try and place to the left of the block instead of the right
|
|
8120
|
+
const blockLeft = pxtblockly.workspaceToScreenCoordinates(block.workspace, new Blockly.utils.Coordinate(bounds.left, bounds.top));
|
|
8121
|
+
if (blockLeft.x - divBounds.width - 20 > workspaceLeft) {
|
|
8122
|
+
widgetDiv.style.left = (blockLeft.x - divBounds.width - 20) + "px";
|
|
8064
8123
|
}
|
|
8065
|
-
|
|
8124
|
+
else {
|
|
8125
|
+
// As a last resort, just center on the inject div
|
|
8126
|
+
widgetDiv.style.left = (workspaceLeft + ((injectDivBounds.width - toolboxWidth) / 2) - divBounds.width / 2) + "px";
|
|
8127
|
+
}
|
|
8128
|
+
}
|
|
8129
|
+
else if (divBounds.left < injectDivBounds.left) {
|
|
8130
|
+
widgetDiv.style.left = workspaceLeft + "px";
|
|
8066
8131
|
}
|
|
8132
|
+
}
|
|
8133
|
+
const finalDimensions = widgetDiv.getBoundingClientRect();
|
|
8134
|
+
bbox = new Blockly.utils.Rect(finalDimensions.top, finalDimensions.bottom, finalDimensions.left, finalDimensions.right);
|
|
8135
|
+
requestAnimationFrame(() => {
|
|
8136
|
+
widgetDiv.style.opacity = "1";
|
|
8137
|
+
widgetDiv.style.transform = `translateY(${animationDistance}px)`;
|
|
8067
8138
|
});
|
|
8068
|
-
|
|
8139
|
+
}
|
|
8140
|
+
onFieldEditorHide(fv) {
|
|
8141
|
+
var _a;
|
|
8142
|
+
const result = fv.getResult();
|
|
8143
|
+
const project = pxt.react.getTilemapProject();
|
|
8144
|
+
if (this.asset.type === "song" /* pxt.AssetType.Song */) {
|
|
8145
|
+
pxtblockly.setMelodyEditorOpen(this.sourceBlock_, false);
|
|
8146
|
+
}
|
|
8147
|
+
if (result) {
|
|
8148
|
+
const old = this.getValue();
|
|
8149
|
+
if (pxt.assetEquals(this.asset, result))
|
|
8150
|
+
return;
|
|
8151
|
+
const oldId = isTemporaryAsset(this.asset) ? null : this.asset.id;
|
|
8152
|
+
let newId = isTemporaryAsset(result) ? null : result.id;
|
|
8153
|
+
if (!oldId && newId === this.sourceBlock_.id) {
|
|
8154
|
+
// The temporary assets we create just use the block id as the id; give it something
|
|
8155
|
+
// a little nicer
|
|
8156
|
+
result.id = project.generateNewID(result.type);
|
|
8157
|
+
newId = result.id;
|
|
8158
|
+
}
|
|
8159
|
+
this.pendingEdit = true;
|
|
8160
|
+
if ((_a = result.meta) === null || _a === void 0 ? void 0 : _a.displayName)
|
|
8161
|
+
this.disposeOfTemporaryAsset();
|
|
8162
|
+
this.asset = result;
|
|
8163
|
+
const lastRevision = project.revision();
|
|
8164
|
+
this.onEditorClose(this.asset);
|
|
8165
|
+
this.updateAssetListener();
|
|
8166
|
+
this.updateAssetMeta();
|
|
8167
|
+
this.redrawPreview();
|
|
8168
|
+
this.undoRedoState = fv.getPersistentData();
|
|
8169
|
+
if (this.sourceBlock_ && Blockly.Events.isEnabled()) {
|
|
8170
|
+
const event = new BlocklyTilemapChange(this.sourceBlock_, 'field', this.name, old, this.getValue(), lastRevision, project.revision());
|
|
8171
|
+
if (oldId !== newId) {
|
|
8172
|
+
event.oldAssetId = oldId;
|
|
8173
|
+
event.newAssetId = newId;
|
|
8174
|
+
}
|
|
8175
|
+
Blockly.Events.fire(event);
|
|
8176
|
+
}
|
|
8177
|
+
this.pendingEdit = false;
|
|
8178
|
+
}
|
|
8069
8179
|
}
|
|
8070
8180
|
render_() {
|
|
8071
8181
|
if (this.isGreyBlock && !this.textElement_) {
|
|
@@ -8163,12 +8273,17 @@ var pxtblockly;
|
|
|
8163
8273
|
case "tilemap" /* pxt.AssetType.Tilemap */:
|
|
8164
8274
|
dataURI = pxtblockly.tilemapToImageURI(this.asset.data, PREVIEW_WIDTH, this.lightMode);
|
|
8165
8275
|
break;
|
|
8276
|
+
case "song" /* pxt.AssetType.Song */:
|
|
8277
|
+
dataURI = pxtblockly.songToDataURI(this.asset.song, 60, 20, this.lightMode);
|
|
8278
|
+
break;
|
|
8279
|
+
}
|
|
8280
|
+
if (dataURI) {
|
|
8281
|
+
const img = new svg.Image()
|
|
8282
|
+
.src(dataURI)
|
|
8283
|
+
.at(X_PADDING + BG_PADDING, Y_PADDING + BG_PADDING)
|
|
8284
|
+
.size(PREVIEW_WIDTH, PREVIEW_WIDTH);
|
|
8285
|
+
this.fieldGroup_.appendChild(img.el);
|
|
8166
8286
|
}
|
|
8167
|
-
const img = new svg.Image()
|
|
8168
|
-
.src(dataURI)
|
|
8169
|
-
.at(X_PADDING + BG_PADDING, Y_PADDING + BG_PADDING)
|
|
8170
|
-
.size(PREVIEW_WIDTH, PREVIEW_WIDTH);
|
|
8171
|
-
this.fieldGroup_.appendChild(img.el);
|
|
8172
8287
|
}
|
|
8173
8288
|
}
|
|
8174
8289
|
parseValueText(newText) {
|
|
@@ -8259,6 +8374,9 @@ var pxtblockly;
|
|
|
8259
8374
|
pxt.react.getTilemapProject().addChangeListener(this.asset, this.assetChangeListener);
|
|
8260
8375
|
}
|
|
8261
8376
|
}
|
|
8377
|
+
isFullscreen() {
|
|
8378
|
+
return true;
|
|
8379
|
+
}
|
|
8262
8380
|
}
|
|
8263
8381
|
pxtblockly.FieldAssetEditor = FieldAssetEditor;
|
|
8264
8382
|
function isTemporaryAsset(asset) {
|
|
@@ -10325,13 +10443,13 @@ var pxtblockly;
|
|
|
10325
10443
|
this.prevString = this.getValue();
|
|
10326
10444
|
// The webapp listens to this event and stops the simulator so that you don't get the melody
|
|
10327
10445
|
// playing twice (once in the editor and once when the code runs in the sim)
|
|
10328
|
-
|
|
10446
|
+
pxtblockly.setMelodyEditorOpen(this.sourceBlock_, true);
|
|
10329
10447
|
Blockly.DropDownDiv.showPositionedByBlock(this, this.sourceBlock_, () => {
|
|
10330
10448
|
this.onEditorClose();
|
|
10331
10449
|
// revert all style attributes for dropdown div
|
|
10332
10450
|
pxt.BrowserUtils.removeClass(contentDiv, "melody-content-div");
|
|
10333
10451
|
pxt.BrowserUtils.removeClass(contentDiv.parentElement, "melody-editor-dropdown");
|
|
10334
|
-
|
|
10452
|
+
pxtblockly.setMelodyEditorOpen(this.sourceBlock_, false);
|
|
10335
10453
|
});
|
|
10336
10454
|
}
|
|
10337
10455
|
getValue() {
|
|
@@ -10999,6 +11117,116 @@ var pxtblockly;
|
|
|
10999
11117
|
return "#DCDCDC";
|
|
11000
11118
|
}
|
|
11001
11119
|
})(pxtblockly || (pxtblockly = {}));
|
|
11120
|
+
/// <reference path="../../built/pxtlib.d.ts" />
|
|
11121
|
+
/// <reference path="./field_asset.ts" />
|
|
11122
|
+
var pxtblockly;
|
|
11123
|
+
(function (pxtblockly) {
|
|
11124
|
+
var svg = pxt.svgUtil;
|
|
11125
|
+
const PREVIEW_HEIGHT = 32;
|
|
11126
|
+
const X_PADDING = 5;
|
|
11127
|
+
const Y_PADDING = 1;
|
|
11128
|
+
const BG_PADDING = 4;
|
|
11129
|
+
const BG_HEIGHT = BG_PADDING * 2 + PREVIEW_HEIGHT;
|
|
11130
|
+
const TOTAL_HEIGHT = Y_PADDING * 2 + BG_PADDING * 2 + PREVIEW_HEIGHT;
|
|
11131
|
+
class FieldMusicEditor extends pxtblockly.FieldAssetEditor {
|
|
11132
|
+
getAssetType() {
|
|
11133
|
+
return "song" /* pxt.AssetType.Song */;
|
|
11134
|
+
}
|
|
11135
|
+
createNewAsset(text) {
|
|
11136
|
+
const project = pxt.react.getTilemapProject();
|
|
11137
|
+
if (text) {
|
|
11138
|
+
const asset = pxt.lookupProjectAssetByTSReference(text, project);
|
|
11139
|
+
if (asset)
|
|
11140
|
+
return asset;
|
|
11141
|
+
}
|
|
11142
|
+
if (this.getBlockData()) {
|
|
11143
|
+
return project.lookupAsset("song" /* pxt.AssetType.Song */, this.getBlockData());
|
|
11144
|
+
}
|
|
11145
|
+
let song;
|
|
11146
|
+
if (text) {
|
|
11147
|
+
const match = /^\s*hex\s*`([a-fA-F0-9]+)`\s*(?:;?)\s*$/.exec(text);
|
|
11148
|
+
if (match) {
|
|
11149
|
+
song = pxt.assets.music.decodeSongFromHex(match[1]);
|
|
11150
|
+
}
|
|
11151
|
+
}
|
|
11152
|
+
else {
|
|
11153
|
+
song = pxt.assets.music.getEmptySong(2);
|
|
11154
|
+
}
|
|
11155
|
+
if (!song) {
|
|
11156
|
+
this.isGreyBlock = true;
|
|
11157
|
+
this.valueText = text;
|
|
11158
|
+
return undefined;
|
|
11159
|
+
}
|
|
11160
|
+
else {
|
|
11161
|
+
// Restore all of the unused tracks
|
|
11162
|
+
pxt.assets.music.inflateSong(song);
|
|
11163
|
+
}
|
|
11164
|
+
const newAsset = {
|
|
11165
|
+
internalID: -1,
|
|
11166
|
+
id: this.sourceBlock_.id,
|
|
11167
|
+
type: "song" /* pxt.AssetType.Song */,
|
|
11168
|
+
meta: {},
|
|
11169
|
+
song
|
|
11170
|
+
};
|
|
11171
|
+
return newAsset;
|
|
11172
|
+
}
|
|
11173
|
+
render_() {
|
|
11174
|
+
super.render_();
|
|
11175
|
+
if (!this.isGreyBlock) {
|
|
11176
|
+
this.size_.height = TOTAL_HEIGHT;
|
|
11177
|
+
this.size_.width = X_PADDING * 2 + BG_PADDING * 2 + this.previewWidth();
|
|
11178
|
+
}
|
|
11179
|
+
}
|
|
11180
|
+
getValueText() {
|
|
11181
|
+
if (this.asset && !this.isTemporaryAsset()) {
|
|
11182
|
+
return pxt.getTSReferenceForAsset(this.asset);
|
|
11183
|
+
}
|
|
11184
|
+
return this.asset ? `hex\`${pxt.assets.music.encodeSongToHex(this.asset.song)}\`` : "";
|
|
11185
|
+
}
|
|
11186
|
+
parseFieldOptions(opts) {
|
|
11187
|
+
return {};
|
|
11188
|
+
}
|
|
11189
|
+
isFullscreen() {
|
|
11190
|
+
return false;
|
|
11191
|
+
}
|
|
11192
|
+
redrawPreview() {
|
|
11193
|
+
var _a;
|
|
11194
|
+
if (!this.fieldGroup_)
|
|
11195
|
+
return;
|
|
11196
|
+
pxsim.U.clear(this.fieldGroup_);
|
|
11197
|
+
if (this.isGreyBlock) {
|
|
11198
|
+
super.redrawPreview();
|
|
11199
|
+
return;
|
|
11200
|
+
}
|
|
11201
|
+
const totalWidth = X_PADDING * 2 + BG_PADDING * 2 + this.previewWidth();
|
|
11202
|
+
const bg = new svg.Rect()
|
|
11203
|
+
.at(X_PADDING, Y_PADDING)
|
|
11204
|
+
.size(BG_PADDING * 2 + this.previewWidth(), BG_HEIGHT)
|
|
11205
|
+
.setClass("blocklySpriteField")
|
|
11206
|
+
.stroke("#898989", 1)
|
|
11207
|
+
.corner(4);
|
|
11208
|
+
this.fieldGroup_.appendChild(bg.el);
|
|
11209
|
+
if (this.asset) {
|
|
11210
|
+
const dataURI = pxtblockly.songToDataURI(this.asset.song, this.previewWidth(), PREVIEW_HEIGHT, this.lightMode);
|
|
11211
|
+
if (dataURI) {
|
|
11212
|
+
const img = new svg.Image()
|
|
11213
|
+
.src(dataURI)
|
|
11214
|
+
.at(X_PADDING + BG_PADDING, Y_PADDING + BG_PADDING)
|
|
11215
|
+
.size(this.previewWidth(), PREVIEW_HEIGHT);
|
|
11216
|
+
this.fieldGroup_.appendChild(img.el);
|
|
11217
|
+
}
|
|
11218
|
+
}
|
|
11219
|
+
if (((_a = this.size_) === null || _a === void 0 ? void 0 : _a.width) != totalWidth) {
|
|
11220
|
+
this.forceRerender();
|
|
11221
|
+
}
|
|
11222
|
+
}
|
|
11223
|
+
previewWidth() {
|
|
11224
|
+
const measures = this.asset ? this.asset.song.measures : 2;
|
|
11225
|
+
return measures * PREVIEW_HEIGHT;
|
|
11226
|
+
}
|
|
11227
|
+
}
|
|
11228
|
+
pxtblockly.FieldMusicEditor = FieldMusicEditor;
|
|
11229
|
+
})(pxtblockly || (pxtblockly = {}));
|
|
11002
11230
|
/// <reference path="../../localtypings/pxtblockly.d.ts" />
|
|
11003
11231
|
var pxtblockly;
|
|
11004
11232
|
(function (pxtblockly) {
|
|
@@ -13534,6 +13762,54 @@ var pxtblockly;
|
|
|
13534
13762
|
return canvas.toDataURL();
|
|
13535
13763
|
}
|
|
13536
13764
|
pxtblockly.tilemapToImageURI = tilemapToImageURI;
|
|
13765
|
+
function songToDataURI(song, width, height, lightMode, maxMeasures) {
|
|
13766
|
+
const colors = pxt.appTarget.runtime.palette.slice();
|
|
13767
|
+
const canvas = document.createElement("canvas");
|
|
13768
|
+
canvas.width = width;
|
|
13769
|
+
canvas.height = height;
|
|
13770
|
+
let context;
|
|
13771
|
+
if (lightMode) {
|
|
13772
|
+
context = canvas.getContext("2d", { alpha: false });
|
|
13773
|
+
context.fillStyle = "#dedede";
|
|
13774
|
+
context.fillRect(0, 0, width, height);
|
|
13775
|
+
}
|
|
13776
|
+
else {
|
|
13777
|
+
context = canvas.getContext("2d");
|
|
13778
|
+
}
|
|
13779
|
+
const trackColors = [
|
|
13780
|
+
5,
|
|
13781
|
+
11,
|
|
13782
|
+
5,
|
|
13783
|
+
4,
|
|
13784
|
+
2,
|
|
13785
|
+
6,
|
|
13786
|
+
14,
|
|
13787
|
+
2,
|
|
13788
|
+
5,
|
|
13789
|
+
1, // explosion
|
|
13790
|
+
];
|
|
13791
|
+
maxMeasures = maxMeasures || song.measures;
|
|
13792
|
+
const cellWidth = Math.max(Math.floor(width / (song.beatsPerMeasure * maxMeasures * 2)), 1);
|
|
13793
|
+
const cellsShown = Math.floor(width / cellWidth);
|
|
13794
|
+
const cellHeight = Math.max(Math.floor(height / 12), 1);
|
|
13795
|
+
const notesShown = Math.floor(height / cellHeight);
|
|
13796
|
+
for (const track of song.tracks) {
|
|
13797
|
+
for (const noteEvent of track.notes) {
|
|
13798
|
+
const col = Math.floor(noteEvent.startTick / (song.ticksPerBeat / 2));
|
|
13799
|
+
if (col > cellsShown)
|
|
13800
|
+
break;
|
|
13801
|
+
for (const note of noteEvent.notes) {
|
|
13802
|
+
const row = 12 - (note % 12);
|
|
13803
|
+
if (row > notesShown)
|
|
13804
|
+
continue;
|
|
13805
|
+
context.fillStyle = colors[trackColors[track.id || song.tracks.indexOf(track)]];
|
|
13806
|
+
context.fillRect(col * cellWidth, row * cellHeight, cellWidth, cellHeight);
|
|
13807
|
+
}
|
|
13808
|
+
}
|
|
13809
|
+
}
|
|
13810
|
+
return canvas.toDataURL();
|
|
13811
|
+
}
|
|
13812
|
+
pxtblockly.songToDataURI = songToDataURI;
|
|
13537
13813
|
function deleteTilesetTileIfExists(ws, tile) {
|
|
13538
13814
|
const existing = ws.getVariablesOfType(pxt.sprite.BLOCKLY_TILESET_TYPE);
|
|
13539
13815
|
for (const model of existing) {
|
|
@@ -13669,10 +13945,17 @@ var pxtblockly;
|
|
|
13669
13945
|
case "animation" /* pxt.AssetType.Animation */:
|
|
13670
13946
|
return getAllFields(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
|
|
13671
13947
|
.map(f => f.ref.getAsset());
|
|
13948
|
+
case "song" /* pxt.AssetType.Song */:
|
|
13949
|
+
return getAllFields(workspace, field => field instanceof pxtblockly.FieldMusicEditor && field.isTemporaryAsset())
|
|
13950
|
+
.map(f => f.ref.getAsset());
|
|
13672
13951
|
default: return [];
|
|
13673
13952
|
}
|
|
13674
13953
|
}
|
|
13675
13954
|
pxtblockly.getTemporaryAssets = getTemporaryAssets;
|
|
13955
|
+
function setMelodyEditorOpen(block, isOpen) {
|
|
13956
|
+
Blockly.Events.fire(new Blockly.Events.Ui(block, "melody-editor", !isOpen, isOpen));
|
|
13957
|
+
}
|
|
13958
|
+
pxtblockly.setMelodyEditorOpen = setMelodyEditorOpen;
|
|
13676
13959
|
function workspaceToScreenCoordinates(ws, wsCoordinates) {
|
|
13677
13960
|
// The position in pixels relative to the origin of the
|
|
13678
13961
|
// main workspace.
|
package/built/pxteditor.d.ts
CHANGED
|
@@ -344,6 +344,8 @@ declare namespace pxt.editor {
|
|
|
344
344
|
convertCloudProjectsToLocal(userId: string): Promise<void>;
|
|
345
345
|
setLanguageRestrictionAsync(restriction: pxt.editor.LanguageRestriction): Promise<void>;
|
|
346
346
|
hasHeaderBeenPersistentShared(): boolean;
|
|
347
|
+
getSharePreferenceForHeader(): boolean;
|
|
348
|
+
saveSharePreferenceForHeaderAsync(anonymousByDefault: boolean): Promise<void>;
|
|
347
349
|
}
|
|
348
350
|
interface IHexFileImporter {
|
|
349
351
|
id: string;
|