Skip to content

Commit 08ba90d

Browse files
committed
fixed bug with empty array, and animated control instr
1 parent caf48a0 commit 08ba90d

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

src/features/cseMachine/CseMachineAnimation.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class CseAnimation {
115115
break;
116116
case 'SpreadElement':
117117
CseAnimation.animations.push(
118-
new ControlExpansionAnimation(lastControlComponent, CseAnimation.getNewControlItems()),
118+
new ControlExpansionAnimation(lastControlComponent, CseAnimation.getNewControlItems())
119119
);
120120
break;
121121
case 'AssignmentExpression':
@@ -285,31 +285,35 @@ export class CseAnimation {
285285
case InstrType.SPREAD:
286286
const prevcontrol = Layout.previousControlComponent.stackItemComponents;
287287
const control = Layout.controlComponent.stackItemComponents;
288-
const array = Layout.previousStashComponent.stashItemComponents.at(-1)!.arrow!.target! as ArrayValue;
288+
const array = Layout.previousStashComponent.stashItemComponents.at(-1)!.arrow!
289+
.target! as ArrayValue;
289290

290291
console.log(array);
291292

292293
let currCallInstr;
293294
let prevCallInstr;
294-
295-
296295

297296
for (let i = 0; control.at(-i) != undefined; i++) {
298-
if (control.at(-i)?.text.includes("call ")) { // find call instr above
297+
if (control.at(-i)?.text.includes('call ')) {
298+
// find call instr above
299299
currCallInstr = control.at(-i);
300300
break;
301301
}
302302
}
303303

304304
for (let i = 0; prevcontrol.at(-i) != undefined; i++) {
305-
if (prevcontrol.at(-i)?.text.includes("call ")) { // find call instr above
305+
if (prevcontrol.at(-i)?.text.includes('call ')) {
306+
// find call instr above
306307
prevCallInstr = prevcontrol.at(-i);
307308
break;
308309
}
309310
}
310311

311-
const resultItems = array.data.length !== 0 ? Layout.stashComponent.stashItemComponents.slice(-array.data.length) : [];
312-
312+
const resultItems =
313+
array.data.length !== 0
314+
? Layout.stashComponent.stashItemComponents.slice(-array.data.length)
315+
: [];
316+
313317
CseAnimation.animations.push(
314318
new ArraySpreadAnimation(
315319
lastControlComponent,
@@ -318,7 +322,6 @@ export class CseAnimation {
318322
currCallInstr!,
319323
prevCallInstr!
320324
)
321-
322325
);
323326
break;
324327
case InstrType.ARRAY_LENGTH:

src/features/cseMachine/animationComponents/ArraySpreadAnimation.tsx

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,34 @@ export class ArraySpreadAnimation extends Animatable {
4545
this.endX = stashItem!.x() + stashItem!.width();
4646
this.controlInstrAnimation = new AnimatedTextbox(
4747
controlInstrItem.text,
48-
getNodePosition(controlInstrItem),
48+
getNodePosition(controlInstrItem),
4949
{ rectProps: { stroke: defaultActiveColor() } }
5050
);
5151
this.stashItemAnimation = new AnimatedTextbox(stashItem.text, getNodePosition(stashItem), {
52-
rectProps: {
53-
stroke: defaultDangerColor()
54-
}
55-
});
52+
rectProps: {
53+
stroke: defaultDangerColor()
54+
}
55+
});
5656

5757
// call instr above
5858
this.prevCallInstrAnimation = new AnimatedTextbox(
5959
this.prevCallInstrItem.text,
60-
{ ...getNodePosition(this.prevCallInstrItem),
61-
opacity: 0 },
60+
{ ...getNodePosition(this.prevCallInstrItem), opacity: 0 },
6261
{ rectProps: { stroke: defaultActiveColor() } }
6362
);
6463

6564
this.currCallInstrAnimation = new AnimatedTextbox(
6665
this.currCallInstrItem.text,
67-
{ ...getNodePosition(this.currCallInstrItem),
68-
opacity: 0 },
66+
{ ...getNodePosition(this.currCallInstrItem), opacity: 0 },
6967
{ rectProps: { stroke: defaultActiveColor() } }
7068
);
7169

7270
this.resultAnimations = resultItems.map(item => {
7371
return new AnimatedTextbox(item.text, {
74-
...getNodePosition(item),
75-
opacity: 0
76-
})});
72+
...getNodePosition(item),
73+
opacity: 0
74+
});
75+
});
7776
if (stashItem.arrow) {
7877
this.arrowAnimation = new AnimatedGenericArrow(stashItem.arrow, { opacity: 0 });
7978
}
@@ -103,10 +102,8 @@ export class ArraySpreadAnimation extends Animatable {
103102
const fadeDuration = ((animationConfig?.duration ?? 1) * 3) / 4;
104103
const fadeInDelay = (animationConfig?.delay ?? 0) + (animationConfig?.duration ?? 1) / 4;
105104

106-
107105
// Move spread instruction next to stash item (array pointer)
108106
await Promise.all([
109-
110107
// Show change in call arity
111108
this.prevCallInstrAnimation.animateTo(
112109
{ scaleX: 1.1, scaleY: 1.1, opacity: 0 },
@@ -118,35 +115,24 @@ export class ArraySpreadAnimation extends Animatable {
118115
{ duration: 0.3, easing: Easings.StrongEaseOut }
119116
),
120117

121-
122-
123118
...this.resultAnimations.flatMap(a => [
124-
125-
a.animateTo(
126-
{ x: startX + (this.endX - startX) / 2 - this.resultItems[0]?.width() / 2 },
127-
{ duration: 0 }
128-
)
129-
]),
119+
a.animateTo(
120+
{ x: startX + (this.endX - startX) / 2 - this.resultItems[0]?.width() / 2 },
121+
{ duration: 0 }
122+
)
123+
]),
130124
this.controlInstrAnimation.animateRectTo({ stroke: defaultStrokeColor() }, animationConfig),
131125
this.controlInstrAnimation.animateTo(
132126
{
133127
x: startX,
134-
y:
135-
resultY +
136-
(this.resultItems[0]?.height() ?? this.stashItem.height()),
128+
y: resultY + (this.resultItems[0]?.height() ?? this.stashItem.height()),
137129
width: minInstrWidth
138130
},
139131
animationConfig
140132
),
141133
this.stashItemAnimation.animateRectTo({ stroke: defaultDangerColor() }, animationConfig)
142-
143134
]);
144135

