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

Add support for tilemaps with 4x4 tiles #9853

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion pxtblocks/fields/field_tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion pxtblocks/fields/field_tileset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -244,6 +244,7 @@ namespace pxtblockly {
switch (id) {
case "myTiles.transparency16":
return 1;
case "myTiles.transparency4":
case "myTiles.transparency8":
case "myTiles.transparency32":
return 2;
Expand Down
5 changes: 4 additions & 1 deletion pxteditor/monaco-fields/field_tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class MonacoTilemapEditor extends MonacoReactFieldEditor<pxt.ProjectTilem
this.isTilemapLiteral = true;

// This matches the regex for the field editor, so it should always match
const match = /^\s*(tilemap(?:8|16|32)?)\s*(?:`([^`]*)`)|(?:\(\s*"""([^"]*)"""\s*\))\s*$/.exec(text);
const match = /^\s*(tilemap(?:4|8|16|32)?)\s*(?:`([^`]*)`)|(?:\(\s*"""([^"]*)"""\s*\))\s*$/.exec(text);
const name = (match[2] || match[3] || "").trim();
this.tilemapLiteral = match[1];

Expand All @@ -57,6 +57,9 @@ export class MonacoTilemapEditor extends MonacoReactFieldEditor<pxt.ProjectTilem
else if (this.tilemapLiteral === "tilemap32") {
tileWidth = 32;
}
else if (this.tilemapLiteral === "tilemap4") {
tileWidth = 4;
}
const [ name ] = project.createNewTilemap(id, tileWidth, 16, 16);
proj = project.getTilemap(name);
id = name;
Expand Down
4 changes: 4 additions & 0 deletions pxtlib/spriteutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ namespace pxt.sprite {
return proj.getTransparency(16);
case "myTiles.transparency8":
return proj.getTransparency(8);
case "myTiles.transparency4":
return proj.getTransparency(4);
case "myTiles.transparency32":
return proj.getTransparency(32);
default:
Expand Down Expand Up @@ -804,6 +806,7 @@ namespace pxt.sprite {

export function tileWidthToTileScale(tileWidth: number) {
switch (tileWidth) {
case 4: return `TileScale.Four`;
case 8: return `TileScale.Eight`;
case 16: return `TileScale.Sixteen`;
case 32: return `TileScale.ThirtyTwo`;
Expand All @@ -814,6 +817,7 @@ namespace pxt.sprite {
export function tileScaleToTileWidth(tileScale: string) {
tileScale = tileScale.replace(/\s/g, "");
switch (tileScale) {
case `TileScale.Four`: return 4;
case `TileScale.Eight`: return 8;
case `TileScale.Sixteen`: return 16;
case `TileScale.ThirtyTwo`: return 32;
Expand Down