CRaph0705 / Combat-Helper

Little tool for DM to organize dnd combats
1 stars 0 forks source link

Add action queue #195

Open CRaph0705 opened 10 months ago

CRaph0705 commented 10 months ago

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

CRaph0705 commented 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

CRaph0705 commented 10 months ago

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);
}

}

CRaph0705 commented 10 months ago

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);
}

}