Skip to content

Commit 70ac0d0

Browse files
committed
Add Else support for AI
1 parent f1401b3 commit 70ac0d0

File tree

5 files changed

+284
-55
lines changed

5 files changed

+284
-55
lines changed

newIDE/app/src/EventsSheet/EventsTree/BottomButtons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default function BottomButtons({
5454
const gdevelopTheme = React.useContext(GDevelopThemeContext);
5555
const onDrop = () => {
5656
draggedNode &&
57+
draggedNode.event &&
5758
moveEventToEventsList({
5859
targetEventsList: rootEventsList,
5960
movingEvent: draggedNode.event,

newIDE/app/src/EventsSheet/EventsTree/TextRenderer/TextRenderer.spec.js

Lines changed: 166 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,45 @@ describe('EventsTree/TextRenderer', () => {
2727
parameters: ['MySpriteObject', '=', '1'],
2828
},
2929
{
30-
type: { value: 'Montre' },
30+
type: { value: 'Show' },
3131
parameters: ['GroupOfObjects', ''],
3232
},
3333
],
3434
events: [
35+
{
36+
type: 'BuiltinCommonInstructions::Else',
37+
conditions: [],
38+
actions: [
39+
{
40+
type: { value: 'Show' },
41+
parameters: ['GroupOfObjects', ''],
42+
},
43+
],
44+
},
45+
{
46+
type: 'BuiltinCommonInstructions::Repeat',
47+
repeatExpression: '1',
48+
conditions: [],
49+
actions: [],
50+
},
51+
{
52+
type: 'BuiltinCommonInstructions::Else',
53+
conditions: [
54+
{
55+
type: { value: 'PlatformBehavior::IsFalling' },
56+
parameters: [
57+
'GroupOfSpriteObjectsWithBehaviors',
58+
'PlatformerObject',
59+
],
60+
},
61+
],
62+
actions: [
63+
{
64+
type: { value: 'ChangeAnimation' },
65+
parameters: ['MySpriteObject', '=', '1'],
66+
},
67+
],
68+
},
3569
{
3670
type: 'BuiltinCommonInstructions::Standard',
3771
variables: [
@@ -171,7 +205,7 @@ describe('EventsTree/TextRenderer', () => {
171205
parameters: ['MySpriteObject', '=', '1'],
172206
},
173207
{
174-
type: { value: 'Montre' },
208+
type: { value: 'Show' },
175209
parameters: ['GroupOfObjects', ''],
176210
},
177211
],
@@ -194,7 +228,7 @@ describe('EventsTree/TextRenderer', () => {
194228
parameters: ['MySpriteObject', '=', '1'],
195229
},
196230
{
197-
type: { value: 'Montre' },
231+
type: { value: 'Show' },
198232
parameters: ['GroupOfObjects', ''],
199233
},
200234
],
@@ -220,7 +254,7 @@ describe('EventsTree/TextRenderer', () => {
220254
parameters: ['MySpriteObject', '=', '1'],
221255
},
222256
{
223-
type: { value: 'Montre' },
257+
type: { value: 'Show' },
224258
parameters: ['GroupOfObjects', ''],
225259
},
226260
],
@@ -232,6 +266,69 @@ describe('EventsTree/TextRenderer', () => {
232266
},
233267
],
234268
},
269+
{
270+
type: 'BuiltinCommonInstructions::Standard',
271+
conditions: [
272+
{
273+
type: { value: 'PlatformBehavior::IsFalling' },
274+
parameters: [
275+
'GroupOfSpriteObjectsWithBehaviors',
276+
'PlatformerObject',
277+
],
278+
},
279+
],
280+
actions: [
281+
{
282+
type: { value: 'ChangeAnimation' },
283+
parameters: ['MySpriteObject', '=', '1'],
284+
},
285+
],
286+
},
287+
{
288+
type: 'BuiltinCommonInstructions::Else',
289+
conditions: [],
290+
actions: [
291+
{
292+
type: { value: 'Show' },
293+
parameters: ['GroupOfObjects', ''],
294+
},
295+
],
296+
},
297+
{
298+
type: 'BuiltinCommonInstructions::Else',
299+
conditions: [
300+
{
301+
type: { value: 'PlatformBehavior::IsFalling' },
302+
parameters: [
303+
'GroupOfSpriteObjectsWithBehaviors',
304+
'PlatformerObject',
305+
],
306+
},
307+
],
308+
actions: [
309+
{
310+
type: { value: 'ChangeAnimation' },
311+
parameters: ['MySpriteObject', '=', '1'],
312+
},
313+
],
314+
},
315+
{
316+
type: 'BuiltinCommonInstructions::Else',
317+
variables: [
318+
{
319+
name: 'MyElseVar',
320+
type: 'number',
321+
value: '42',
322+
},
323+
],
324+
conditions: [],
325+
actions: [
326+
{
327+
type: { value: 'Cache' },
328+
parameters: ['GroupOfObjects', ''],
329+
},
330+
],
331+
},
235332
],
236333
},
237334
];
@@ -257,6 +354,29 @@ describe('EventsTree/TextRenderer', () => {
257354
- Show GroupOfObjects
258355
Sub-events:
259356
<event-0.0>
357+
~~Else~~ (Else is ignored because not following a standard event)
358+
359+
Conditions:
360+
(no conditions)
361+
Actions:
362+
- Show GroupOfObjects
363+
</event-0.0>
364+
<event-0.1>
365+
Repeat \`1\` times these:
366+
Conditions:
367+
(no conditions)
368+
Actions:
369+
(no actions)
370+
</event-0.1>
371+
<event-0.2>
372+
~~Else if~~ (Else is ignored because not following a standard event)
373+
374+
Conditions:
375+
- GroupOfSpriteObjectsWithBehaviors is falling
376+
Actions:
377+
- Change the number of the animation of MySpriteObject: = 1
378+
</event-0.2>
379+
<event-0.3>
260380
- Declare local variable \\"MyVariable\\" of type \\"number\\" with value \`1\`
261381
- Declare local variable \\"MyArray\\" of type \\"array\\" with value \`[-0.1,2.3,\\"three\\"]\`
262382
- Declare local variable \\"MyStructure\\" of type \\"structure\\" with value \`{\\"MyChild\\":1,\\"MyChild2\\":[1,2,\\"three\\",true]}\`
@@ -271,8 +391,8 @@ describe('EventsTree/TextRenderer', () => {
271391
- Change the number of the animation of MySpriteObject: = 1
272392
- Hide GroupOfObjects
273393
- Unknown or unsupported instruction
274-
</event-0.0>
275-
<event-0.1>
394+
</event-0.3>
395+
<event-0.4>
276396
While these conditions are true:
277397
- GroupOfSpriteObjectsWithBehaviors is falling
278398
Then do:
@@ -281,32 +401,63 @@ describe('EventsTree/TextRenderer', () => {
281401
Actions:
282402
- Change the number of the animation of MySpriteObject: = 1
283403
- Show GroupOfObjects
284-
</event-0.1>
285-
<event-0.2>
404+
</event-0.4>
405+
<event-0.5>
286406
Repeat \`3 + 4\` times these:
287407
Conditions:
288408
- GroupOfSpriteObjectsWithBehaviors is falling
289409
Actions:
290410
- Change the number of the animation of MySpriteObject: = 1
291411
- Show GroupOfObjects
292-
</event-0.2>
293-
<event-0.3>
412+
</event-0.5>
413+
<event-0.6>
294414
Group called \\"My super group\\":
295415
Sub-events:
296-
<event-0.3.0>
416+
<event-0.6.0>
297417
Conditions:
298418
- GroupOfSpriteObjectsWithBehaviors is falling
299419
Actions:
300420
- Change the number of the animation of MySpriteObject: = 1
301421
- Show GroupOfObjects
302-
</event-0.3.0>
303-
<event-0.3.1>
422+
</event-0.6.0>
423+
<event-0.6.1>
304424
Conditions:
305425
(no conditions)
306426
Actions:
307427
(no actions)
308-
</event-0.3.1>
309-
</event-0.3>
428+
</event-0.6.1>
429+
</event-0.6>
430+
<event-0.7>
431+
Conditions:
432+
- GroupOfSpriteObjectsWithBehaviors is falling
433+
Actions:
434+
- Change the number of the animation of MySpriteObject: = 1
435+
</event-0.7>
436+
<event-0.8>
437+
Else
438+
439+
Conditions:
440+
(no conditions)
441+
Actions:
442+
- Show GroupOfObjects
443+
</event-0.8>
444+
<event-0.9>
445+
Else if
446+
447+
Conditions:
448+
- GroupOfSpriteObjectsWithBehaviors is falling
449+
Actions:
450+
- Change the number of the animation of MySpriteObject: = 1
451+
</event-0.9>
452+
<event-0.10>
453+
Else
454+
- Declare local variable \\"MyElseVar\\" of type \\"number\\" with value \`42\`
455+
456+
Conditions:
457+
(no conditions)
458+
Actions:
459+
- Hide GroupOfObjects
460+
</event-0.10>
310461
</event-0>"
311462
`);
312463
} finally {

0 commit comments

Comments
 (0)