Skip to content

Commit 04384e3

Browse files
authored
Add properties of objects and behaviors to extensions summaries sent to AI (#7967)
Don't show in changelog
1 parent 59f94af commit 04384e3

File tree

5 files changed

+224
-20
lines changed

5 files changed

+224
-20
lines changed

newIDE/app/src/EditorFunctions/SimplifiedProject/ExtensionSummary.js

Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import { mapFor } from '../../Utils/MapFor';
2+
import { mapFor, mapVector } from '../../Utils/MapFor';
33

44
export type ParameterSummary = {|
55
isCodeOnly?: boolean,
@@ -36,12 +36,27 @@ export type PropertySummary = {|
3636
name: string,
3737
description: string,
3838
type: string,
39+
40+
label?: string,
41+
measurementUnit?: {
42+
name: string,
43+
},
44+
extraInfo?: Array<string>,
45+
group?: string,
46+
choices?: Array<{
47+
value: string,
48+
label: string,
49+
}>,
50+
hidden?: boolean,
51+
deprecated?: boolean,
52+
advanced?: boolean,
3953
|};
4054

4155
export type ObjectSummary = {|
4256
name: string,
4357
fullName: string,
4458
description: string,
59+
properties?: Array<PropertySummary>,
4560
actions: Array<InstructionSummary>,
4661
conditions: Array<InstructionSummary>,
4762
expressions: Array<ExpressionSummary>,
@@ -52,6 +67,8 @@ export type BehaviorSummary = {|
5267
fullName: string,
5368
description: string,
5469
objectType?: string,
70+
properties: Array<PropertySummary>,
71+
sharedProperties: Array<PropertySummary>,
5572
actions: Array<InstructionSummary>,
5673
conditions: Array<InstructionSummary>,
5774
expressions: Array<ExpressionSummary>,
@@ -122,32 +139,79 @@ const getParameterSummary = (
122139

123140
const getPropertySummary = (
124141
propertyName: string,
125-
property: gdPropertyDescriptor
126-
) => {
127-
return {
142+
property: gdPropertyDescriptor | gdNamedPropertyDescriptor
143+
): PropertySummary => {
144+
const propertySummary: PropertySummary = {
128145
name: propertyName,
129146
description: property.getDescription(),
130147
type: property.getType(),
131148
};
149+
150+
if (property.getLabel()) {
151+
propertySummary.label = property.getLabel();
152+
}
153+
if (property.getGroup()) {
154+
propertySummary.group = property.getGroup();
155+
}
156+
if (!property.getMeasurementUnit().isUndefined()) {
157+
propertySummary.measurementUnit = {
158+
name: property.getMeasurementUnit().getName(),
159+
};
160+
}
161+
if (property.getChoices().size() > 0) {
162+
propertySummary.choices = mapVector(property.getChoices(), choice => ({
163+
value: choice.getValue(),
164+
label: choice.getLabel(),
165+
}));
166+
}
167+
if (property.isHidden()) {
168+
propertySummary.hidden = true;
169+
}
170+
if (property.isDeprecated()) {
171+
propertySummary.deprecated = true;
172+
}
173+
if (property.isAdvanced()) {
174+
propertySummary.advanced = true;
175+
}
176+
const extraInfo = property.getExtraInfo().toJSArray();
177+
if (extraInfo.length > 0) {
178+
propertySummary.extraInfo = extraInfo;
179+
}
180+
181+
return propertySummary;
132182
};
133183

134-
const getPropertiesSummary = (
135-
propertiesMetadata: gdMapStringPropertyDescriptor
136-
) => {
137-
return propertiesMetadata
138-
.keys()
139-
.toJSArray()
140-
.map(propertyName => {
141-
const property = propertiesMetadata.get(propertyName);
142-
return getPropertySummary(propertyName, property);
184+
const getPropertiesSummary = ({
185+
propertiesMetadata,
186+
propertiesContainer,
187+
}: {|
188+
propertiesMetadata?: gdMapStringPropertyDescriptor,
189+
propertiesContainer?: gdPropertiesContainer,
190+
|}) => {
191+
if (propertiesMetadata)
192+
return propertiesMetadata
193+
.keys()
194+
.toJSArray()
195+
.map(propertyName => {
196+
const property = propertiesMetadata.get(propertyName);
197+
return getPropertySummary(propertyName, property);
198+
});
199+
200+
if (propertiesContainer)
201+
return mapVector(propertiesContainer, namedProperty => {
202+
return getPropertySummary(namedProperty.getName(), namedProperty);
143203
});
204+
205+
return [];
144206
};
145207

146208
export const buildExtensionSummary = ({
147209
gd,
210+
eventsFunctionsExtension,
148211
extension,
149212
}: {
150213
gd: libGDevelop,
214+
eventsFunctionsExtension: gdEventsFunctionsExtension | null,
151215
extension: gdPlatformExtension,
152216
}): ExtensionSummary => {
153217
const objects: { [string]: ObjectSummary } = {};
@@ -238,10 +302,27 @@ export const buildExtensionSummary = ({
238302
return;
239303
}
240304

305+
const objectName =
306+
objectType.split('::').pop() || 'Unrecognized object type format';
307+
308+
const eventsBasedObjects = eventsFunctionsExtension
309+
? eventsFunctionsExtension.getEventsBasedObjects()
310+
: null;
311+
312+
const eventsBasedObject =
313+
eventsBasedObjects && eventsBasedObjects.has(objectName)
314+
? eventsBasedObjects.get(objectName)
315+
: null;
316+
241317
objects[objectType] = {
242318
name: objectMetadata.getName(),
243319
fullName: objectMetadata.getFullName(),
244320
description: objectMetadata.getDescription(),
321+
properties: eventsBasedObject
322+
? getPropertiesSummary({
323+
propertiesContainer: eventsBasedObject.getPropertyDescriptors(),
324+
})
325+
: undefined,
245326
actions: generateInstructionsSummaries({
246327
instructionsMetadata: objectMetadata.getAllActions(),
247328
}),
@@ -274,6 +355,12 @@ export const buildExtensionSummary = ({
274355
name: behaviorMetadata.getName(),
275356
fullName: behaviorMetadata.getFullName(),
276357
description: behaviorMetadata.getDescription(),
358+
properties: getPropertiesSummary({
359+
propertiesMetadata: behaviorMetadata.getProperties(),
360+
}),
361+
sharedProperties: getPropertiesSummary({
362+
propertiesMetadata: behaviorMetadata.getSharedProperties(),
363+
}),
277364
actions: generateInstructionsSummaries({
278365
instructionsMetadata: behaviorMetadata.getAllActions(),
279366
}),
@@ -312,7 +399,9 @@ export const buildExtensionSummary = ({
312399
onlyWorkingFor2D: effectMetadata.isMarkedAsOnlyWorkingFor2D(),
313400
onlyWorkingFor3D: effectMetadata.isMarkedAsOnlyWorkingFor3D(),
314401
unique: effectMetadata.isMarkedAsUnique(),
315-
properties: getPropertiesSummary(effectMetadata.getProperties()),
402+
properties: getPropertiesSummary({
403+
propertiesMetadata: effectMetadata.getProperties(),
404+
}),
316405
};
317406

318407
effects[effectType] = effectSummary;

newIDE/app/src/EditorFunctions/SimplifiedProject/SimplifiedProject.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,20 @@ export const makeSimplifiedProjectBuilder = (gd: libGDevelop) => {
383383
).filter(Boolean);
384384

385385
const extensionsSummary: ProjectSpecificExtensionsSummary = {
386-
extensionSummaries: projectSpecificExtensions.map(extension =>
387-
buildExtensionSummary({ gd, extension })
388-
),
386+
extensionSummaries: projectSpecificExtensions.map(extension => {
387+
const extensionName = extension.getName();
388+
const eventsFunctionsExtension = project.hasEventsFunctionsExtensionNamed(
389+
extensionName
390+
)
391+
? project.getEventsFunctionsExtension(extensionName)
392+
: null;
393+
394+
return buildExtensionSummary({
395+
gd,
396+
eventsFunctionsExtension,
397+
extension,
398+
});
399+
}),
389400
};
390401

391402
const duration = Date.now() - startTime;

newIDE/app/src/EditorFunctions/SimplifiedProject/SimplifiedProject.spec.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,20 @@ describe('SimplifiedProject', () => {
949949
],
950950
"fullName": "Fake behavior with two properties",
951951
"name": "FakeBehavior::FakeBehavior",
952+
"properties": Array [
953+
Object {
954+
"description": "",
955+
"label": "Property 1",
956+
"name": "property1",
957+
"type": "",
958+
},
959+
Object {
960+
"description": "A description for property 2",
961+
"name": "property2",
962+
"type": "Boolean",
963+
},
964+
],
965+
"sharedProperties": Array [],
952966
},
953967
},
954968
"description": "A fake extension with a fake behavior containing 2 properties.",
@@ -966,4 +980,83 @@ describe('SimplifiedProject', () => {
966980

967981
project.delete();
968982
});
983+
984+
it('should include summaries of project specific extensions with events based objects', async () => {
985+
const gd = await initializeGDevelopJs();
986+
makeTestExtensions(gd);
987+
988+
const { project } = makeTestProject(gd);
989+
990+
const projectSpecificExtensionsSummary = makeSimplifiedProjectBuilder(
991+
gd
992+
).getProjectSpecificExtensionsSummary(project);
993+
994+
const buttonExtensionSummary = projectSpecificExtensionsSummary.extensionSummaries.find(
995+
extensionSummary => extensionSummary.extensionName === 'Button'
996+
);
997+
998+
expect(buttonExtensionSummary).toMatchInlineSnapshot(`
999+
Object {
1000+
"behaviors": Object {},
1001+
"description": "Fake event-based object",
1002+
"effects": Object {},
1003+
"extensionFullName": "Fake event-based object",
1004+
"extensionName": "Button",
1005+
"freeActions": Array [],
1006+
"freeConditions": Array [],
1007+
"freeExpressions": Array [],
1008+
"objects": Object {
1009+
"Button::PanelSpriteButton": Object {
1010+
"actions": Array [],
1011+
"conditions": Array [],
1012+
"description": "A fake button made with a panel sprite and events.",
1013+
"expressions": Array [],
1014+
"fullName": "PanelSpriteButton",
1015+
"name": "Button::PanelSpriteButton",
1016+
"properties": Array [
1017+
Object {
1018+
"description": "",
1019+
"label": "Label offset on Y axis when pressed",
1020+
"name": "PressedLabelOffsetY",
1021+
"type": "number",
1022+
},
1023+
Object {
1024+
"description": "The left padding of the button",
1025+
"group": "Padding",
1026+
"label": "Left padding",
1027+
"measurementUnit": Object {
1028+
"name": "Pixel",
1029+
},
1030+
"name": "LeftPadding",
1031+
"type": "number",
1032+
},
1033+
Object {
1034+
"description": "",
1035+
"group": "Padding",
1036+
"label": "Right padding",
1037+
"name": "RightPadding",
1038+
"type": "number",
1039+
},
1040+
Object {
1041+
"description": "",
1042+
"group": "Padding",
1043+
"label": "Top padding",
1044+
"name": "TopPadding",
1045+
"type": "number",
1046+
},
1047+
Object {
1048+
"description": "",
1049+
"group": "Padding",
1050+
"label": "Down padding",
1051+
"name": "DownPadding",
1052+
"type": "number",
1053+
},
1054+
],
1055+
},
1056+
},
1057+
}
1058+
`);
1059+
1060+
project.delete();
1061+
});
9691062
});

newIDE/app/src/fixtures/TestExtensions.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// @flow
2-
let testExtensionsAdded = false;
2+
let testExtensionsAdded = new WeakSet();
33

44
/**
55
* Create dummy extensions into gd.JsPlatform
66
* @param gd The GD instance to use to create the extensions and find the platform.
77
*/
88
export const makeTestExtensions = (gd: libGDevelop) => {
99
// Be sure to only add test extensions once, as gd.JsPlatform is a singleton.
10-
if (testExtensionsAdded) return;
11-
testExtensionsAdded = true;
10+
if (testExtensionsAdded.has(gd)) return;
11+
testExtensionsAdded.add(gd);
1212

1313
const platform = gd.JsPlatform.get();
1414

@@ -185,9 +185,11 @@ export const makeTestExtensions = (gd: libGDevelop) => {
185185

186186
behaviorProperties
187187
.getOrCreate('property1')
188+
.setLabel('Property 1')
188189
.setValue(behaviorContent.getStringAttribute('property1'));
189190
behaviorProperties
190191
.getOrCreate('property2')
192+
.setDescription('A description for property 2')
191193
.setValue(
192194
behaviorContent.getBoolAttribute('property2') ? 'true' : 'false'
193195
)
@@ -336,6 +338,13 @@ export const makeTestExtensions = (gd: libGDevelop) => {
336338
'',
337339
'MIT'
338340
);
341+
extension.addObject(
342+
'PanelSpriteButton',
343+
'PanelSpriteButton',
344+
'A fake button made with a panel sprite and events.',
345+
'res/button.svg',
346+
new gd.ObjectJsImplementation()
347+
);
339348
platform.addNewExtension(extension);
340349
extension.delete(); // Release the extension as it was copied inside gd.JsPlatform
341350
}

newIDE/app/src/fixtures/TestProject.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ export const makeTestProject = (gd /*: libGDevelop */) /*: TestProject */ => {
142142
.insertNew('LeftPadding', 1)
143143
.setType('number')
144144
.setLabel('Left padding')
145+
.setMeasurementUnit(gd.MeasurementUnit.getPixel())
146+
.setDescription('The left padding of the button')
145147
.setGroup('Padding');
146148
buttonProperties
147149
.insertNew('RightPadding', 2)

0 commit comments

Comments
 (0)