Skip to content

Commit 2d8dedc

Browse files
authored
don't parse junk tilemaps literally (#10477)
1 parent b5ea196 commit 2d8dedc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pxtlib/spriteutils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ namespace pxt.sprite {
248248
export function decodeTilemap(literal: string, fileType: "typescript" | "python", proj: TilemapProject): TilemapData {
249249
literal = Util.htmlUnescape(literal).trim();
250250

251-
if (!literal.trim()) {
251+
if (!literal.trim() || literal.indexOf("(") === -1) {
252252
return null;
253253
}
254254

pxtlib/tilemap.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,9 +1683,17 @@ namespace pxt {
16831683
const tmWidth = bytes[1] | (bytes[2] << 8);
16841684
const tmHeight = bytes[3] | (bytes[4] << 8);
16851685

1686+
const tiles: Tile[] = jres.tileset.map(id => (resolveTile && resolveTile(id)) || { id } as any);
1687+
let tileWidth = bytes[0];
1688+
1689+
if (!tileWidth) {
1690+
tileWidth = tiles.length && tiles.find(t => t.bitmap?.width)?.bitmap.width;
1691+
}
1692+
tileWidth = tileWidth || 16;
1693+
16861694
const tileset: TileSet = {
1687-
tileWidth: bytes[0],
1688-
tiles: jres.tileset.map(id => (resolveTile && resolveTile(id)) || { id } as any)
1695+
tileWidth,
1696+
tiles
16891697
};
16901698

16911699
const tilemapStart = 5;

0 commit comments

Comments
 (0)