Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/microsoft/pxt into thspar…
Browse files Browse the repository at this point in the history
…ks/add_teacher_tools_react_app
  • Loading branch information
thsparks committed Dec 8, 2023
2 parents 4f63eaf + 40079fd commit c3d0776
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pxt-core",
"version": "9.3.7",
"version": "9.3.8",
"description": "Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors",
"keywords": [
"TypeScript",
Expand Down
2 changes: 2 additions & 0 deletions pxtblocks/fields/field_asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace pxtblockly {
protected pendingEdit = false;
protected isEmpty = false;

protected qName?: string;

// If input is invalid, the subclass can set this to be true. The field will instead
// render as a grey block and preserve the decompiled code
public isGreyBlock: boolean;
Expand Down
33 changes: 29 additions & 4 deletions pxtblocks/fields/field_sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ namespace pxtblockly {

const bmp = text ? pxt.sprite.imageLiteralToBitmap(text) : new pxt.sprite.Bitmap(this.params.initWidth, this.params.initHeight);

let data: pxt.sprite.BitmapData;

if (!bmp) {
this.isGreyBlock = true;
this.valueText = text;
return undefined;
// check for qualified name
data = qNameToBitmapData(text);
if (!data) {
this.isGreyBlock = true;
this.valueText = text;
return undefined;
} else {
this.qName = text;
}
}

const data = bmp.data();
if (!data) data = bmp.data();

const newAsset: pxt.ProjectImage = {
internalID: -1,
Expand All @@ -71,6 +79,12 @@ namespace pxtblockly {
protected getValueText(): string {
if (this.asset && !this.isTemporaryAsset()) {
return pxt.getTSReferenceForAsset(this.asset);
} else if (this.qName) {
// check if image has been edited
const data = qNameToBitmapData(this.qName);
if (data && pxt.sprite.bitmapEquals(data, (this.asset as pxt.ProjectImage).bitmap)) {
return this.qName;
}
}
return pxt.sprite.bitmapToImageLiteral(this.asset && pxt.sprite.Bitmap.fromData((this.asset as pxt.ProjectImage).bitmap), pxt.editor.FileType.TypeScript);
}
Expand Down Expand Up @@ -148,5 +162,16 @@ namespace pxtblockly {
}
return res;
}

}

function qNameToBitmapData(qName: string): pxt.sprite.BitmapData {
const project = pxt.react.getTilemapProject();
const images = project.getGalleryAssets(pxt.AssetType.Image).filter(asset => asset.id === qName);
const img = images.length && images[0];
if (img) {
return img.bitmap;
}
return undefined;
}
}
1 change: 1 addition & 0 deletions pxtsim/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace pxsim {
export interface SimulatorBroadcastMessage extends SimulatorMessage {
broadcast: boolean;
toParentIFrameOnly?: boolean;
srcFrameIndex?: number;
}

export interface SimulatorControlMessage extends SimulatorBroadcastMessage {
Expand Down
2 changes: 2 additions & 0 deletions pxtsim/simdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ namespace pxsim {

const broadcastmsg = msg as pxsim.SimulatorBroadcastMessage;
if (source && broadcastmsg?.broadcast) {
// include index of the source iframe
broadcastmsg.srcFrameIndex = this.simFrames().findIndex((item) => item.contentWindow === source)
// if the editor is hosted in a multi-editor setting
// don't start extra frames
const single = !!this._currentRuntime?.single;
Expand Down

0 comments on commit c3d0776

Please sign in to comment.