Skip to content

Commit fcdc431

Browse files
authored
[stable11.3] reverting asset fixes for patch release (#10542)
* Revert "fix edited/deleted tile metadata being lost when patching temp assets (#10532) (#10536)" This reverts commit b5ed443. * Revert "[Stable11.3] Cherry pick asset fixes (#10522)" This reverts commit f24235b.
1 parent 1a68865 commit fcdc431

File tree

10 files changed

+38
-156
lines changed

10 files changed

+38
-156
lines changed

pxtblocks/fields/field_animation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class FieldAnimationEditor extends FieldAssetEditor<FieldAnimationOptions
8080
const frames = parseImageArrayString(text, this.params.taggedTemplate);
8181

8282
if (frames && frames.length) {
83-
const id = this.temporaryAssetId();
83+
const id = this.sourceBlock_.id;
8484

8585
const newAnimation: pxt.Animation = {
8686
internalID: -1,
@@ -97,7 +97,7 @@ export class FieldAnimationEditor extends FieldAssetEditor<FieldAnimationOptions
9797
if (asset) return asset;
9898
}
9999

100-
const id = this.temporaryAssetId();
100+
const id = this.sourceBlock_.id;
101101
const bitmap = new pxt.sprite.Bitmap(this.params.initWidth, this.params.initHeight).data()
102102

103103
const newAnimation: pxt.Animation = {

pxtblocks/fields/field_asset.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
264264
}
265265

266266
protected onFieldEditorHide(fv: pxt.react.FieldEditorView<pxt.Asset>) {
267-
let result = fv.getResult();
267+
const result = fv.getResult();
268268
const project = pxt.react.getTilemapProject();
269269

270270
if (this.asset.type === pxt.AssetType.Song) {
@@ -275,10 +275,15 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
275275
const old = this.getValue();
276276
if (pxt.assetEquals(this.asset, result)) return;
277277

278-
result = pxt.patchTemporaryAsset(this.asset, result, project);
279-
280278
const oldId = isTemporaryAsset(this.asset) ? null : this.asset.id;
281-
const newId = isTemporaryAsset(result) ? null : result.id;
279+
let newId = isTemporaryAsset(result) ? null : result.id;
280+
281+
if (!oldId && newId === this.sourceBlock_.id) {
282+
// The temporary assets we create just use the block id as the id; give it something
283+
// a little nicer
284+
result.id = project.generateNewID(result.type);
285+
newId = result.id;
286+
}
282287

283288
this.pendingEdit = true;
284289

@@ -547,10 +552,6 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
547552
protected isFullscreen() {
548553
return true;
549554
}
550-
551-
protected temporaryAssetId() {
552-
return this.sourceBlock_.id + "_" + this.name;
553-
}
554555
}
555556

556557
function isTemporaryAsset(asset: pxt.Asset) {

pxtblocks/fields/field_musiceditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class FieldMusicEditor extends FieldAssetEditor<FieldMusicEditorOptions,
6161

6262
const newAsset: pxt.Song = {
6363
internalID: -1,
64-
id: this.temporaryAssetId(),
64+
id: this.sourceBlock_.id,
6565
type: pxt.AssetType.Song,
6666
meta: {
6767
},

pxtblocks/fields/field_sprite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class FieldSpriteEditor extends FieldAssetEditor<FieldSpriteEditorOptions
7070

7171
const newAsset: pxt.ProjectImage = {
7272
internalID: -1,
73-
id: this.temporaryAssetId(),
73+
id: this.sourceBlock_.id,
7474
type: pxt.AssetType.Image,
7575
jresData: pxt.sprite.base64EncodeBitmap(data),
7676
meta: {

pxteditor/monaco-fields/field_musiceditor.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ export class MonacoSongEditor extends MonacoReactFieldEditor<pxt.Song> {
77
protected isPython: boolean;
88
protected isAsset: boolean;
99
protected text: string;
10-
protected editing: pxt.Asset;
1110

1211
protected textToValue(text: string): pxt.Song {
1312
this.isPython = text.indexOf("`") === -1
1413
this.text = text;
1514

1615
const match = pxt.parseAssetTSReference(text);
1716
if (match) {
18-
const { name: matchedName } = match;
17+
const { type, name: matchedName } = match;
1918
const name = matchedName.trim();
2019
const project = pxt.react.getTilemapProject();
2120
this.isAsset = true;
2221
const asset = project.lookupAssetByName(pxt.AssetType.Song, name);
2322
if (asset) {
24-
this.editing = asset;
2523
return asset;
2624
}
2725
else {
@@ -31,8 +29,6 @@ export class MonacoSongEditor extends MonacoReactFieldEditor<pxt.Song> {
3129
newAsset.meta.displayName = name;
3230
}
3331

34-
this.editing = newAsset;
35-
3632
return newAsset;
3733
}
3834
}
@@ -43,24 +39,18 @@ export class MonacoSongEditor extends MonacoReactFieldEditor<pxt.Song> {
4339
const contents = hexLiteralMatch[1].trim();
4440

4541
if (contents) {
46-
this.editing = createFakeAsset(pxt.assets.music.decodeSongFromHex(contents));
47-
}
48-
else {
49-
this.editing = createFakeAsset(pxt.assets.music.getEmptySong(2));
42+
return createFakeAsset(pxt.assets.music.decodeSongFromHex(contents));
5043
}
5144

52-
return this.editing;
45+
return createFakeAsset(pxt.assets.music.getEmptySong(2));
5346
}
5447

5548
return undefined; // never
5649
}
5750

5851
protected resultToText(result: pxt.Song): string {
59-
const project = pxt.react.getTilemapProject();
60-
project.pushUndo();
61-
62-
result = pxt.patchTemporaryAsset(this.editing, result, project) as pxt.Song;
6352
if (result.meta?.displayName) {
53+
const project = pxt.react.getTilemapProject();
6454
if (this.isAsset || project.lookupAsset(result.type, result.id)) {
6555
result = project.updateAsset(result)
6656
} else {

pxteditor/monaco-fields/field_sprite.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ export class MonacoSpriteEditor extends MonacoReactFieldEditor<pxt.ProjectImage>
77
protected isPython: boolean;
88
protected isAsset: boolean;
99
protected template: string;
10-
protected editing: pxt.Asset;
1110

1211
protected textToValue(text: string): pxt.ProjectImage {
1312
this.isPython = text.indexOf("`") === -1
1413
this.template = text.startsWith("bmp") ? "bmp" : "img"
1514

1615
const match = pxt.parseAssetTSReference(text);
1716
if (match) {
18-
const { name: matchedName } = match;
17+
const { type, name: matchedName } = match;
1918
const name = matchedName.trim();
2019
const project = pxt.react.getTilemapProject();
2120
this.isAsset = true;
2221
const asset = project.lookupAssetByName(pxt.AssetType.Image, name);
2322
if (asset) {
24-
this.editing = asset;
2523
return asset;
2624
}
2725
else {
@@ -31,23 +29,16 @@ export class MonacoSpriteEditor extends MonacoReactFieldEditor<pxt.ProjectImage>
3129
newAsset.meta.displayName = name;
3230
}
3331

34-
this.editing = newAsset;
35-
3632
return newAsset;
3733
}
3834
}
3935

40-
this.editing = createFakeAsset(pxt.sprite.imageLiteralToBitmap(text, this.template));
41-
42-
return this.editing;
36+
return createFakeAsset(pxt.sprite.imageLiteralToBitmap(text, this.template));
4337
}
4438

4539
protected resultToText(result: pxt.ProjectImage): string {
46-
const project = pxt.react.getTilemapProject();
47-
project.pushUndo();
48-
result = pxt.patchTemporaryAsset(this.editing, result, project) as pxt.ProjectImage;
49-
5040
if (result.meta?.displayName) {
41+
const project = pxt.react.getTilemapProject();
5142
if (this.isAsset || project.lookupAsset(result.type, result.id)) {
5243
result = project.updateAsset(result)
5344
} else {

pxteditor/monaco-fields/field_tilemap.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ const fieldEditorId = "tilemap-editor";
66
export class MonacoTilemapEditor extends MonacoReactFieldEditor<pxt.ProjectTilemap> {
77
protected isTilemapLiteral: boolean;
88
protected tilemapLiteral: string;
9-
protected editing: pxt.Asset;
109

1110
protected textToValue(text: string): pxt.ProjectTilemap {
1211
const tm = this.readTilemap(text);
1312

1413
const project = pxt.react.getTilemapProject();
1514
pxt.sprite.addMissingTilemapTilesAndReferences(project, tm);
1615

17-
this.editing = tm;
1816
return tm;
1917
}
2018

@@ -33,7 +31,7 @@ export class MonacoTilemapEditor extends MonacoReactFieldEditor<pxt.ProjectTilem
3331
// If the user is still typing, they might try to open the editor on an incomplete tilemap
3432
}
3533
return null;
36-
}
34+
}
3735
}
3836

3937
this.isTilemapLiteral = true;
@@ -73,7 +71,7 @@ export class MonacoTilemapEditor extends MonacoReactFieldEditor<pxt.ProjectTilem
7371
protected resultToText(asset: pxt.ProjectTilemap): string {
7472
const project = pxt.react.getTilemapProject();
7573
project.pushUndo();
76-
asset = pxt.patchTemporaryAsset(this.editing, asset, project) as pxt.ProjectTilemap;
74+
7775
pxt.sprite.updateTilemapReferencesFromResult(project, asset);
7876

7977
if (this.isTilemapLiteral) {

pxtlib/spriteutils.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace pxt.sprite {
145145
}
146146
}
147147

148-
dataLength() {
148+
protected dataLength() {
149149
return Math.ceil(this.width * this.height / 2);
150150
}
151151
}
@@ -179,7 +179,7 @@ namespace pxt.sprite {
179179
this.buf[index] = value;
180180
}
181181

182-
dataLength() {
182+
protected dataLength() {
183183
return this.width * this.height;
184184
}
185185
}
@@ -196,7 +196,7 @@ namespace pxt.sprite {
196196

197197
constructor(public tilemap: Tilemap, public tileset: TileSet, public layers: BitmapData) {}
198198

199-
cloneData(includeEditorData = false) {
199+
cloneData() {
200200
const tm = this.tilemap.copy();
201201
const tileset: TileSet = {
202202
tileWidth: this.tileset.tileWidth,
@@ -207,17 +207,7 @@ namespace pxt.sprite {
207207
}
208208
const layers = Bitmap.fromData(this.layers).copy().data();
209209

210-
const result = new TilemapData(tm, tileset, layers);
211-
212-
if (includeEditorData) {
213-
result.nextId = this.nextId;
214-
result.projectReferences = this.projectReferences?.slice();
215-
result.tileOrder = this.tileOrder?.slice();
216-
result.editedTiles = this.editedTiles?.slice();
217-
result.deletedTiles = this.deletedTiles?.slice();
218-
}
219-
220-
return result;
210+
return new TilemapData(tm, tileset, layers);
221211
}
222212

223213
equals(other: TilemapData) {

0 commit comments

Comments
 (0)