From e505c63d16aa8badf1b4f6597ad6b739192b9f3a Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Wed, 7 Feb 2024 10:33:29 -0800 Subject: [PATCH] Add support for tilemaps with 4x4 tiles --- pxtblocks/fields/field_tilemap.ts | 9 ++++++++- pxtblocks/fields/field_tileset.ts | 3 ++- pxteditor/monaco-fields/field_tilemap.ts | 5 ++++- pxtlib/spriteutils.ts | 4 ++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pxtblocks/fields/field_tilemap.ts b/pxtblocks/fields/field_tilemap.ts index 31cbe8a3c010..20215b205b72 100644 --- a/pxtblocks/fields/field_tilemap.ts +++ b/pxtblocks/fields/field_tilemap.ts @@ -16,7 +16,7 @@ namespace pxtblockly { initWidth: number; initHeight: number; disableResize: boolean; - tileWidth: 8 | 16 | 32; + tileWidth: 4 | 8 | 16 | 32; filter?: string; lightMode: boolean; } @@ -107,6 +107,9 @@ namespace pxtblockly { if (opts.tileWidth) { if (typeof opts.tileWidth === "number") { switch (opts.tileWidth) { + case 4: + parsed.tileWidth = 4; + break; case 8: parsed.tileWidth = 8; break; @@ -121,6 +124,10 @@ namespace pxtblockly { else { const tw = opts.tileWidth.trim().toLowerCase(); switch (tw) { + case "4": + case "four": + parsed.tileWidth = 4; + break; case "8": case "eight": parsed.tileWidth = 8; diff --git a/pxtblocks/fields/field_tileset.ts b/pxtblocks/fields/field_tileset.ts index d87590053d60..ab3cdda3ae27 100644 --- a/pxtblocks/fields/field_tileset.ts +++ b/pxtblocks/fields/field_tileset.ts @@ -28,7 +28,7 @@ namespace pxtblockly { FieldTileset.cachedWorkspaceId = workspace.id; const references = getAllReferencedTiles(workspace); - const supportedTileWidths = [16, 8, 32]; + const supportedTileWidths = [16, 4, 8, 32]; for (const width of supportedTileWidths) { const projectTiles = project.getProjectTiles(width, width === 16); @@ -244,6 +244,7 @@ namespace pxtblockly { switch (id) { case "myTiles.transparency16": return 1; + case "myTiles.transparency4": case "myTiles.transparency8": case "myTiles.transparency32": return 2; diff --git a/pxteditor/monaco-fields/field_tilemap.ts b/pxteditor/monaco-fields/field_tilemap.ts index b0cacd0b6e29..a207108be603 100644 --- a/pxteditor/monaco-fields/field_tilemap.ts +++ b/pxteditor/monaco-fields/field_tilemap.ts @@ -37,7 +37,7 @@ export class MonacoTilemapEditor extends MonacoReactFieldEditor