Added bulk spell queue (#10241)

* Added bulk spell queue

* Removed extra comment

* Moved queue to store
This commit is contained in:
Keith Holliday
2018-04-23 20:30:55 -05:00
committed by GitHub
parent 7d7fe6047c
commit 8d25a5d140
3 changed files with 58 additions and 8 deletions

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

View File

@@ -92,10 +92,13 @@ export default {
let spellText = typeof spell.text === 'function' ? spell.text() : spell.text; let spellText = typeof spell.text === 'function' ? spell.text() : spell.text;
let apiResult = await this.$store.dispatch('user:castSpell', {key: spell.key, targetId}); let apiResult = await this.$store.dispatch('user:castSpell', {
key: spell.key,
targetId,
pinType: spell.pinType,
});
let msg = ''; let msg = '';
switch (type) { switch (type) {
case 'task': case 'task':
msg = this.$t('youCastTarget', { msg = this.$t('youCastTarget', {
@@ -147,8 +150,7 @@ export default {
} }
} }
// @TODO: if (!beforeQuestProgress) return;
if (!beforeQuestProgress) return apiResult;
let questProgress = this.questProgress() - beforeQuestProgress; let questProgress = this.questProgress() - beforeQuestProgress;
if (questProgress > 0) { if (questProgress > 0) {
let userQuest = this.quests[this.user.party.quest.key]; let userQuest = this.quests[this.user.party.quest.key];
@@ -159,8 +161,7 @@ export default {
} }
} }
return;
return apiResult;
// @TOOD: User.sync(); // @TOOD: User.sync();
}, },
castCancel () { castCancel () {

View File

@@ -1,4 +1,5 @@
import { loadAsyncResource } from 'client/libs/asyncResource'; import { loadAsyncResource } from 'client/libs/asyncResource';
import spellQueue from 'client/libs/spellQueue';
import setProps from 'lodash/set'; import setProps from 'lodash/set';
import axios from 'axios'; import axios from 'axios';
@@ -117,11 +118,19 @@ export async function movePinnedItem (store, params) {
} }
export function castSpell (store, params) { export function castSpell (store, params) {
if (params.pinType !== 'card' && !params.quantity) {
spellQueue.queue({key: params.key, targetId: params.targetId}, store);
return;
}
let spellUrl = `/api/v3/user/class/cast/${params.key}`; let spellUrl = `/api/v3/user/class/cast/${params.key}`;
if (params.targetId) spellUrl += `?targetId=${params.targetId}`; const data = {};
return axios.post(spellUrl); if (params.targetId) spellUrl += `?targetId=${params.targetId}`;
if (params.quantity) data.quantity = params.quantity;
return axios.post(spellUrl, data);
} }
export function openMysteryItem () { export function openMysteryItem () {