@@ -26,6 +26,42 @@ const getVariant = (
26
26
: eventBasedObject . getDefaultVariant ( ) ;
27
27
} ;
28
28
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
+
29
65
/**
30
66
* Renderer for gd.CustomObject (the class is not exposed to newIDE)
31
67
*/
@@ -39,22 +75,25 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
39
75
40
76
layoutedInstances = new Map < number , LayoutedInstance > ( ) ;
41
77
renderedInstances = new Map < number , RenderedInstance | Rendered3DInstance > ( ) ;
78
+ _propertyMappingRules: Array < PropertyMappingRule > ;
42
79
43
80
constructor (
44
81
project : gdProject ,
45
82
instance : gdInitialInstance ,
46
83
associatedObjectConfiguration : gdObjectConfiguration ,
47
84
pixiContainer : PIXI . Container ,
48
85
threeGroup : THREE . Group ,
49
- pixiResourcesLoader : Class < PixiResourcesLoader >
86
+ pixiResourcesLoader : Class < PixiResourcesLoader > ,
87
+ propertyOverridings : Map < string , string >
50
88
) {
51
89
super (
52
90
project ,
53
91
instance ,
54
92
associatedObjectConfiguration ,
55
93
pixiContainer ,
56
94
threeGroup ,
57
- pixiResourcesLoader
95
+ pixiResourcesLoader ,
96
+ propertyOverridings
58
97
) ;
59
98
60
99
// Setup the PIXI object:
@@ -83,6 +122,7 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
83
122
if ( ! eventBasedObject ) {
84
123
return ;
85
124
}
125
+ this . _propertyMappingRules = getPropertyMappingRules ( eventBasedObject ) ;
86
126
this . _isRenderedIn3D = eventBasedObject . isRenderedIn3D ( ) ;
87
127
88
128
// Functor used to render an instance
@@ -160,9 +200,32 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
160
200
if ( variant ) {
161
201
const childObjects = variant . getObjects ( ) ;
162
202
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
+ ) ;
166
229
}
167
230
}
168
231
//...so let's create a renderer.
@@ -172,7 +235,8 @@ export default class RenderedCustomObjectInstance extends Rendered3DInstance
172
235
instance ,
173
236
childObjectConfiguration ,
174
237
this . _pixiObject ,
175
- this . _threeObject
238
+ this . _threeObject ,
239
+ childPropertyOverridings
176
240
)
177
241
: new RenderedUnknownInstance (
178
242
this . _project ,
0 commit comments