mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Added bulk spell queue (#10241)
* Added bulk spell queue * Removed extra comment * Moved queue to store
This commit is contained in:
40
website/client/libs/spellQueue.js
Normal file
40
website/client/libs/spellQueue.js
Normal file
@@ -0,0 +1,40 @@
|
||||
let store = {};
|
||||
|
||||
let currentCount = 1;
|
||||
let currentSpell = {
|
||||
key: '',
|
||||
};
|
||||
let timer = null;
|
||||
|
||||
// @TODO: We are using this lib in actions, so we have to inject store
|
||||
function setStore (storeInc) {
|
||||
store = storeInc;
|
||||
}
|
||||
|
||||
function castSpell () {
|
||||
clearTimeout(timer);
|
||||
|
||||
currentSpell.quantity = currentCount;
|
||||
store.dispatch('user:castSpell', currentSpell);
|
||||
|
||||
currentCount = 0;
|
||||
}
|
||||
|
||||
function queue (spell, storeInc) {
|
||||
setStore(storeInc);
|
||||
|
||||
currentCount += 1;
|
||||
|
||||
if (currentSpell.key && spell.key !== currentSpell.key) {
|
||||
castSpell();
|
||||
}
|
||||
|
||||
currentSpell = spell;
|
||||
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
castSpell();
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
export default { queue };
|
||||
Reference in New Issue
Block a user