From dc36196b0f53c70fa4309f46cbf304dbd6347010 Mon Sep 17 00:00:00 2001 From: Kim Ying <15070078+kimprice@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:41:24 -0800 Subject: [PATCH 1/3] Check for qualified name in sprite editor (#9789) * check for qualified name in sprite editor * check qName for sprite when converting back to js --- pxtblocks/fields/field_asset.ts | 2 ++ pxtblocks/fields/field_sprite.ts | 33 ++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pxtblocks/fields/field_asset.ts b/pxtblocks/fields/field_asset.ts index aec2912ae6a2..f90a1a697aa3 100644 --- a/pxtblocks/fields/field_asset.ts +++ b/pxtblocks/fields/field_asset.ts @@ -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; diff --git a/pxtblocks/fields/field_sprite.ts b/pxtblocks/fields/field_sprite.ts index b063d1b93286..8a3c619e8bfd 100644 --- a/pxtblocks/fields/field_sprite.ts +++ b/pxtblocks/fields/field_sprite.ts @@ -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, @@ -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); } @@ -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; } } From 11b30fa2d9895c8ce8af56d93609f2791730a308 Mon Sep 17 00:00:00 2001 From: Kim Ying <15070078+kimprice@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:46:33 -0800 Subject: [PATCH 2/3] 9.3.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 17ffbc6c9f55..369a84b4e722 100644 --- a/package.json +++ b/package.json @@ -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", From 40079fdcdc143dd6d462ece1eff8c4722e8d9be5 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 7 Dec 2023 20:10:06 -0800 Subject: [PATCH 3/3] Add index of the source iframe to the broadcast message (#9790) * Add index of the source iframe to the broadcast message * avoid using potentially filtered frame array --- pxtsim/embed.ts | 1 + pxtsim/simdriver.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pxtsim/embed.ts b/pxtsim/embed.ts index 0f3ecf99a416..59ed1873a763 100644 --- a/pxtsim/embed.ts +++ b/pxtsim/embed.ts @@ -83,6 +83,7 @@ namespace pxsim { export interface SimulatorBroadcastMessage extends SimulatorMessage { broadcast: boolean; toParentIFrameOnly?: boolean; + srcFrameIndex?: number; } export interface SimulatorControlMessage extends SimulatorBroadcastMessage { diff --git a/pxtsim/simdriver.ts b/pxtsim/simdriver.ts index 525189be2a48..2a1dbdc1814e 100644 --- a/pxtsim/simdriver.ts +++ b/pxtsim/simdriver.ts @@ -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;