Skip to content

Commit b3210ef

Browse files
committed
Return non-zero objectSizeInfo for TextInput, Lighting and 3D objects and null when unknown
1 parent d8f966f commit b3210ef

3 files changed

Lines changed: 152 additions & 97 deletions

File tree

newIDE/app/src/EditorFunctions/Utils.js

Lines changed: 94 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const gd: libGDevelop = global.gd;
66
export type ObjectSizeInfo = {|
77
width: number,
88
height: number,
9-
depth: number,
9+
depth: number | null,
1010
originX: number,
1111
originY: number,
12-
originZ: number,
12+
originZ: number | null,
1313
centerX: number,
1414
centerY: number,
15-
centerZ: number,
15+
centerZ: number | null,
1616
|};
1717

1818
/**
@@ -80,60 +80,129 @@ export const getObjectSizeInfo = (
8080
return {
8181
width,
8282
height,
83-
depth: 0,
83+
depth: null,
8484
originX,
8585
originY,
86-
originZ: 0,
86+
originZ: null,
8787
centerX,
8888
centerY,
89-
centerZ: 0,
89+
centerZ: null,
9090
};
9191
}
9292
}
93+
return null;
94+
}
95+
96+
if (objectType === 'TiledSpriteObject::TiledSprite') {
97+
const config = gd.asTiledSpriteConfiguration(objectConfiguration);
98+
const width = config.getWidth();
99+
const height = config.getHeight();
93100
return {
94-
width: 0,
95-
height: 0,
96-
depth: 0,
101+
width,
102+
height,
103+
depth: null,
97104
originX: 0,
98105
originY: 0,
99-
originZ: 0,
100-
centerX: 0,
101-
centerY: 0,
102-
centerZ: 0,
106+
originZ: null,
107+
centerX: width / 2,
108+
centerY: height / 2,
109+
centerZ: null,
103110
};
104111
}
105112

106-
if (objectType === 'TiledSpriteObject::TiledSprite') {
107-
const config = gd.asTiledSpriteConfiguration(objectConfiguration);
113+
if (objectType === 'PanelSpriteObject::PanelSprite') {
114+
const config = gd.asPanelSpriteConfiguration(objectConfiguration);
108115
const width = config.getWidth();
109116
const height = config.getHeight();
110117
return {
111118
width,
112119
height,
113-
depth: 0,
120+
depth: null,
121+
originX: 0,
122+
originY: 0,
123+
originZ: null,
124+
centerX: width / 2,
125+
centerY: height / 2,
126+
centerZ: null,
127+
};
128+
}
129+
130+
if (objectType === 'TextInput::TextInputObject') {
131+
// Defaults match DEFAULT_WIDTH/DEFAULT_HEIGHT in Extensions/TextInput/JsExtension.js.
132+
const width = 300;
133+
const height = 30;
134+
return {
135+
width,
136+
height,
137+
depth: null,
138+
originX: 0,
139+
originY: 0,
140+
originZ: null,
141+
centerX: width / 2,
142+
centerY: height / 2,
143+
centerZ: null,
144+
};
145+
}
146+
147+
if (objectType === 'Lighting::LightObject') {
148+
const properties = objectConfiguration.getProperties();
149+
const radius = properties.has('radius')
150+
? parseFloat(properties.get('radius').getValue()) || 0
151+
: 0;
152+
const width = radius * 2;
153+
const height = radius * 2;
154+
return {
155+
width,
156+
height,
157+
depth: null,
158+
originX: radius,
159+
originY: radius,
160+
originZ: null,
161+
centerX: radius,
162+
centerY: radius,
163+
centerZ: null,
164+
};
165+
}
166+
167+
if (objectType === 'Scene3D::Cube3DObject') {
168+
const properties = objectConfiguration.getProperties();
169+
const width = properties.has('width')
170+
? parseFloat(properties.get('width').getValue()) || 0
171+
: 0;
172+
const height = properties.has('height')
173+
? parseFloat(properties.get('height').getValue()) || 0
174+
: 0;
175+
const depth = properties.has('depth')
176+
? parseFloat(properties.get('depth').getValue()) || 0
177+
: 0;
178+
return {
179+
width,
180+
height,
181+
depth,
114182
originX: 0,
115183
originY: 0,
116184
originZ: 0,
117185
centerX: width / 2,
118186
centerY: height / 2,
119-
centerZ: 0,
187+
centerZ: depth / 2,
120188
};
121189
}
122190

123-
if (objectType === 'PanelSpriteObject::PanelSprite') {
124-
const config = gd.asPanelSpriteConfiguration(objectConfiguration);
191+
if (objectType === 'Scene3D::Model3DObject') {
192+
const config = gd.asModel3DConfiguration(objectConfiguration);
125193
const width = config.getWidth();
126194
const height = config.getHeight();
195+
const depth = config.getDepth();
127196
return {
128197
width,
129198
height,
130-
depth: 0,
199+
depth,
131200
originX: 0,
132201
originY: 0,
133202
originZ: 0,
134203
centerX: width / 2,
135204
centerY: height / 2,
136-
centerZ: 0,
205+
centerZ: depth / 2,
137206
};
138207
}
139208

@@ -163,25 +232,15 @@ export const getObjectSizeInfo = (
163232
return {
164233
width,
165234
height,
166-
depth,
235+
depth: isRenderedIn3D ? depth : null,
167236
originX: -minX || 0,
168237
originY: -minY || 0,
169-
originZ: -minZ || 0,
238+
originZ: isRenderedIn3D ? -minZ || 0 : null,
170239
centerX: width / 2,
171240
centerY: height / 2,
172-
centerZ: depth / 2,
241+
centerZ: isRenderedIn3D ? depth / 2 : null,
173242
};
174243
}
175244

176-
return {
177-
width: 0,
178-
height: 0,
179-
depth: 0,
180-
originX: 0,
181-
originY: 0,
182-
originZ: 0,
183-
centerX: 0,
184-
centerY: 0,
185-
centerZ: 0,
186-
};
245+
return null;
187246
};

0 commit comments

Comments
 (0)