Skip to content

Commit 481bd73

Browse files
committed
Improve AI events handling
Don't show in changelog
1 parent 71c0f66 commit 481bd73

File tree

2 files changed

+108
-10
lines changed

2 files changed

+108
-10
lines changed

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

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('EventsTree/TextRenderer', () => {
99
it('renders events as text', () => {
1010
const { project } = makeTestProject(gd);
1111
try {
12+
const longCommentText = 'A'.repeat(450);
1213
const serializedEvents = [
1314
{
1415
type: 'BuiltinCommonInstructions::Standard',
@@ -331,6 +332,51 @@ describe('EventsTree/TextRenderer', () => {
331332
},
332333
],
333334
},
335+
// Disabled event with conditions/actions - should get disabled="true"
336+
{
337+
type: 'BuiltinCommonInstructions::Standard',
338+
disabled: true,
339+
conditions: [
340+
{
341+
type: { value: 'PlatformBehavior::IsFalling' },
342+
parameters: [
343+
'GroupOfSpriteObjectsWithBehaviors',
344+
'PlatformerObject',
345+
],
346+
},
347+
],
348+
actions: [
349+
{
350+
type: { value: 'Show' },
351+
parameters: ['GroupOfObjects', ''],
352+
},
353+
],
354+
events: [
355+
// Sub-event of disabled parent - should get disabled-because-of-ancestor="true"
356+
{
357+
type: 'BuiltinCommonInstructions::Standard',
358+
conditions: [],
359+
actions: [
360+
{
361+
type: { value: 'Show' },
362+
parameters: ['GroupOfObjects', ''],
363+
},
364+
],
365+
},
366+
],
367+
},
368+
// Short comment
369+
{
370+
type: 'BuiltinCommonInstructions::Comment',
371+
comment: 'This is a short comment',
372+
color: { r: 255, g: 230, b: 109, textR: 0, textG: 0, textB: 0 },
373+
},
374+
// Long comment (>400 chars) - should be truncated
375+
{
376+
type: 'BuiltinCommonInstructions::Comment',
377+
comment: longCommentText,
378+
color: { r: 255, g: 230, b: 109, textR: 0, textG: 0, textB: 0 },
379+
},
334380
];
335381

336382
const eventsList = new gd.EventsList();
@@ -361,7 +407,7 @@ describe('EventsTree/TextRenderer', () => {
361407
Actions:
362408
- Show GroupOfObjects
363409
</event-0.0>
364-
<event-0.1>
410+
<event-0.1 type=\\"repeat\\">
365411
Repeat \`1\` times these:
366412
Conditions:
367413
(no conditions)
@@ -392,7 +438,7 @@ describe('EventsTree/TextRenderer', () => {
392438
- Hide GroupOfObjects
393439
- Unknown or unsupported instruction
394440
</event-0.3>
395-
<event-0.4>
441+
<event-0.4 type=\\"while\\">
396442
While these conditions are true:
397443
- GroupOfSpriteObjectsWithBehaviors is falling
398444
Then do:
@@ -402,15 +448,15 @@ describe('EventsTree/TextRenderer', () => {
402448
- Change the number of the animation of MySpriteObject: = 1
403449
- Show GroupOfObjects
404450
</event-0.4>
405-
<event-0.5>
451+
<event-0.5 type=\\"repeat\\">
406452
Repeat \`3 + 4\` times these:
407453
Conditions:
408454
- GroupOfSpriteObjectsWithBehaviors is falling
409455
Actions:
410456
- Change the number of the animation of MySpriteObject: = 1
411457
- Show GroupOfObjects
412458
</event-0.5>
413-
<event-0.6>
459+
<event-0.6 type=\\"group\\">
414460
Group called \\"My super group\\":
415461
Sub-events:
416462
<event-0.6.0>
@@ -458,7 +504,26 @@ describe('EventsTree/TextRenderer', () => {
458504
Actions:
459505
- Hide GroupOfObjects
460506
</event-0.10>
461-
</event-0>"
507+
</event-0>
508+
<event-1 disabled=\\"true\\">
509+
Conditions:
510+
- GroupOfSpriteObjectsWithBehaviors is falling
511+
Actions:
512+
- Show GroupOfObjects
513+
Sub-events:
514+
<event-1.0 disabled-because-of-ancestor=\\"true\\">
515+
Conditions:
516+
(no conditions)
517+
Actions:
518+
- Show GroupOfObjects
519+
</event-1.0>
520+
</event-1>
521+
<event-2 type=\\"comment\\">
522+
This is a short comment
523+
</event-2>
524+
<event-3 type=\\"comment\\">
525+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA[cut - 50 more characters]
526+
</event-3>"
462527
`);
463528
} finally {
464529
project.delete();

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ ${actions}`,
9696
};
9797
},
9898
'BuiltinCommonInstructions::Comment': ({ event, padding }) => {
99-
return { content: `${padding}(comment - content is not displayed)` };
99+
const commentEvent = gd.asCommentEvent(event);
100+
const fullText = commentEvent.getComment();
101+
const maxLength = 400;
102+
const text =
103+
fullText.length > maxLength
104+
? fullText.slice(0, maxLength) +
105+
`[cut - ${fullText.length - maxLength} more characters]`
106+
: fullText;
107+
return { content: `${padding}${text}` };
100108
},
101109
'BuiltinCommonInstructions::While': ({ event, padding }) => {
102110
const whileEvent = gd.asWhileEvent(event);
@@ -280,16 +288,15 @@ const renderEventAsText = ({
280288
eventIndex,
281289
padding,
282290
eventPath,
291+
isAncestorDisabled,
283292
}: {|
284293
event: gdBaseEvent,
285294
eventsList: gdEventsList,
286295
eventIndex: number,
287296
padding: string,
288297
eventPath: string,
298+
isAncestorDisabled: boolean,
289299
|}) => {
290-
const isDisabled = event.isDisabled();
291-
if (isDisabled) return `${padding}(This event is disabled - ignored)`;
292-
293300
const localVariablesText =
294301
event.canHaveVariables() && event.hasVariables()
295302
? renderLocalVariablesAsText({
@@ -324,6 +331,7 @@ const renderEventAsText = ({
324331
eventsList: event.getSubEvents(),
325332
parentPath: eventPath,
326333
padding: padding + ' ',
334+
isAncestorDisabled: isAncestorDisabled || event.isDisabled(),
327335
});
328336
}
329337

@@ -334,10 +342,12 @@ export const renderEventsAsText = ({
334342
eventsList,
335343
parentPath,
336344
padding,
345+
isAncestorDisabled = false,
337346
}: {|
338347
eventsList: gdEventsList,
339348
parentPath: string,
340349
padding: string,
350+
isAncestorDisabled?: boolean,
341351
|}): string => {
342352
return mapFor(0, eventsList.getEventsCount(), i => {
343353
const event = eventsList.getEventAt(i);
@@ -349,6 +359,7 @@ export const renderEventsAsText = ({
349359
eventIndex: i,
350360
eventPath,
351361
padding: padding + ' ',
362+
isAncestorDisabled,
352363
});
353364

354365
let elseOfAttribute = '';
@@ -362,7 +373,29 @@ export const renderEventsAsText = ({
362373
elseOfAttribute = ` else-of="event-${previousEventPath}"`;
363374
}
364375

365-
return `${padding}<event-${eventPath}${elseOfAttribute}>
376+
const eventTypeToAttribute: { [string]: string } = {
377+
'BuiltinCommonInstructions::Comment': 'comment',
378+
'BuiltinCommonInstructions::While': 'while',
379+
'BuiltinCommonInstructions::Link': 'link',
380+
'BuiltinCommonInstructions::Group': 'group',
381+
'BuiltinCommonInstructions::ForEachChildVariable':
382+
'for-each-child-variable',
383+
'BuiltinCommonInstructions::ForEach': 'for-each',
384+
'BuiltinCommonInstructions::Repeat': 'repeat',
385+
};
386+
const typeAttributeValue = eventTypeToAttribute[event.getType()];
387+
const typeAttribute = typeAttributeValue
388+
? ` type="${typeAttributeValue}"`
389+
: '';
390+
391+
let disabledAttribute = '';
392+
if (event.isDisabled()) {
393+
disabledAttribute = ' disabled="true"';
394+
} else if (isAncestorDisabled) {
395+
disabledAttribute = ' disabled-because-of-ancestor="true"';
396+
}
397+
398+
return `${padding}<event-${eventPath}${elseOfAttribute}${typeAttribute}${disabledAttribute}>
366399
${eventAndSubEventsText}
367400
${padding}</event-${eventPath}>`;
368401
}).join('\n');

0 commit comments

Comments
 (0)