Skip to content

Commit 4d4b86a

Browse files
authored
Display a placeholder for instances with unknown object in the editor (#7933)
1 parent f3595a9 commit 4d4b86a

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed

newIDE/app/src/InstancesEditor/InstancesRenderer/LayerRenderer.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,26 @@ export default class LayerRenderer {
412412
this.objectsContainer,
413413
associatedObjectName
414414
);
415-
if (!associatedObject) return null;
416-
417415
//...so let's create a renderer.
418-
renderedInstance = this.renderedInstances[
419-
instance.ptr
420-
] = ObjectsRenderingService.createNewInstanceRenderer(
421-
this.project,
422-
instance,
423-
associatedObject.getConfiguration(),
424-
this.pixiContainer,
425-
this._threeGroup
426-
);
416+
if (associatedObject) {
417+
renderedInstance = this.renderedInstances[
418+
instance.ptr
419+
] = ObjectsRenderingService.createNewInstanceRenderer(
420+
this.project,
421+
instance,
422+
associatedObject.getConfiguration(),
423+
this.pixiContainer,
424+
this._threeGroup
425+
);
426+
} else {
427+
renderedInstance = this.renderedInstances[
428+
instance.ptr
429+
] = ObjectsRenderingService.createNewUnknownInstanceRenderer(
430+
this.project,
431+
instance,
432+
this.pixiContainer
433+
);
434+
}
427435

428436
renderedInstance._pixiObject.eventMode = 'static';
429437
panable(renderedInstance._pixiObject);

newIDE/app/src/ObjectsRendering/ObjectsRenderingService.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ const ObjectsRenderingService = {
7878
);
7979
}
8080
},
81+
createNewUnknownInstanceRenderer: function(
82+
project: gdProject,
83+
instance: gdInitialInstance,
84+
pixiContainer: PIXI.Container
85+
): RenderedInstance | Rendered3DInstance {
86+
return new this.renderers['unknownObjectType'](
87+
project,
88+
instance,
89+
null,
90+
pixiContainer,
91+
PixiResourcesLoader
92+
);
93+
},
8194
createNewInstanceRenderer: function(
8295
project: gdProject,
8396
instance: gdInitialInstance,

newIDE/app/src/ObjectsRendering/Renderers/RenderedUnknownInstance.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ export default class RenderedUnknownInstance extends RenderedInstance {
1111
constructor(
1212
project: gdProject,
1313
instance: gdInitialInstance,
14-
associatedObjectConfiguration: gdObjectConfiguration,
14+
associatedObjectConfiguration: gdObjectConfiguration | null,
1515
pixiContainer: PIXI.Container,
1616
pixiResourcesLoader: Class<PixiResourcesLoader>
1717
) {
1818
super(
1919
project,
2020
instance,
21+
//$FlowFixMe It's ok because RenderedUnknownInstance don't use it.
2122
associatedObjectConfiguration,
2223
pixiContainer,
2324
pixiResourcesLoader
2425
);
2526

2627
//This renderer show a placeholder for the object:
27-
this._pixiObject = new PIXI.Graphics();
28+
this._pixiObject = new PIXI.Sprite(
29+
this._pixiResourcesLoader.getInvalidPIXITexture()
30+
);
2831
this._pixiContainer.addChild(this._pixiObject);
2932
}
3033

@@ -42,21 +45,34 @@ export default class RenderedUnknownInstance extends RenderedInstance {
4245
}
4346

4447
update() {
45-
const width = this.getWidth();
46-
const height = this.getHeight();
47-
48-
this._pixiObject.clear();
49-
this._pixiObject.beginFill(0x0033ff);
50-
this._pixiObject.lineStyle(1, 0xffd900, 1);
51-
this._pixiObject.moveTo(-width / 2, -height / 2);
52-
this._pixiObject.lineTo(width / 2, -height / 2);
53-
this._pixiObject.lineTo(width / 2, height / 2);
54-
this._pixiObject.lineTo(-width / 2, height / 2);
55-
this._pixiObject.lineTo(-width / 2, -height / 2);
56-
this._pixiObject.endFill();
57-
58-
this._pixiObject.position.x = this._instance.getX() + width / 2;
59-
this._pixiObject.position.y = this._instance.getY() + height / 2;
60-
this._pixiObject.angle = this._instance.getAngle();
48+
// Avoid to use _pixiObject after destroy is called.
49+
// It can happen when onRemovedFromScene and update cross each other.
50+
if (!this._pixiObject) {
51+
return;
52+
}
53+
const objectTextureFrame = this._pixiObject.texture.frame;
54+
// In case the texture is not loaded yet, we don't want to crash.
55+
if (!objectTextureFrame) return;
56+
57+
this._pixiObject.anchor.x = 0.5;
58+
this._pixiObject.anchor.y = 0.5;
59+
this._pixiObject.rotation = RenderedInstance.toRad(
60+
this._instance.getAngle()
61+
);
62+
this._pixiObject.scale.x = this.getWidth() / objectTextureFrame.width;
63+
this._pixiObject.scale.y = this.getHeight() / objectTextureFrame.height;
64+
this._pixiObject.position.x = this._instance.getX() + this.getCenterX();
65+
this._pixiObject.position.y = this._instance.getY() + this.getCenterY();
66+
67+
// Do not hide completely an object so it can still be manipulated
68+
const alphaForDisplay = Math.max(this._instance.getOpacity() / 255, 0.5);
69+
this._pixiObject.alpha = alphaForDisplay;
70+
71+
this._pixiObject.scale.x =
72+
Math.abs(this._pixiObject.scale.x) *
73+
(this._instance.isFlippedX() ? -1 : 1);
74+
this._pixiObject.scale.y =
75+
Math.abs(this._pixiObject.scale.y) *
76+
(this._instance.isFlippedY() ? -1 : 1);
6177
}
6278
}

0 commit comments

Comments
 (0)