Skip to content

Commit

Permalink
support image editor for bmp in Monaco (#9913)
Browse files Browse the repository at this point in the history
* check in

* flow bmp/img through code

* updates

* update

* oops!

* Update pxteditor/monaco-fields/field_sprite.ts

Co-authored-by: Richard Knoll <[email protected]>

---------

Co-authored-by: Richard Knoll <[email protected]>
  • Loading branch information
tballmsft and riknoll authored Mar 14, 2024
1 parent 91df577 commit 89d396f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pxteditor/monaco-fields/field_sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const fieldEditorId = "image-editor";
export class MonacoSpriteEditor extends MonacoReactFieldEditor<pxt.ProjectImage> {
protected isPython: boolean;
protected isAsset: boolean;
protected template: string;

protected textToValue(text: string): pxt.ProjectImage {
this.isPython = text.indexOf("`") === -1
this.template = text.startsWith("bmp") ? "bmp" : "img"

const match = pxt.parseAssetTSReference(text);
if (match) {
Expand All @@ -31,7 +33,7 @@ export class MonacoSpriteEditor extends MonacoReactFieldEditor<pxt.ProjectImage>
}
}

return createFakeAsset(pxt.sprite.imageLiteralToBitmap(text));
return createFakeAsset(pxt.sprite.imageLiteralToBitmap(text, this.template));
}

protected resultToText(result: pxt.ProjectImage): string {
Expand All @@ -45,7 +47,10 @@ export class MonacoSpriteEditor extends MonacoReactFieldEditor<pxt.ProjectImage>
this.isAsset = true;
return pxt.getTSReferenceForAsset(result, this.isPython);
}
return pxt.sprite.bitmapToImageLiteral(pxt.sprite.Bitmap.fromData(result.bitmap), this.isPython ? "python" : "typescript");
return pxt.sprite.bitmapToImageLiteral(pxt.sprite.Bitmap.fromData(result.bitmap),
this.isPython ? "python" : "typescript",
this.template
)
}

protected getFieldEditorId() {
Expand Down Expand Up @@ -78,7 +83,7 @@ export const spriteEditorDefinition: MonacoFieldEditorDefinition = {
heightInPixels: 510,
matcher: {
// match both JS and python
searchString: "(?:img|assets\\s*\\.\\s*image)\\s*(?:`|\\(\\s*\"\"\")(?:(?:[^(){}:\\[\\]\"';?/,+\\-=*&|^%!`~]|\\n)*)\\s*(?:`|\"\"\"\\s*\\))",
searchString: "(?:img|bmp|assets\\s*\\.\\s*image)\\s*(?:`|\\(\\s*\"\"\")(?:(?:[^(){}:\\[\\]\"';?/,+\\-=*&|^%!`~]|\\n)*)\\s*(?:`|\"\"\"\\s*\\))",
isRegex: true,
matchCase: true,
matchWholeWord: false
Expand Down

0 comments on commit 89d396f

Please sign in to comment.