Skip to content

Commit e3d0868

Browse files
authored
fix missing gallery, don't import gallery tiles into my tiles, fix null listener (#11125)
1 parent 8593270 commit e3d0868

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

pxtblocks/fields/field_tileset.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,20 @@ export class FieldTileset extends FieldImages implements FieldCustom {
289289
}
290290

291291
protected updateAssetListener() {
292+
if (!this.assetChangeListener) {
293+
this.assetChangeListener = () => {
294+
this.doValueUpdate_(this.getValue());
295+
this.forceRerender();
296+
};
297+
}
292298
const project = pxt.react.getTilemapProject();
293299
project.removeChangeListener(pxt.AssetType.Tile, this.assetChangeListener);
294300
if (this.selectedOption_) {
295301
project.addChangeListener(this.selectedOption_[2], this.assetChangeListener);
296302
}
297303
}
298304

299-
protected assetChangeListener = () => {
300-
this.doValueUpdate_(this.getValue());
301-
this.forceRerender();
302-
}
305+
protected assetChangeListener: () => void;
303306

304307
saveState(_doFullSerialization?: boolean) {
305308
let asset = this.localTile || this.selectedOption_?.[2];

webapp/src/components/ImageEditor/ImageEditor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Unsubscribe, Action } from 'redux';
1919
import { createNewImageAsset, getNewInternalID } from '../../assets';
2020
import { AssetEditorCore } from '../ImageFieldEditor';
2121
import { classList } from '../../../../react-common/components/util';
22+
import { BUILTIN_CATEGORIES } from './tilemap/TilePalette';
2223

2324
export const LIGHT_MODE_TRANSPARENT = "#dedede";
2425

@@ -220,7 +221,7 @@ export class ImageEditor extends React.Component<ImageEditorProps, ImageEditorSt
220221
const remappedByBitmap: pxt.Map<pxt.Tile> = {};
221222

222223
for (let i = 0; i < tiles.length; i++) {
223-
const tile = tiles[i];
224+
let tile = tiles[i];
224225
if (!tile) continue;
225226

226227
const key = (tile as any).jresData || (tile.bitmap ? pxt.sprite.base64EncodeBitmap(tile.bitmap) : "");
@@ -250,7 +251,16 @@ export class ImageEditor extends React.Component<ImageEditorProps, ImageEditorSt
250251
continue;
251252
}
252253

254+
const galleryTile = project.lookupAsset(pxt.AssetType.Tile, tile.id);
255+
if (galleryTile) {
256+
tile = galleryTile;
257+
}
258+
253259
if (tile.bitmap) {
260+
if (tile.meta.tags?.some(t => t.startsWith("category-") || BUILTIN_CATEGORIES.some(c => c.id === t))) {
261+
// tile already exist in the tile palette dropdown, so skip to avoid creating duplicates in the project
262+
continue;
263+
}
254264
const originalName = getSourceTileName(tile);
255265
const newName = originalName ? project.generateNewName(pxt.AssetType.Tile, originalName) : undefined;
256266

webapp/src/components/ImageEditor/tilemap/TilePalette.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface Category {
5858
tiles: GalleryTile[];
5959
}
6060

61-
const options: Category[] = [
61+
export const BUILTIN_CATEGORIES: Category[] = [
6262
{
6363
id: "forest",
6464
text: lf("Forest"),
@@ -126,7 +126,7 @@ class TilePaletteImpl extends React.Component<TilePaletteProps,{}> {
126126
}
127127
}
128128

129-
this.categories = options.concat(Object.keys(extraCategories).map(key => extraCategories[key]));
129+
this.categories = BUILTIN_CATEGORIES.concat(Object.keys(extraCategories).map(key => extraCategories[key]));
130130
} else {
131131
this.categories = [];
132132
}
@@ -434,7 +434,7 @@ class TilePaletteImpl extends React.Component<TilePaletteProps,{}> {
434434
protected refreshGallery(props: TilePaletteProps) {
435435
const { gallery, tileset } = props;
436436
if (gallery) {
437-
options.forEach(opt => {
437+
BUILTIN_CATEGORIES.forEach(opt => {
438438
opt.tiles = gallery.filter(t => t.tags.indexOf(opt.id) !== -1 && t.tileWidth === tileset.tileWidth);
439439
});
440440
}

webapp/src/components/ImageFieldEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class ImageFieldEditor<U extends pxt.Asset> extends React.Component<Image
8080

8181
let showHeader = headerVisible;
8282
// If there is no asset, show the gallery to prevent changing shape when it's added
83-
let showGallery = !this.props.isMusicEditor && (!this.asset || editingTile);
83+
let showGallery = !this.props.isMusicEditor || !this.asset || editingTile;
8484
const showMyAssets = !hideMyAssets && !editingTile;
8585

8686
if (this.asset && !this.galleryAssets && showGallery) {

0 commit comments

Comments
 (0)