Skip to content

Commit 99287dd

Browse files
committedMar 10, 2025
Handle a property mapping between the parent and the child for editor rendering.
1 parent 66391a3 commit 99287dd

File tree

8 files changed

+108
-22
lines changed

8 files changed

+108
-22
lines changed
 

‎Extensions/BBText/JsExtension.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,16 @@ module.exports = {
485485
instance,
486486
associatedObjectConfiguration,
487487
pixiContainer,
488-
pixiResourcesLoader
488+
pixiResourcesLoader,
489+
propertyOverridings
489490
) {
490491
super(
491492
project,
492493
instance,
493494
associatedObjectConfiguration,
494495
pixiContainer,
495-
pixiResourcesLoader
496+
pixiResourcesLoader,
497+
propertyOverridings
496498
);
497499

498500
const bbTextStyles = {
@@ -532,7 +534,9 @@ module.exports = {
532534
gd.ObjectJsImplementation
533535
);
534536

535-
const rawText = object.content.text;
537+
const rawText = this._propertyOverridings.has('Text')
538+
? this._propertyOverridings.get('Text')
539+
: object.content.text;
536540
if (rawText !== this._pixiObject.text) {
537541
this._pixiObject.text = rawText;
538542
}

‎Extensions/BitmapText/JsExtension.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,16 @@ module.exports = {
624624
instance,
625625
associatedObjectConfiguration,
626626
pixiContainer,
627-
pixiResourcesLoader
627+
pixiResourcesLoader,
628+
propertyOverridings
628629
) {
629630
super(
630631
project,
631632
instance,
632633
associatedObjectConfiguration,
633634
pixiContainer,
634-
pixiResourcesLoader
635+
pixiResourcesLoader,
636+
propertyOverridings
635637
);
636638

637639
// We'll track changes of the font to trigger the loading of the new font.
@@ -657,8 +659,9 @@ module.exports = {
657659

658660
// Update the rendered text properties (note: Pixi is only
659661
// applying changes if there were changed).
660-
const rawText = object.content.text;
661-
this._pixiObject.text = rawText;
662+
this._pixiObject.text = this._propertyOverridings.has('Text')
663+
? this._propertyOverridings.get('Text')
664+
: object.content.text;
662665

663666
const align = object.content.align;
664667
this._pixiObject.align = align;

‎Extensions/JsExtensionTypes.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class RenderedInstance {
1515
_pixiContainer: PIXI.Container;
1616
_pixiResourcesLoader: Class<PixiResourcesLoader>;
1717
_pixiObject: PIXI.DisplayObject | null;
18+
_propertyOverridings: Map<string, string>;
1819
wasUsed: boolean;
1920

2021
/** Set to true when onRemovedFromScene is called. Allows to cancel promises/asynchronous operations (notably: waiting for a resource load). */
@@ -25,7 +26,8 @@ class RenderedInstance {
2526
instance: gdInitialInstance,
2627
associatedObjectConfiguration: gdObjectConfiguration,
2728
pixiContainer: PIXI.Container,
28-
pixiResourcesLoader: Class<PixiResourcesLoader>
29+
pixiResourcesLoader: Class<PixiResourcesLoader>,
30+
propertyOverridings: Map<string, string> = new Map<string, string>()
2931
);
3032

3133
/**

‎newIDE/app/src/ObjectsRendering/ObjectsRenderingService.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ const ObjectsRenderingService = {
8383
instance: gdInitialInstance,
8484
associatedObjectConfiguration: gdObjectConfiguration,
8585
pixiContainer: PIXI.Container,
86-
threeGroup: THREE.Group | null
86+
threeGroup: THREE.Group | null,
87+
propertyOverridings: Map<string, string> = new Map<string, string>()
8788
): RenderedInstance | Rendered3DInstance {
8889
const objectType = associatedObjectConfiguration.getType();
8990
if (threeGroup && this.renderers3D.hasOwnProperty(objectType)) {
@@ -101,7 +102,8 @@ const ObjectsRenderingService = {
101102
instance,
102103
associatedObjectConfiguration,
103104
pixiContainer,
104-
PixiResourcesLoader
105+
PixiResourcesLoader,
106+
propertyOverridings
105107
);
106108
else {
107109
if (project.hasEventsBasedObject(objectType)) {
@@ -135,7 +137,8 @@ const ObjectsRenderingService = {
135137
associatedObjectConfiguration,
136138
pixiContainer,
137139
threeGroup,
138-
PixiResourcesLoader
140+
PixiResourcesLoader,
141+
propertyOverridings
139142
);
140143
}
141144
}

‎newIDE/app/src/ObjectsRendering/Renderers/Rendered3DInstance.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ export default class Rendered3DInstance {
1919
_threeObject: THREE.Object3D | null;
2020
wasUsed: boolean;
2121
_wasDestroyed: boolean;
22+
_propertyOverridings: Map<string, string>;
2223

2324
constructor(
2425
project: gdProject,
2526
instance: gdInitialInstance,
2627
associatedObjectConfiguration: gdObjectConfiguration,
2728
pixiContainer: PIXI.Container,
2829
threeGroup: THREE.Group,
29-
pixiResourcesLoader: Class<PixiResourcesLoader>
30+
pixiResourcesLoader: Class<PixiResourcesLoader>,
31+
propertyOverridings: Map<string, string> = new Map<string, string>()
3032
) {
3133
this._pixiObject = null;
3234
this._threeObject = null;
@@ -36,6 +38,7 @@ export default class Rendered3DInstance {
3638
this._threeGroup = threeGroup;
3739
this._project = project;
3840
this._pixiResourcesLoader = pixiResourcesLoader;
41+
this._propertyOverridings = propertyOverridings;
3942
this.wasUsed = true; //Used by InstancesRenderer to track rendered instance that are not used anymore.
4043
this._wasDestroyed = false;
4144
}

‎newIDE/app/src/ObjectsRendering/Renderers/RenderedCustomObjectInstance.js

+70-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@ const getVariant = (
2626
: eventBasedObject.getDefaultVariant();
2727
};
2828

29+
type PropertyMappingRule = {
30+
targetChild: string,
31+
targetProperty: string,
32+
sourceProperty: string,
33+
};
34+
35+
const getPropertyMappingRules = (
36+
eventBasedObject: gdEventsBasedObject
37+
): Array<PropertyMappingRule> => {
38+
const properties = eventBasedObject.getPropertyDescriptors();
39+
if (!properties.has('_PropertyMapping')) {
40+
return [];
41+
}
42+
const extraInfos = properties
43+
.get('_PropertyMapping')
44+
.getExtraInfo()
45+
.toJSArray();
46+
return extraInfos
47+
.map(extraInfo => {
48+
const mapping = extraInfo.split('=');
49+
if (mapping.length < 2) {
50+
return null;
51+
}
52+
const targetPath = mapping[0].split('.');
53+
if (mapping.length < 2) {
54+
return null;
55+
}
56+
return {
57+
targetChild: targetPath[0],
58+
targetProperty: targetPath[1],
59+
sourceProperty: mapping[1],
60+
};
61+
})
62+
.filter(Boolean);
63+
};
64+
2965
/**
3066
* Renderer for gd.CustomObject (the class is not exposed to newIDE)
3167
*/
@@ -39,22 +75,25 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
3975

4076
layoutedInstances = new Map<number, LayoutedInstance>();
4177
renderedInstances = new Map<number, RenderedInstance | Rendered3DInstance>();
78+
_propertyMappingRules: Array<PropertyMappingRule>;
4279

4380
constructor(
4481
project: gdProject,
4582
instance: gdInitialInstance,
4683
associatedObjectConfiguration: gdObjectConfiguration,
4784
pixiContainer: PIXI.Container,
4885
threeGroup: THREE.Group,
49-
pixiResourcesLoader: Class<PixiResourcesLoader>
86+
pixiResourcesLoader: Class<PixiResourcesLoader>,
87+
propertyOverridings: Map<string, string>
5088
) {
5189
super(
5290
project,
5391
instance,
5492
associatedObjectConfiguration,
5593
pixiContainer,
5694
threeGroup,
57-
pixiResourcesLoader
95+
pixiResourcesLoader,
96+
propertyOverridings
5897
);
5998

6099
// Setup the PIXI object:
@@ -83,6 +122,7 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
83122
if (!eventBasedObject) {
84123
return;
85124
}
125+
this._propertyMappingRules = getPropertyMappingRules(eventBasedObject);
86126
this._isRenderedIn3D = eventBasedObject.isRenderedIn3D();
87127

88128
// Functor used to render an instance
@@ -160,9 +200,32 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
160200
if (variant) {
161201
const childObjects = variant.getObjects();
162202
if (childObjects.hasObjectNamed(instance.getObjectName())) {
163-
childObjectConfiguration = childObjects
164-
.getObject(instance.getObjectName())
165-
.getConfiguration();
203+
const childObject = childObjects.getObject(instance.getObjectName());
204+
childObjectConfiguration = childObject.getConfiguration();
205+
}
206+
}
207+
// Apply property mapping rules on the child instance.
208+
const childPropertyOverridings = new Map<string, string>();
209+
const customObjectConfiguration = gd.asCustomObjectConfiguration(
210+
this._associatedObjectConfiguration
211+
);
212+
for (const propertyMappingRule of this._propertyMappingRules) {
213+
if (propertyMappingRule.targetChild !== instance.getObjectName()) {
214+
continue;
215+
}
216+
const sourceValue = this._propertyOverridings.has(
217+
propertyMappingRule.sourceProperty
218+
)
219+
? this._propertyOverridings.get(propertyMappingRule.sourceProperty)
220+
: customObjectConfiguration
221+
.getProperties()
222+
.get(propertyMappingRule.sourceProperty)
223+
.getValue();
224+
if (sourceValue !== undefined) {
225+
childPropertyOverridings.set(
226+
propertyMappingRule.targetProperty,
227+
sourceValue
228+
);
166229
}
167230
}
168231
//...so let's create a renderer.
@@ -172,7 +235,8 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
172235
instance,
173236
childObjectConfiguration,
174237
this._pixiObject,
175-
this._threeObject
238+
this._threeObject,
239+
childPropertyOverridings
176240
)
177241
: new RenderedUnknownInstance(
178242
this._project,

‎newIDE/app/src/ObjectsRendering/Renderers/RenderedInstance.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ export default class RenderedInstance {
1515
_pixiObject: PIXI.DisplayObject;
1616
wasUsed: boolean;
1717
_wasDestroyed: boolean;
18+
_propertyOverridings: Map<string, string>;
1819

1920
constructor(
2021
project: gdProject,
2122
instance: gdInitialInstance,
2223
associatedObjectConfiguration: gdObjectConfiguration,
2324
pixiContainer: PIXI.Container,
24-
pixiResourcesLoader: Class<PixiResourcesLoader>
25+
pixiResourcesLoader: Class<PixiResourcesLoader>,
26+
propertyOverridings: Map<string, string> = new Map<string, string>()
2527
) {
2628
this._pixiObject = null;
2729
this._instance = instance;
2830
this._associatedObjectConfiguration = associatedObjectConfiguration;
2931
this._pixiContainer = pixiContainer;
3032
this._project = project;
3133
this._pixiResourcesLoader = pixiResourcesLoader;
34+
this._propertyOverridings = propertyOverridings;
3235
this.wasUsed = true; //Used by InstancesRenderer to track rendered instance that are not used anymore.
3336
this._wasDestroyed = false;
3437
}

‎newIDE/app/src/ObjectsRendering/Renderers/RenderedTextInstance.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ export default class RenderedTextInstance extends RenderedInstance {
3838
instance: gdInitialInstance,
3939
associatedObjectConfiguration: gdObjectConfiguration,
4040
pixiContainer: PIXI.Container,
41-
pixiResourcesLoader: Class<PixiResourcesLoader>
41+
pixiResourcesLoader: Class<PixiResourcesLoader>,
42+
propertyOverridings: Map<string, string>
4243
) {
4344
super(
4445
project,
4546
instance,
4647
associatedObjectConfiguration,
4748
pixiContainer,
48-
pixiResourcesLoader
49+
pixiResourcesLoader,
50+
propertyOverridings
4951
);
5052

5153
const style = new PIXI.TextStyle({
@@ -84,7 +86,9 @@ export default class RenderedTextInstance extends RenderedInstance {
8486
const textObjectConfiguration = gd.asTextObjectConfiguration(
8587
this._associatedObjectConfiguration
8688
);
87-
this._pixiObject.text = textObjectConfiguration.getText();
89+
this._pixiObject.text = this._propertyOverridings.has('Text')
90+
? this._propertyOverridings.get('Text')
91+
: textObjectConfiguration.getText();
8892

8993
//Update style, only if needed to avoid destroying text rendering performances
9094
if (

0 commit comments

Comments
 (0)