Skip to content

Commit 163612d

Browse files
committed
UPDATE: animations.js
added a stop.
1 parent f116113 commit 163612d

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

src/code/js/animation.js

+41-30
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,44 @@ async function animateElement(elem, wires) {
142142
};
143143

144144
async function animatePath(i) {
145-
if (isPaused) return;
146-
let type = pathElements[i].type;
147-
let id = pathElements[i].id;
148-
if (type == "DFF") type = "ff";
149-
let elem = document.getElementById(`animation-${type}-${id}`);
150-
let wire1 = document.getElementById(`${type}-${id}-Wire1`)
151-
let wire2 = document.getElementById(`${type}-${id}-Wire2`)
152-
let wire3 = document.getElementById(`${type}-${id}-Wire3`)
153-
let wire4 = document.getElementById(`${type}-${id}-Wire4`) ?? null;
154-
let wire5 = document.getElementById(`${type}-${id}-Wire5`) ?? null;
155-
elem.style.display = 'block';
156-
let wiresLength = wire4 != null
157-
? wire5 != null
158-
? 5
159-
: 4
160-
: 3;
161-
animateElement(elem, [wire1, wire2, wire3, wire4, wire5]);
162-
setTimeout(() => {
163-
if (i < pathElements.length - 2) {
164-
elem.remove();
165-
generateAnimations({ element: elem });
166-
animatePath(i + 1);
167-
} else {
168-
elem.remove();
169-
generateAnimations({ element: elem });
170-
play.firstChild.className = 'fa-solid top-bar fa-circle-play';
171-
isPaused = true;
172-
}
173-
}, wiresLength * speedValue);
174-
}
145+
// Stop
146+
if (i >= 5000) {
147+
play.firstChild.className = 'fa-solid top-bar fa-circle-play';
148+
isPaused = true;
149+
return;
150+
}
151+
152+
if (isPaused) return;
153+
154+
let type = pathElements[i].type;
155+
let id = pathElements[i].id;
156+
if (type == "DFF") type = "ff";
157+
158+
let elem = document.getElementById(`animation-${type}-${id}`);
159+
let wire1 = document.getElementById(`${type}-${id}-Wire1`);
160+
let wire2 = document.getElementById(`${type}-${id}-Wire2`);
161+
let wire3 = document.getElementById(`${type}-${id}-Wire3`);
162+
let wire4 = document.getElementById(`${type}-${id}-Wire4`) ?? null;
163+
let wire5 = document.getElementById(`${type}-${id}-Wire5`) ?? null;
164+
165+
elem.style.display = 'block';
166+
167+
let wiresLength = wire4 != null
168+
? (wire5 != null ? 5 : 4)
169+
: 3;
170+
171+
animateElement(elem, [wire1, wire2, wire3, wire4, wire5]);
172+
173+
setTimeout(() => {
174+
if (i < pathElements.length - 2) {
175+
elem.remove();
176+
generateAnimations({ element: elem });
177+
animatePath(i + 1);
178+
} else {
179+
elem.remove();
180+
generateAnimations({ element: elem });
181+
play.firstChild.className = 'fa-solid top-bar fa-circle-play';
182+
isPaused = true;
183+
}
184+
}, wiresLength * speedValue);
185+
}

0 commit comments

Comments
 (0)