mirror of
https://github.com/4ian/GDevelop.git
synced 2026-10-12 02:01:17 +00:00
Handle tile maps with invalid resources (#4140)
* Fix an uncatched exceptions when a tile map resource is not set. * Show place-holders for tile map with invalid resources in the instances editor. * Give a better default name to tile map collision mask objects. * Add a border around the tile map collision mask objects in the instance editor.
This commit is contained in:
@@ -794,7 +794,8 @@ module.exports = {
|
||||
pixiResourcesLoader
|
||||
);
|
||||
|
||||
this._pixiObject = new Tilemap.CompositeRectTileLayer(0);
|
||||
this.tileMapPixiObject = new Tilemap.CompositeRectTileLayer(0);
|
||||
this._pixiObject = this.tileMapPixiObject;
|
||||
|
||||
// Implement `containsPoint` so that we can set `interactive` to true and
|
||||
// the Tilemap will properly emit events when hovered/clicked.
|
||||
@@ -812,8 +813,8 @@ module.exports = {
|
||||
);
|
||||
};
|
||||
this._pixiContainer.addChild(this._pixiObject);
|
||||
this.width = 20;
|
||||
this.height = 20;
|
||||
this.width = 48;
|
||||
this.height = 48;
|
||||
this.update();
|
||||
this.updateTileMap();
|
||||
}
|
||||
@@ -822,6 +823,21 @@ module.exports = {
|
||||
RenderedInstance.prototype
|
||||
);
|
||||
|
||||
RenderedTileMapInstance.prototype.onLoadingError = function () {
|
||||
this.errorPixiObject = this.errorPixiObject ||
|
||||
new PIXI.Sprite(this._pixiResourcesLoader.getInvalidPIXITexture());
|
||||
this._pixiContainer.addChild(this.errorPixiObject);
|
||||
this._pixiObject = this.errorPixiObject;
|
||||
};
|
||||
|
||||
RenderedTileMapInstance.prototype.onLoadingSuccess = function () {
|
||||
if (this.errorPixiObject) {
|
||||
this._pixiContainer.removeChild(this.errorPixiObject);
|
||||
this.errorPixiObject = null;
|
||||
this._pixiObject = this.tileMapPixiObject;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the path to the thumbnail of the specified object.
|
||||
*/
|
||||
@@ -871,6 +887,7 @@ module.exports = {
|
||||
pako,
|
||||
(tileMap) => {
|
||||
if (!tileMap) {
|
||||
this.onLoadingError();
|
||||
// _loadTiledMapWithCallback already log errors
|
||||
return;
|
||||
}
|
||||
@@ -885,14 +902,16 @@ module.exports = {
|
||||
tilesetJsonFile,
|
||||
(textureCache) => {
|
||||
if (!textureCache) {
|
||||
this.onLoadingError();
|
||||
// getOrLoadTextureCache already log warns and errors.
|
||||
return;
|
||||
}
|
||||
this.onLoadingSuccess();
|
||||
|
||||
this.width = tileMap.getWidth();
|
||||
this.height = tileMap.getHeight();
|
||||
TilemapHelper.PixiTileMapHelper.updatePixiTileMap(
|
||||
this._pixiObject,
|
||||
this.tileMapPixiObject,
|
||||
tileMap,
|
||||
textureCache,
|
||||
displayMode,
|
||||
@@ -917,12 +936,13 @@ module.exports = {
|
||||
tilemapJsonFile,
|
||||
tilesetJsonFile) {
|
||||
|
||||
const tileMapJsonData = await this._pixiResourcesLoader.getResourceJsonData(
|
||||
let tileMapJsonData = null;
|
||||
try {
|
||||
tileMapJsonData = await this._pixiResourcesLoader.getResourceJsonData(
|
||||
this._project,
|
||||
tilemapJsonFile
|
||||
);
|
||||
|
||||
try {
|
||||
const tilesetJsonData = tilesetJsonFile
|
||||
? await this._pixiResourcesLoader.getResourceJsonData(
|
||||
this._project,
|
||||
@@ -1015,7 +1035,8 @@ module.exports = {
|
||||
pixiResourcesLoader
|
||||
);
|
||||
|
||||
this._pixiObject = new PIXI.Graphics();
|
||||
this.tileMapPixiObject = new PIXI.Graphics();
|
||||
this._pixiObject = this.tileMapPixiObject;
|
||||
|
||||
// Implement `containsPoint` so that we can set `interactive` to true and
|
||||
// the Tilemap will properly emit events when hovered/clicked.
|
||||
@@ -1034,8 +1055,8 @@ module.exports = {
|
||||
);
|
||||
};
|
||||
this._pixiContainer.addChild(this._pixiObject);
|
||||
this.width = 20;
|
||||
this.height = 20;
|
||||
this.width = 48;
|
||||
this.height = 48;
|
||||
this.update();
|
||||
this.updateTileMap();
|
||||
}
|
||||
@@ -1044,6 +1065,21 @@ module.exports = {
|
||||
RenderedInstance.prototype
|
||||
);
|
||||
|
||||
RenderedCollisionMaskInstance.prototype.onLoadingError = function () {
|
||||
this.errorPixiObject = this.errorPixiObject ||
|
||||
new PIXI.Sprite(this._pixiResourcesLoader.getInvalidPIXITexture());
|
||||
this._pixiContainer.addChild(this.errorPixiObject);
|
||||
this._pixiObject = this.errorPixiObject;
|
||||
};
|
||||
|
||||
RenderedCollisionMaskInstance.prototype.onLoadingSuccess = function () {
|
||||
if (this.errorPixiObject) {
|
||||
this._pixiContainer.removeChild(this.errorPixiObject);
|
||||
this.errorPixiObject = null;
|
||||
this._pixiObject = this.tileMapPixiObject;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the path to the thumbnail of the specified object.
|
||||
*/
|
||||
@@ -1107,9 +1143,11 @@ module.exports = {
|
||||
pako,
|
||||
(tileMap) => {
|
||||
if (!tileMap) {
|
||||
this.onLoadingError();
|
||||
// _loadTiledMapWithCallback already log errors
|
||||
return;
|
||||
}
|
||||
this.onLoadingSuccess();
|
||||
|
||||
this.width = tileMap.getWidth();
|
||||
this.height = tileMap.getHeight();
|
||||
@@ -1165,12 +1203,13 @@ module.exports = {
|
||||
tilemapJsonFile,
|
||||
tilesetJsonFile) {
|
||||
|
||||
const tileMapJsonData = await this._pixiResourcesLoader.getResourceJsonData(
|
||||
let tileMapJsonData = null;
|
||||
try {
|
||||
tileMapJsonData = await this._pixiResourcesLoader.getResourceJsonData(
|
||||
this._project,
|
||||
tilemapJsonFile
|
||||
);
|
||||
|
||||
try {
|
||||
const tilesetJsonData = tilesetJsonFile
|
||||
? await this._pixiResourcesLoader.getResourceJsonData(
|
||||
this._project,
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
{"version":3,"file":"TileMapPixiHelper.d.ts","sourceRoot":"","sources":["../../src/render/TileMapPixiHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,QAA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OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC;AAGpC,qBAAa,iBAAiB;IAC5B;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CACf,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,EACpD,UAAU,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,GACnE,gBAAgB,GAAG,IAAI;IA+E1B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,iBAAiB,CACtB,kBAAkB,EAAE,GAAG,EACvB,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,gBAAgB,EAC9B,WAAW,EAAE,OAAO,GAAG,SAAS,GAAG,KAAK,EACxC,UAAU,EAAE,MAAM,GACjB,IAAI;IA4EP;;OAEG;IACH,MAAM,CAAC,uBAAuB,CAC5B,YAAY,EAAE,IAAI,CAAC,QAAQ,EAC3B,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,OAAO,EACpB,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,KAAK,EACrB,SAAS,EAAE,OAAO,EAClB,WAAW,EAAE,KAAK,GACjB,IAAI;CA+DR"}
|
||||
@@ -213,6 +213,9 @@ export class PixiTileMapHelper {
|
||||
if (!pixiGraphics) return;
|
||||
pixiGraphics.clear();
|
||||
|
||||
pixiGraphics.lineStyle(outlineSize, outlineColor, outlineOpacity);
|
||||
pixiGraphics.drawRect(0, 0, tileMap.getWidth(), tileMap.getHeight());
|
||||
|
||||
for (const layer of tileMap.getLayers()) {
|
||||
const tileWidth = tileMap.getTileWidth();
|
||||
const tileHeight = tileMap.getTileHeight();
|
||||
@@ -237,7 +240,6 @@ export class PixiTileMapHelper {
|
||||
if (!hitboxes) {
|
||||
continue;
|
||||
}
|
||||
pixiGraphics.lineStyle(outlineSize, outlineColor, outlineOpacity);
|
||||
for (const vertices of hitboxes) {
|
||||
if (vertices.length === 0) continue;
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ const objectTypeToDefaultName = {
|
||||
'BitmapText::BitmapTextObject': 'NewBitmapText',
|
||||
'TextEntryObject::TextEntry': 'NewTextEntry',
|
||||
'TileMap::TileMap': 'NewTileMap',
|
||||
'TileMap::CollisionMask': 'NewTileMapMask',
|
||||
'MyDummyExtension::DummyObject': 'NewDummyObject',
|
||||
'Lighting::LightObject': 'NewLight',
|
||||
'TextInput::TextInputObject': 'NewTextInput',
|
||||
|
||||
Reference in New Issue
Block a user