Open CRaph0705 opened 10 months ago
add an actionQueue to the encounter : this.actionQueue = [];
modify handle change function like this to add actions to queue
handleUnitChange(action) { this.actionQueue.push(action); this.processActionQueue(); }
and add a function to process the queue
processActionQueue() { if (!this.isProcessingQueue && this.actionQueue.length > 0) { this.isProcessingQueue = true; const action = this.actionQueue.shift(); switch (action) { case 'next': this.nextUnit(); break; case 'previous': this.previousUnit(); break; }
// wait for the end of animation (slide change) before next action
setTimeout(() => {
this.isProcessingQueue = false;
this.processActionQueue();
}, 400);
}
}
and modify next and prev unit functions :
nextUnit() { if (this.swiper && this.swiper.slideNext) { // ...
if (this.activeUnit.isDead) {
setTimeout(() => {
this.isProcessingQueue = false;
this.processActionQueue();
}, 350);
} else {
setTimeout(() => {
this.processActionQueue();
}, 400);
}
}
}
previousUnit() { // ...
if (this.activeUnit.isDead) {
setTimeout(() => {
this.isProcessingQueue = false;
this.processActionQueue();
}, 350);
} else {
setTimeout(() => {
this.processActionQueue();
}, 400);
}
}
nextUnit has to load the next slide of the carousel. disable any other call before a short time
await for carousel property like a boolean isReady to make available again navigation functions