Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support image editor for bmp in Monaco #9913

Merged
merged 7 commits into from
Mar 14, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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.match("\s*bmp") ? "bmp" : "img"
Fixed Show fixed Hide fixed

const match = pxt.parseAssetTSReference(text);
if (match) {
Expand All @@ -31,7 +33,7 @@
}
}

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 @@
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 @@
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