From 3e849ec9a84782453a4f7e35390a8ffd516058e7 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 4 Feb 2018 15:50:36 +0100 Subject: [PATCH] Revert "refactor casting spells on the client side (#9921)" (#9948) This reverts commit 03946e6a876046b9ff1b1e7349966f8ca20a55f8. --- website/client/components/tasks/spells.vue | 14 +++++++++++++ website/client/mixins/spells.js | 24 +++++++--------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/website/client/components/tasks/spells.vue b/website/client/components/tasks/spells.vue index 0cbe0b461d..d6bf2a54bd 100644 --- a/website/client/components/tasks/spells.vue +++ b/website/client/components/tasks/spells.vue @@ -188,12 +188,22 @@ export default { }; }, mounted () { + this.$root.$on('castEnd', (target, type, $event) => { + this.castEnd(target, type, $event); + }); + + document.addEventListener('keyup', this.handleKeyUp); + // @TODO: should we abstract the drawer state/local store to a library and mixing combo? We use a similar pattern in equipment const spellDrawerState = getLocalSetting(CONSTANTS.keyConstants.SPELL_DRAWER_STATE); if (spellDrawerState === CONSTANTS.valueConstants.DRAWER_CLOSED) { this.$store.state.spellOptions.spellDrawOpen = false; } }, + beforeDestroy () { + this.$root.$off('castEnd'); + document.removeEventListener('keyup', this.handleKeyUp); + }, computed: { ...mapState({user: 'user.data'}), openStatus () { @@ -201,6 +211,10 @@ export default { }, }, methods: { + handleKeyUp (keyEvent) { + if (keyEvent.keyCode !== 27) return; + this.castCancel(); + }, drawerToggled (newState) { this.$store.state.spellOptions.spellDrawOpen = newState; diff --git a/website/client/mixins/spells.js b/website/client/mixins/spells.js index 6976857cca..f0bec18674 100644 --- a/website/client/mixins/spells.js +++ b/website/client/mixins/spells.js @@ -4,10 +4,6 @@ import isArray from 'lodash/isArray'; // @TODO: Let's separate some of the business logic out of Vue if possible export default { methods: { - handleCastCancelKeyUp (keyEvent) { - if (keyEvent.keyCode !== 27) return; - this.castCancel(); - }, async castStart (spell) { if (this.$store.state.spellOptions.castingSpell) { this.castCancel(); @@ -51,13 +47,6 @@ export default { return true; }); this.castEnd(tasks, spell.target); - } else { - // If the cast target has to be selected (and can be cancelled) - document.addEventListener('keyup', this.handleCastCancelKeyUp); - - this.$root.$on('castEnd', (target, type, $event) => { - this.castEnd(target, type, $event); - }); } }, async castEnd (target, type) { @@ -72,12 +61,17 @@ export default { if (target && target.challenge && target.challenge.id) return this.text(this.$t('invalidTarget')); if (target && target.group && target.group.id) return this.text(this.$t('invalidTarget')); + // @TODO: just call castCancel? + this.$store.state.spellOptions.castingSpell = false; + this.potionClickMode = false; + this.spell.cast(this.user, target); + // User.save(); // @TODO: let spell = this.spell; let targetId = target ? target._id : null; - - this.castCancel(); + this.spell = null; + this.applyingAction = false; let spellUrl = `/api/v3/user/class/cast/${spell.key}`; if (targetId) spellUrl += `?targetId=${targetId}`; @@ -129,10 +123,6 @@ export default { this.spell = null; document.querySelector('body').style.cursor = 'initial'; this.$store.state.spellOptions.castingSpell = false; - - // Remove listeners - this.$root.$off('castEnd'); - document.removeEventListener('keyup', this.handleCastCancelKeyUp); }, }, };