145-
146-
147-
148-
149-
150136
animationConfig = { ...animationConfig, delay: 0 };
151137
// Merge all elements together to form the result
152138
await Promise.all([
@@ -156,20 +142,21 @@ export class ArraySpreadAnimation extends Animatable {
156142
{ ...animationConfig, duration: fadeDuration }
157143
),
158144
this.stashItemAnimation.animateTo({ x: resultX(0) }, animationConfig),
159-
this.stashItemAnimation.animateTo({ opacity: 0 }, { ...animationConfig, duration: fadeDuration }),
145+
this.stashItemAnimation.animateTo(
146+
{ opacity: 0 },
147+
{ ...animationConfig, duration: fadeDuration }
148+
),
160149

161150
...this.resultAnimations.flatMap((a, idx) => [
162151
a.animateTo({ x: resultX(idx) }, animationConfig),
163152
a.animateRectTo({ stroke: defaultDangerColor() }, animationConfig),
164-
a.animateTo(
165-
{ opacity: 1 },
166-
{ ...animationConfig, duration: fadeDuration, delay: fadeInDelay }
167-
),
168-
]),
169-
153+
a.animateTo(
154+
{ opacity: 1 },
155+
{ ...animationConfig, duration: fadeDuration, delay: fadeInDelay }
156+
)
157+
])
170158
]);
171159

172-
173160
this.destroy();
174161
}
175162

0 commit comments

Comments
 (0)